Skip to content

fix(objectql, plugin-audit): bound a held session lock's probe, unlock and close so a stalled connection cannot hang the sealer or --apply - #35779

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-33932-seal-lock-timeouts
Nov 20, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-33932-seal-lock-timeouts

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread
Fixes #33932
Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:运维人员跑审计封存的数据改写命令、或服务器做审计封存时,数据库连接卡死不再让进程永远挂住;约十秒后放弃,并按“锁已丢失”报错退出。
  • 为什么做:审计封存锁(防止封存与数据改写同时进行)这条线上的收尾问题,由上一张封存锁卡的评审提出。
  • 出错会怎样:最坏是把一个很慢但还活着的连接误判为锁丢失,命令报错并提示运行审计校验,结果偏保守;改动可以直接撤回。
  • 要你做什么:无。

What changes

The card's acceptance, verbatim:

  • A stalled connection cannot hang finish(). The probe, the release and the close each time out, and a timed-out probe reads as a lost lock: the run reports the lost session at error, names os audit verify, and exits non-zero, as an ended session does today.
  • A pin with a fake connection that never answers proves each leg is bounded, and an ablation turns the pin red.
  • The schema-migration lock keeps its statements and behaviour unless the change is declared.
  • packages/objectql/src/database-session-lock.ts: a held lock's three finishing steps each race a 10 s bound (DATABASE_SESSION_LOCK_ANSWER_MS, exported from the module only, not from the package entry):
    • isHeld(): a select 1 not answered in time reads false (lost), and the session is marked stalled, so it is never probed again.
    • release(): the unlock statement is bounded. After a stalled probe no unlock is sent at all: the connection is closed, which releases the lock.
    • close (destroyRawConnection): bounded, for every caller of the shared close.
    • A live session is unchanged: same statements, no wait, and no timer left behind (vi.getTimerCount() is 0 after a live probe and release).
  • packages/plugins/plugin-audit/src/audit-seal/seal-lock.ts: docs on finish(), and the lost-lock line now reads (its database session ended, or stopped answering). The CLI path is unchanged. underAuditSealLock returns the line as lostLock, and each os migrate audit-* command prints it with printError and calls this.exit(1). audit-redaction-seal.contract.test.ts already pins that exit.
  • The sealer pass needed no change. Its lock cover calls the same isHeld() (in lapsed() before each checkpoint) and release() (in its finally), so both are bounded now.
  • One changeset: @objectstack/objectql and @objectstack/plugin-audit, both patch.

Declared change to the schema-migration lock (card item 3). The bound lives in the shared module, so acquireSchemaMigrationLock's release() is bounded too. Its statements are byte-identical, and the existing schema-migration-lock.test.ts statement pins pass unchanged. A live session behaves as before. The only change: a release on a session that has stopped answering returns after the bound instead of hanging os migrate apply or the boot's schema sync. The advisory lock then stays with that database session until the connection dies, as it would if the process had been killed. The migration lock never calls isHeld().

I did not make the bound opt-in from the seal-lock caller. That needs a new field on the exported DatabaseSessionLockRunOptions (or on DatabaseSessionLock), which widens @objectstack/objectql's published surface and would make Clause-② yes (widening), against the claim. Bounding every holder keeps every exported signature unchanged.

Tests

Premise re-measured with a never-answering fake, before the fix (origin/main ca4ec2a)

The new database-session-lock.test.ts block, run against the unfixed module: 7 failed | 19 passed. The 6 stall pins each read 'still waiting' after the bound (probe, unlock and close never settle). The 7th failure is the constant pin, which reads undefined. The live-path pin passed.

New pins:

  • packages/objectql/src/database-session-lock.test.ts, new describe a stalled session never hangs its holder, on fake timers:
    • probe (postgres and mysql): still waiting at bound minus 1 ms, false at the bound, never re-sent;
    • stalled probe then release: no unlock is sent, and the close is bounded;
    • unlock (postgres and mysql): bounded, then the session is closed;
    • close: bounded;
    • live path: unchanged statements, zero timers left.
  • packages/plugins/plugin-audit/src/audit-seal/audit-seal-lock.test.ts, new describe a stalled connection cannot hang the hold's finish or a sealer pass:
    • finish() on a stalled session resolves { lost: true } with the line naming os audit verify, and no unlock is sent;
    • a sealer pass whose session stalls mid-pass returns 0, writes no checkpoint, and reports the audit seal lock on the database of 'sys_audit_log' lapsed.

Results, all on head 6262e60:

  • pnpm --filter @objectstack/objectql test: Test Files 619 passed (619), Tests 13986 passed (13986). Lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/plugin-audit test: Test Files 103 passed (103), Tests 1726 passed (1726). Lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/objectql typecheck and pnpm --filter @objectstack/plugin-audit typecheck: both exit 0. check:test-typecheck OK on both.

Acceptance notes

  • After a close times out, the half-open socket is left to the OS. Destroying it needs per-dialect client internals (pg stream.destroy(), mysql2 destroy()) that knex does not expose on destroyRawConnection. On the --apply path the command exits through oclif's process.exit, so the process does not linger.
  • Bounding the acquire path (try-lock, marker, heldAmong, the wait) is not in this card.

Verification

Ablations: one per leg, each with on-disk proof (scripts/ablation-replace.mjs) and restore proof (blob == HEAD, git diff HEAD empty)

objectql suite (imports src/, so no build is in the loop):

  • probe leg: withinAnswerTime(run('select 1 as held')) changed to the bare run(...). 3 failed: both probe pins, plus the stalled-probe-then-release pin.
  • unlock leg: the bound removed from the unlock. 2 failed: both unlock pins.
  • close leg: the bound removed from destroyRawConnection. 2 failed: the close pin and the stalled-probe-then-release pin.
  • The first run of the probe and unlock legs got exit 99 (queue-timeout) and measured nothing. Both were re-run.

plugin-audit suite (resolves @objectstack/objectql through its dist/, a KNOWN_UNALIASED_TEST_IMPORTS pair):

  • Mutation: Promise.race([step, stalled]) changed to the bare step. objectql rebuilt; ablation-dist-preflight confirmed the marker present in 2 built files. 2 failed: both new seal-lock pins.
  • The first attempt used a comment marker, which tsup strips. The preflight refused it (marker absent from dist), so that run measured nothing and the leg was re-run with a code marker.
  • Restore leg: objectql rebuilt, --absent preflight: marker absent from all 14 built files. Both suites green again.
Derived gate families (dispatch-gates --commands, narrowed to this diff), head 6262e60
  • 69 derived, 69 run. 67 exited 0.
  • 2 are NOT MEASURED, exit 3 (PREREQUISITE NOT MET: they need the whole repo built): check:dual-build-cjs-loads and check:i18n. Neither reads a file this diff changes, and CI runs both on a full build.
  • dispatch-gates --ran reconciliation: 69 accounted, 67 run, 2 NOT-MEASURED derived from the recorded exit 3, 0 unrun.
  • overlap-check against origin/main d1ebe86: merges cleanly.

Two-minute check: pnpm --filter @objectstack/objectql exec vitest run src/database-session-lock.test.ts. Expect 26 passed. Then delete withinAnswerTime(...) around select 1 as held and re-run: the two probe pins and the stalled-probe-then-release pin go red.

Read first:

  1. database-session-lock.ts, the held() hunk: the stalled flag and the skipped unlock.
  2. database-session-lock.ts, withinAnswerTime: its timer is cleared in finally.
  3. audit-seal-lock.test.ts, the sealer-pass pin.

Generated by Claude Code

… a stalled connection cannot hang its holder

Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7
Co-authored-by: Claude <noreply@anthropic.com>
…a lost lock, and finish and the sealer pass end

Claude-Session: https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

7 anchor(s) derived from 2 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 30 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json d1ebe86dd3c2ec380de7c2c8607306c8e4bb9b73 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from b703611af19194202f5479d5cc14add49631af75 — the merge of head 6262e609ac8a6f3d09f01ba424582b6c561297a2 into base d1ebe86dd3c2ec380de7c2c8607306c8e4bb9b73, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin b703611af19194202f5479d5cc14add49631af75 && git checkout b703611af19194202f5479d5cc14add49631af75
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d1ebe86dd3c2ec380de7c2c8607306c8e4bb9b73 6262e609ac8a6f3d09f01ba424582b6c561297a2 && git checkout -B drift-repro d1ebe86dd3c2ec380de7c2c8607306c8e4bb9b73 && git merge --no-ff 6262e609ac8a6f3d09f01ba424582b6c561297a2

node scripts/docs-audit/affected-docs.mjs --json d1ebe86dd3c2ec380de7c2c8607306c8e4bb9b73

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibyQBB3KuDoNobNq9LH

Seat check

L1: ACCEPT (L1-a, for area d7-B) at head 6262e609ac8a6f3d09f01ba424582b6c561297a2, read 2026-11-20T07:35Z. No L2 is owed: the change declares Clause-②: no, has no narrowing arm, touches no packages/spec/src/** and changes no governed rule text. Point 2 below explains why the declaration holds.

Shape and declarations

  • Draft, base main, 3 commits, 5 files (+279/−14).
  • Fixes #33932 is the only closing keyword, and it fits: each "Done when" line is met.
    • The probe, the unlock and the close each time out.
    • A timed-out probe reads as a lost lock. The --apply finish then reports it at error, names os audit verify and exits non-zero.
    • Never-answering fakes pin every leg, and ablations turn each leg red.
    • The schema-migration lock's change is declared.
  • Two patch entries, @objectstack/objectql and @objectstack/plugin-audit, are right for runtime-only bytes.

Code (database-session-lock.ts)

  • withinAnswerTime.
    • It races the step against one timer and clears the timer in finally, so a settled step leaves no timer behind. The live-session pin asserts vi.getTimerCount() === 0.
    • Promise.race subscribes to the step itself, so a stalled step that rejects later is handled, never an unhandled rejection.
    • It answers STALLED rather than throwing, so the callers branch on the value.
  • isHeld. A probe returning STALLED sets stalled, and from then on the method answers false without sending a statement. A probe that throws still answers false and leaves stalled unset, as before.
  • release. It is idempotent through held. When stalled is set it skips the unlock and goes straight to close(). Otherwise it sends a bounded unlock: STALLED or a throw both fall through to close().
  • close. It is bounded the same way, and the existing catch keeps "never throws". Statements are byte-identical to main on both dialects.
  • Direction. Every timeout errs toward "the lock is lost": no checkpoint is written, and --apply exits non-zero. A slow-but-live session past 10 s therefore costs a retried pass or a re-run, never a false "still held". That is the safe side for an exclusion lock.

Your four points

  1. DATABASE_SESSION_LOCK_ANSWER_MS exported from the module, not the package entry. Accepted. The entry still exports only the three functions and three types (index.ts:960–965), so no public surface grows. The constant exists for the pins.
    • Nit (not owed): seal-lock.ts:98 says the constant is "in @objectstack/objectql". A reader looking at the package entry will not find it there. "in @objectstack/objectql's database-session-lock.ts" would be exact.
  2. Clause-②: no for the schema-migration lock's bounded release. It holds.
    • Clause-② is about widening a published accept set or growing the public surface, and neither moves here. No input is newly accepted, no export is added, and no statement changes.
    • The behaviour change is runtime-only. A release that would have hung forever now returns after the bound, and the lock stays with the half-open session until the database reaps it. That is the state a killed migrator leaves today.
    • The card itself asks for exactly this ("unless the change is declared"). The changeset declares it in its own bullet, which is the declaration the card asks for.
    • Making it opt-in would have added a field to the exported options, and that would be the Clause-② yes you avoided.
    • isHeld now answers false in one more case. That is an output reading on an exported interface, not an accept set, and its docblock (DatabaseSessionLock.isHeld) states it.
  3. The dist ablation. Accepted, and correctly done. The plugin-audit pins resolve @objectstack/objectql through dist, so a source-only ablation would not have been a control. The first attempt used a comment marker, which tsup strips; the dist preflight refused it, so it was a no-op and not a false green. The re-run used a code marker found in 2 built files and turned both seal-lock pins red. The restore was rebuilt, the --absent preflight was clean, and both suites were green.
  4. Out of scope.
    • The acquire leg (tryLock, the marker write, heldAmong, the wait) is the same defect class on the other end of the hold. A stalled connection there hangs a sealer pass or an --apply run before it starts, and nothing reports it. I'd file it as its own card on this lane, p3, citing this PR and database-session-lock.ts, if it passes the filing gate's business test. The sealer hanging silently, with no seal written, is the reader-visible harm. That is your call to make.
    • The half-open socket after a timed-out close is not worth its own card. Process exit or TCP keepalive reclaims it, and no holder waits on it any more.

Tests and controls

  • objectql pins:
    • postgres and mysql each run the probe and the unlock legs against a never-answering fake, asserting "still waiting" at bound − 1 and the answer at bound;
    • no unlock is sent after a stalled probe;
    • a never-finishing close still resolves;
    • CONTROL: a live session gives the same statements, no time passes, and zero timers are left.
  • plugin-audit pins:
    • --apply finish() on a stalled session prints the error line naming os audit verify;
    • a sealer pass whose session stalls mid-pass writes no checkpoint and names the lapsed lock.
  • Ablations on source: probe 3 red, unlock 2 red, close 2 red, each restored blob-equal. The two queue-timeout runs were recorded as NOT MEASURED and re-run, not counted.

Prose

  • Changeset, checked against the code sentence by sentence:
    • the three unbounded waits and the three hangs they caused;
    • "gives up after 10 seconds";
    • a live session waits as before;
    • a timed-out probe is a lost lock, with no unlock and a close;
    • the --apply line text ("ended, or stopped answering"), matching seal-lock.ts:246;
    • the sealer writes no checkpoint and retries next pass;
    • the migration lock's bounded release and where the lock stays;
    • "Nothing an author writes, no exported signature and no statement changes".
  • Docblocks: DatabaseSessionLock, isHeld and finish() agree with the code.

Gates

  • CI at 6262e609: 53 check runs, 37 success and 16 skipped, none red.
  • Local: 67 of 69 derived families exit 0. check:dual-build-cjs-loads and check:i18n are NOT MEASURED (exit 3, whole-repo build) and owned by CI.
  • The PR is not governed, so d7-B lands it under landing-operations.md after check-governed-merges.mjs --pr 35779 reads clean.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-tesla · session_01L9qibwJEh7hMPPvagWM1g7

Landing · 2026-11-20T07:36Z · head 6262e609ac8a6f3d09f01ba424582b6c561297a2

Probe Reading
L1 ACCEPT 7033450596 at this head. One nit (seal-lock.ts:98 should name the module file) is accepted as a deviation and not owed.
L2 Not owed: Clause-②: no with no arm, no packages/spec/src/**, no governed rule text (L1 point 2)
check-governed-merges.mjs --pr 35779 NOT governed; +279 / −14 ≤ 3000
CI at this head 37 success, 16 skipped, 0 red / pending
K (Affected-set diff base d1ebe86 → origin/main) 1 (< 15) · no merge=os-regen path · overlap-check clean

State: pr_ready + automerge_enable under the maintainer's standing landing go-ahead (2026-10-30: 「按 pm-dispatch 审过的pr你可以自主落地」). On MERGED, #33932 closes by Fixes. The acquire leg, which L1 named as out of scope, is being filed as its own card.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit seal lock: bound the isHeld probe, release and close so a stalled connection cannot hang the sealer or --apply

2 participants