fix(poll): снять квоты журналов полного опроса
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 10m21s
Docker images / frontend-image (push) Successful in 2m8s
Docker images / updater-image (push) Successful in 38s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 1m59s
Docker images / publish-release (push) Successful in 12s
Docker images / notify-webhook (push) Successful in 2s

This commit is contained in:
Denozordec committed 2026-11-23 11:35:04 +07:00
1 parent e11e67b3a1
commit ef3d7b6779
40 files changed
+461 -364

No files matched your search

@@ -106,10 +106,10 @@ try{
await assert.rejects(store.write(options(),sql=>sql.query("INSERT INTO server_poll_intents(receipt_id,stage,before_proof,effect_proof,intent_proof) VALUES($1,'native.resource',$2,$2,$2)",[value.receiptId,proof])),PollStorageRefused)
cases.push("two-phase claim, exact reservation, durable spent identity, normalized activity, plan stage cap and idempotent quarantine actual-row metering")
const owner="concurrent-"+randomUUID(),claims=await Promise.allSettled(Array.from({length:10},async()=>{const s=scope(owner);return createServerPollStorage(binding(s)).claim(options(),sql=>anchor(sql,s))}))
assert.equal(claims.filter(row=>row.status==="fulfilled").length,8)
assert.deepEqual(await usage(owner),{admissions:8,reserved_rows:8*4019,reserved_bytes:String(8*8421376)})
cases.push("ten concurrent independent factories atomically admit eight owner attempts, refuse two, never partially charge counters")
const owner="concurrent-"+randomUUID(),claims=await Promise.allSettled(Array.from({length:20},async()=>{const s=scope(owner);return createServerPollStorage(binding(s)).claim(options(),sql=>anchor(sql,s))}))
assert.equal(claims.filter(row=>row.status==="fulfilled").length,20)
assert.deepEqual(await usage(owner),{admissions:20,reserved_rows:20*4019,reserved_bytes:String(20*8421376)})
cases.push("twenty concurrent attempts for one owner retain exact charges")
const uncertain=scope(),b=binding(uncertain);let loss=true,callbacks=0
const lost=createServerPollStorageForTests(b,{now:Date.now,async connect(opts){const c=await connectProbeStorage(opts);return {release:v=>c.release(v),async query(text,values,queryOptions){const result=await c.query(text,values,queryOptions);if(text==="COMMIT"&&loss){loss=false;throw Error("SYNTHETIC lost admission commit acknowledgement")};return result}}}})
@@ -181,41 +181,31 @@ try{
cases.push("actual existing worker tick collects an eligible original terminal poll admission and refunds quota while MCP is disabled")
await (await import("./server-poll-storage-execution.sql-helper.js")).acceptServerPollStorageExecutionSql()
cases.push("actual quota-bound full production poll: all four native GETs observe committed consumed admission, every maintenance publication/ACK metered, known replay no new native or quota")
const globalBefore=Number((await pool.query("SELECT admissions FROM server_poll_storage_usage WHERE scope='global'")).rows[0].admissions)
const fill=await Promise.allSettled(Array.from({length:130-globalBefore},async()=>{const s=scope();return createServerPollStorage(binding(s)).claim({deadlineAt:Date.now()+60000},sql=>anchor(sql,s))}))
assert.equal(fill.filter(row=>row.status==="fulfilled").length,128-globalBefore)
assert.equal(Number((await pool.query("SELECT admissions FROM server_poll_storage_usage WHERE scope='global'")).rows[0].admissions),128)
assert.equal((await pool.query("SELECT count(*)::int AS n FROM server_poll_storage_usage WHERE scope<>'global' AND admissions=0")).rows[0].n,0,"Refused owner reservations leave no zero counter rows")
cases.push("global 128-attempt cap holds across independent owners and concurrent actual commits; failed admissions leave no orphan counters")
{
const {readServerPollCapacity}=await import("./server-poll-capacity.js")
const fullOwner=(await pool.query("SELECT scope FROM server_poll_storage_usage WHERE scope<>'global' AND admissions=8 LIMIT 1")).rows[0]
assert(fullOwner)
const ownerId=String(fullOwner.scope).slice("owner:".length)
const before=(await pool.query("SELECT * FROM server_poll_storage_usage ORDER BY scope")).rows
const readOnly=await pool.connect()
try{
await readOnly.query("BEGIN READ ONLY")
const capacity=await readServerPollCapacity(readOnly,ownerId,true)
assert.equal(capacity.status,"observed")
if(capacity.status!=="observed")assert.fail("Expected actual full retained capacity")
assert.deepEqual(capacity.owner,{used:8,limit:8,remaining:0})
assert.deepEqual(capacity.global,{exhausted:true,usage:{used:128,limit:128,remaining:0}})
const privateCapacity=await readServerPollCapacity(readOnly,ownerId,false)
assert.equal(privateCapacity.status,"observed")
if(privateCapacity.status!=="observed")assert.fail("Expected scoped private capacity")
assert.deepEqual(privateCapacity.global,{exhausted:true,usage:null})
assert.equal(JSON.stringify(privateCapacity).includes(ownerId),false)
const emptyOwner=await readServerPollCapacity(readOnly,"unallocated-"+randomUUID(),false)
assert.equal(emptyOwner.status,"observed")
if(emptyOwner.status!=="observed")assert.fail("Expected unallocated owner capacity")
assert.deepEqual(emptyOwner.owner,{used:0,limit:8,remaining:8})
assert.equal(emptyOwner.global.exhausted,true)
await readOnly.query("COMMIT")
}finally{readOnly.release()}
assert.deepEqual((await pool.query("SELECT * FROM server_poll_storage_usage ORDER BY scope")).rows,before)
cases.push("portal retained capacity uses real READ ONLY snapshot of owner8/global128, hides non-admin global numbers, never claims unallocated owner bypasses full global cap, and changes no quota row")
const globalBefore = Number((await pool.query("SELECT admissions FROM server_poll_storage_usage WHERE scope='global'")).rows[0].admissions)
const ownerId = "scale-" + randomUUID()
for (let n = globalBefore; n < 130; n += 1) {
const attempt = scope(ownerId)
await createServerPollStorage(binding(attempt)).claim(options(), sql => anchor(sql, attempt))
}
const { readServerPollUsage } = await import("./server-poll-capacity.js")
const before = (await pool.query("SELECT * FROM server_poll_storage_usage ORDER BY scope")).rows
const readOnly = await pool.connect()
try {
await readOnly.query("BEGIN READ ONLY")
const usage = await readServerPollUsage(readOnly, ownerId, true)
assert.equal(usage.status, "observed")
if (usage.status !== "observed") assert.fail("Expected observed journal usage")
assert.equal(usage.ownerFull, 130 - globalBefore)
assert.equal(usage.globalFull, 130)
const privateUsage = await readServerPollUsage(readOnly, ownerId, false)
assert.deepEqual(privateUsage, { ...usage, globalFull: null })
assert.equal(JSON.stringify(privateUsage).includes(ownerId), false)
const emptyOwner = await readServerPollUsage(readOnly, "unallocated-" + randomUUID(), false)
assert.deepEqual(emptyOwner, { ...privateUsage, ownerFull: 0 })
await readOnly.query("COMMIT")
} finally { readOnly.release() }
assert.deepEqual((await pool.query("SELECT * FROM server_poll_storage_usage ORDER BY scope")).rows, before)
cases.push("historical journals coexist with over 128 full admissions and read-only usage counts")
const evidence=await(await import("./server-poll-storage-restore-evidence.sql-helper.js")).pollStorageRestoreEvidence(pool)
await writeFile(resolve(process.env.MCP_STATE_DIR!,"poll-storage-owned-restore-evidence.json"),JSON.stringify(evidence),{flag:"wx",mode:0o600})
console.log("Owned poll storage SQL:",JSON.stringify({cases:cases.length,names:cases,historicalPrefix39:39,currentMigrations:MIGRATION_MANIFEST.length,actualMigrationFileStagedForOwnedHistoricalFixtures:true,allFileStatementsAndRealTerminalMarker:true,historicalRowsAndHashesPreserved:true,realPgTransactions:true,realQuotaTriggers:true,historicalFixtureBeforeGuards:true,providerOrClockOverrides:false,simulatedCommitAckLossAfterRealCommit:true,publicRoutesRegistered:false,journalAdapterIntegrated:true,productionDatabaseTouched:false,externalNetwork:false}))