Skip to content

fix(ui-server): hold conversation intake writes across a journal observation or scope pause (#2869) - #4041

Merged
schlessera merged 4 commits into
mainfrom
fix/2869-intake-hold-aware-writes
Nov 16, 2026
Merged

schlessera merged 4 commits into
mainfrom
fix/2869-intake-hold-aware-writes

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #2869

What changed

A conversation turn's inbox_add now treats a journal observation or a scope pause that begins after its entry check as a hold, not as revocation. Before, it checked the turn at entry and again just before the receipt commit, and its staging writes ran unchecked in between. A hold that began while it staged let those writes run through the hold. The final check then refused a still-valid turn with "Inbox principal or turn is no longer authorized" and removed the staged files during the hold. Now every intake write goes through one write boundary (writeBoundary, packages/ui-server/src/inbox/intake.ts): partial creation, each file and meta.json write, publication, the prepare/accept/replay receipt writes, and the reconciliation removals. Each one waits out a hold outside any transaction or lock, with one 60-second deadline shared across the whole intake. It then runs in the same tick as its final check, so a hold that begins after that check cannot overlap it. One item is accepted after the hold ends.

Why this shape

This follows the maintainer's option A on the issue: guard the whole intake lifecycle rather than relax isCurrent.

  • Synchronous writes under the gate. stageShareAt takes an optional StagingWriteGate and, when one is given, writes each file synchronously (writeExclusiveSync). An async write in flight could otherwise straddle a hold that begins mid-write. The share, person and CLI routes pass no gate and keep their existing async path unchanged.
  • Hold versus revocation. The bridge's authorize reports AuthorityHeld only when the principal row is still usable and the bridge's own hold.active() says authority stands (packages/ui-server/src/inbox/bridge-tools.ts). Revocation, turn replacement and cancellation keep refusing at once.
  • Renewed premises. Each write check renews the turn, the principal, the origin thread and, through a new requalify hook, the provider masks over the staging directory. That mask check was entry-only; it is now shared by guardMaskedRecords and openInbox in packages/ui-server/src/ws/bridge-capabilities/activity.ts. The accept transaction still refuses a receipt that reconciliation took meanwhile.
  • Compensation never blocks the refusal and never writes through a hold. An inline removal that meets a hold is skipped. The intake that owns the arrival then removes it after the hold, off the reply's path. It waits on a writes-only hold (journal.isHeld() || scopePaused(), independent of turn authority) under the same deadline, and keeps the receipt in active until it settles. When it cannot run (bound passed or turn cancelled), its cleanup receipt stays queued for reconciliation. close() now waits for these owned cleanups. A committed receipt is never compensated.
  • Rejected: waiting for compensation before refusing. A first cut did that, and a revoked or replaced turn's refusal then waited up to the full bound for a hold to end.

The boundary is recorded in docs/decisions/governed-writable-workers.md, next to the #2853 paragraph. While there, I repaired citations into the touched files that had drifted, in that record and in three plans.

Proof

bun run check:pr --base origin/main          # passed, receipt below
NODE_OPTIONS=--max-old-space-size=8192 bunx tsc --noEmit   # clean
bun run test packages/ui-server/tests/inbox-intake-holds.test.ts packages/ui-server/tests/ws-inbox-intake-hold.test.ts   # 17 pass, 3 consecutive runs
bun run test <inbox/staging/hold suites, 16 files>   # 250 pass, 2 fail (environment, see below)

New tests run real intake, real descriptor-anchored staging on a temporary brain, and a real UI database.

  • inbox-intake-holds.test.ts covers a journal hold and a scope pause raised at the staging, publication and receipt checks, and a hold raised in the macrotask after entry. It also covers the shared deadline and timeout, revocation and turn replacement during a hold, cancellation, a stale mask premise, a receipt reconciled during the wait, concurrent duplicates with one winner, and a loser whose cleanup meets a hold.
  • ws-inbox-intake-hold.test.ts drives the live WsHost bridge for both hold kinds. It also asserts that the brain lock stays acquirable during the wait, so Continue/Stop and journal completion are not blocked.

Failing first (new tests against origin/main's packages/ui-server/src): 0 pass, 17 fail. The receipt-check cases and both live-bridge cases fail with the issue's exact refusal, Inbox principal or turn is no longer authorized. The staging and publication cases fail at INTAKE_HOLD_RAISED_AT_STAGING and …_AT_PUBLICATION, because main runs no check at those points.

Mutations (each restored; tree verified clean afterwards):

  1. Publication outside the gate: both publication cases fail at INTAKE_HOLD_RAISED_AT_PUBLICATION (no check runs there).
  2. A fresh deadline per wait ({} instead of the shared budget): fails at INTAKE_HOLDS_SHARE_ONE_DEADLINE.
  3. No mask/premise recheck (requalify removed): fails at INTAKE_REQUALIFIES_AFTER_HOLD, because the stale premise was admitted.
  4. Compensation written through the hold (cleanup runs the removal directly): fails at INTAKE_COMPENSATION_WAITS_FOR_HOLD.
  5. The old strict check before accept: both receipt cases fail at INTAKE_HOLD_WAITS_RATHER_THAN_REFUSING.
  6. openInbox without holds: both live-bridge cases fail with Inbox principal or turn is no longer authorized.

Regression found by candidate confirmation, fixed in 6e96b392e. Unit shard 3 at fd7cf1a97 failed share-staging-protection.test.ts › the guard judges every change staging makes, as it lands, in order at EVERY_STAGING_CHANGE_JUDGED. The gated partial creation judged the partial directory twice: once before the gate and again inside it. The check now runs once, inside the change and before the staging root opens, as on main. My earlier local list named a nonexistent share-staging.test.ts, which is how this test was missed. Rerun at the fix: every ui-server test importing share/staging, share/staging-fs or inbox/intake (22 files) gives 328 pass, 3 fail. All three also fail with packages/ui-server/src at origin/main: the two provider-mask-bridge cases below, and http-internal-mounts.test.ts › retired POST /api/brain/whatsup …. NODE_OPTIONS=--max-old-space-size=8192 bun run typecheck is clean.

Environment-only failures: provider-mask-bridge.test.ts fails both brain_read_base and applications refuse a masked provider folder … cases (event profile strict vs governed). The same two fail with packages/ui-server/src checked out at origin/main.

Collisions (bun scripts/collisions.ts --json --pr <this PR>): recorded in a comment below.

{"version":1,"kind":"brain-check-pr-receipt","head":"e19c95f5b3d0c604855f0636bf7b0b526110c151","base":"origin/main","mode":"focused","startedAt":"2026-11-16T06:03:11.849Z","finishedAt":"2026-11-16T06:04:20.146Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12894.564102999999},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":105.18085100000098},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":69.79219399999783},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.867044999999052},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":55192.526629}]}

Proportionate containment

The guard changed is intake's refusal when a turn's authority is held mid-write.

  • Trigger: a journal observation or scope pause active at one of intake's write checks while the principal and turn still stand. It does not cover principal revocation, turn replacement, cancellation, an expired authorization or a closed origin thread; those refuse at once as before.
  • Restricts: one write of one intake, the narrowest unit whose authority is uncertain. Other turns, intakes and routes, Continue/Stop and the observation itself proceed.
  • Restricted mode before refusing: a bounded wait (60 s, shared across the intake) instead of the previous immediate refusal. Refusal comes only past the bound.
  • Clears: automatically, when the hold ends (journal idle or the pause answered), rechecked at least every 50 ms. No human action. A cleanup that could not run is retried by intake reconciliation on the next intake or at startup.
  • Cause: the refusal names the hold ("stayed held by a journal observation or a scope pause past the wait bound"). A retained cleanup stays a durable cleanup receipt in inbox_intake_receipts.
  • Scope isolation: INTAKE_DUPLICATES_NOTHING_ACCEPTED_UNDER_HOLD / INTAKE_COMMITTED_WINNER_NEVER_CLEANED (one intake's held cleanup never touches the committed winner), and WS_INBOX_HOLD_LEAVES_BRAIN_LOCK_FREE (a waiting intake leaves the brain lock usable).

Checklist

  • Focused local preflight/behavioral receipts passed (above). Selected hosted proof runs on confirmation.
  • Acceptance criteria from the issue are all met.
  • The PR and ui-server: inbox intake refuses a valid turn when a journal observation or scope pause begins during staging #2869 carry milestone 0.45.0.
  • A changeset is included (@schlessera/brain-ui-server patch).
  • No personal data anywhere in the diff.
  • Nothing in the machine surface moved: no CLI, MCP, wire or api-report change. IntakeHolds is an internal export of an unexported module path.
  • Docs under docs/ reflect the change.
  • The proportionate-containment checklist is answered above.
  • Provider history unchanged: nothing enters the provider-facing conversation.

Anything left open

Nothing for this issue. The share, person and CLI intake routes are outside a turn and were out of scope; their staging behaviour is unchanged.

🤖 Generated with Claude Code

…rvation or scope pause (#2869)

A turn's inbox_add checked the turn's strict authority at entry and again
before the receipt commit, with unguarded staging writes in between. An
observation or scope pause that began while it staged let those writes run
through the hold, then refused a still-valid turn and removed the staging
during the hold.

Every intake write now runs through one write boundary: staging,
publication and the receipt commit wait out a hold, bounded by one deadline
shared across the intake, and run in the tick their final check passes.
The check renews the turn, principal, origin thread and the provider masks
over the staging directory. Revocation, replacement and cancellation refuse
at once. Compensation never writes during a hold: inline removal skips, and
the intake that owns the arrival removes it after the hold, off the reply's
path, or leaves its cleanup receipt queued for reconciliation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. labels Nov 15, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Collisions at head e782dc9eec5e8c5a1ed733a1800aa17adc843810 (bun scripts/collisions.ts --json --pr 4041): no path collisions. 19 closure reports only (#3056, #3059, #3069, #3116, #3437, #3581, #3622, #3806, #4002, #4018, #4022, #4024, #4028, #4034, #4035, #4036, #4037, #4038, #4040), from shared test-closure membership. The claim-time path collision with #4028 on packages/ui-server/src/ws/bridge.ts no longer applies, because this PR does not change bridge.ts.

@schlessera
schlessera marked this pull request as ready for review November 16, 2026 04:29
…ing it (#2869)

The gated partial creation judged the partial directory both before and
inside its change, so the guard saw the first change twice and
share-staging-protection's in-order guard test failed. The check inside
the change already runs before the staging root opens, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Collisions at head 6e96b392eb70cd891e3d2fd255ecc3f22f8b9827 (bun scripts/collisions.ts --json --pr 4041): no path collisions; 27 closure reports only (shared test-closure membership).

@schlessera
schlessera marked this pull request as draft November 16, 2026 06:06
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 06:06
@schlessera
schlessera merged commit c07f5f6 into main Nov 16, 2026
50 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: inbox intake refuses a valid turn when a journal observation or scope pause begins during staging

1 participant