Repository navigation
CONTRACT: fix(ui-server,ui-sdk): wait for a turn's own maintenance before refusing its first reference call (#4079) - #4080
Merged
Conversation
…fore refusing its first reference call (#4079) Every maintenance command reserves the whole default 256 MiB maintenance budget, and admission refuses rather than waits. A reference Git command that overlapped the turn's scratch check, or the boot-time scratch prune, was refused at once, and the tool answered the generic `unavailable` with no retry guidance. The scratch check refused the other way round left `.brain/scratch/` read-only for the turn. - The reference transport waits up to REFERENCE_ADMISSION_WAIT_MS (30 s) per Git command for the budget to free, then refuses as `busy`. The reference source maps that to its existing `busy` code on resolution and on fetch or checkout. The tool classifies any raw maintenance-busy error that reaches it as `busy` too, never `unavailable`. - An awaited scratch check waits up to SCRATCH_ADMISSION_WAIT_MS (3 s) on one deadline across its Git queries. The synchronous check and bind-time revalidation of lapsed sources still refuse at once. - MaintenanceTempBusyError gains freedWithin(ms, signal), a bounded freed(). Neither wait adds an allowance; both stay inside the existing budget. The MCP contract component states the new bound for `busy`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 16, 2026
…ntenance worker sees it; import an exported type (#4079) Hosted heavy feedback showed two test faults in this PR, not in the fix: - The writable-scratch test built its brain under the OS /tmp, which a maintenance worker replaces with its own, so the worker's git query could not see it and scratch stayed read-only after the wait had worked. The brain now lives in the repository's gitignored tmp/, as the worker sandbox tests place theirs, and the assertion prints the mount's reason. - The reference admission test imported MaintenanceTempReservation, which the SDK's internal entry does not export (TS2305 in strict typecheck). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reference cell (#4079)" The probe ran the integrated cell on hosted runtime_host in heavy feedback run 43854394276: Integrated reference proof passed (claude, pi). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 16, 2026
Merged
…intenance-admission
schlessera
marked this pull request as ready for review
November 16, 2026 18:23
…fixture input lease (#4079) Candidate confirmation showed the writable-scratch test still read-only: "git could not run to confirm .brain/scratch/ is gitignored". The wait had worked, but the worker never ran git. It had no prepared startup view, which every real-worker writable test supplies through createFixtureMaintenanceHost. The test now uses that host, with its ledger state beside the brain in the repository's gitignored tmp/ and masked from the worker, as maintenance-temp-helpers.test.ts does. It passes locally, where the worker now runs, and still fails on main with the "(held by: git)" busy refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 tasks done
…intenance-admission
schlessera
marked this pull request as draft
November 16, 2026 20:04
schlessera
marked this pull request as ready for review
November 16, 2026 20:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4079
What changed
A turn's first
reference_sourcecall no longer fails because the turn's own maintenance commands hold the shared maintenance budget. Each reference Git command now waits up to 30 s (REFERENCE_ADMISSION_WAIT_MS) for the budget to free, then refuses asbusywith "nothing ran, retry" guidance. That covers resolution as well as fetch and checkout. A raw maintenance-busy error that still reaches the tool is classifiedbusy, never the genericunavailable. An awaited scratch check now waits up to 3 s (SCRATCH_ADMISSION_WAIT_MS, one deadline across its Git queries), so a short reference command no longer leaves.brain/scratch/read-only for the turn.MaintenanceTempBusyErrorgainsfreedWithin(ms, signal), a boundedfreed().Why this shape
The issue offered three options. I took the bounded admission wait:
referenceTools.begin. The hosted refusal named acommand-kind holder, which was the app's boot-timebrain scratch prune(its own log says "scratch prune failed"), not the turn's scratch check.The wait reuses the existing in-process release wake-up (
freed()) and the bounded cross-process recheck, so no new mechanism is involved. Each bound is per command, so no wait is unbounded. Neither wait reserves anything extra.These keep the old refuse-at-once behaviour on purpose:
prepareWorkerSandbox) cannot wait. Its step refuses as before.admissionWaitMs: 0and withholds the source, as before, rather than stalling the turn's start behind an index.Proof
All of these run against the real maintenance admission ledger, with production limits (one 256 MiB allowance in a 256 MiB budget) on a private domain. In the ui-server file, only the worker launch is scripted. The scratch test uses the real
prepareWorkerSandboxAsyncand maintenance worker.Failing first. I reverted only
packages/*/srctoorigin/main(eb3c53a) and ran the new tests:packages/ui-server/tests/reference-maintenance-admission.test.ts: every test fails on the reason the issue quotes. For example,REFERENCE_CALL_SUCCEEDS_ONCE_THE_SCRATCH_CHECK_FINISHESreceives{"ok":false,"code":"unavailable","message":"The reference service could not complete this request."}.REFERENCE_CALL_PAST_ITS_BOUND_IS_BUSY_NOT_UNAVAILABLEandRAW_MAINTENANCE_BUSY_IS_A_BUSY_REFUSALreceivecode: "unavailable".packages/ui-sdk/tests/maintenance-temp-holders.test.ts:TURN_SCRATCH_CHECK_IS_NOT_REFUSED_BY_A_SHORT_REFERENCE_COMMANDreceives".brain/scratch/ could not be checked (Maintenance temporary storage is busy: ... (held by: git). ...)", the line from the hosted log.With the fix, the ui-server file passes 4 of 4. Its timing assertion proves the call is admitted within the stated 30 s bound.
Mutations, each restored afterwards:
REFERENCE_CALL_SUCCEEDS_ONCE_THE_SCRATCH_CHECK_FINISHES,REFERENCE_CALL_WAITS_ITS_BOUND_BEFORE_REFUSINGbusyon resolutionREFERENCE_CALL_PAST_ITS_BOUND_IS_BUSY_NOT_UNAVAILABLERAW_MAINTENANCE_BUSY_IS_A_BUSY_REFUSALTURN_SCRATCH_CHECK_IS_NOT_REFUSED_BY_A_SHORT_REFERENCE_COMMANDSYNC_SCRATCH_CHECK_NEVER_WAITS(5007 ms)acquiredropsbusyon fetchREFERENCE_FETCH_PAST_ITS_BOUND_IS_BUSY_NOT_UNAVAILABLEEnvironment limit. This host has no unprivileged user namespaces (
unshare: write failed /proc/self/uid_map), so no real worker starts here. Locally, the scratch test therefore gets past admission (the busy assertion passes) and then failsTURN_SCRATCH_STAYS_WRITABLE_AFTER_A_SHORT_REFERENCE_COMMANDwith "git could not run to confirm .brain/scratch/ is gitignored". Uncontendedorigin/maingives the same environment-only result. Hosted CI proves the writable outcome.Neighbouring suites. I ran the reference-source, tools, worktrees, GitHub access, transport, maintenance-temp, worker-sandbox, worker-steps, index-requeue and probe-admission files. 182 pass. All 8 failures also fail on
origin/mainin this sandbox (real worker boundary).Build.
bun run buildis clean, because exports changed.tsc --noEmitis clean.Hosted integrated cell (AC4): passed. A temporary probe commit (9ac8999, copied from #4072's) made hosted
runtime_hostalso runscripts/prove-reference-pool.ts --integratedon both backends. Heavy feedback run https://github.com/schlessera/brain-kit/actions/runs/43854394276 tested merge commit e19300f, and itsruntime_hostjob (https://github.com/schlessera/brain-kit/actions/runs/43854394276/job/133255130366) loggedIntegrated reference proof passed (claude, pi)., besideReference pool proof passed. Its log has noreference tool failed, noMaintenance temporary storage is busyand noread-only this turn. The proof step succeeded. Only the job's receipt-upload step failed, withEACCESon the integrated cell's app-ownedtranscript-archivedirectory. That directory comes from the probe, which is reverted in 2407cb4; #4072's branch carries the upload fix separately.Two test faults that run found, now fixed in f762439:
unit (3): the writable-scratch test built its brain under the OS/tmp, which a maintenance worker replaces with its own. The wait worked (TURN_SCRATCH_CHECK_IS_NOT_REFUSED_BY_A_SHORT_REFERENCE_COMMANDpassed on hosted), but the worker's git query could not see the brain. The brain now lives in the repository's gitignoredtmp/, where the worker sandbox writable test keeps its brain; that test passed in the same run (unit (2)). The assertion now prints the mount's reason.verify: the reference admission test importedMaintenanceTempReservation, which@schlessera/brain-ui-sdk/internaldoes not export (TS2305). It now usesReturnType<typeof reserveMaintenanceTemp>. Roottsc --noEmitis clean at 2407cb4.Third fix, in 62934ee: candidate confirmation at ef20465 still failed
unit (3), now with the reason visible:"git could not run to confirm .brain/scratch/ is gitignored". The wait had worked, but the maintenance worker never ran git, because it had no prepared startup view. Every real-worker writable test supplies one throughcreateFixtureMaintenanceHost. The test now uses that host, with its ledger state beside the brain in the repository's gitignoredtmp/and masked from the worker, the same waymaintenance-temp-helpers.test.tsdoes.With that input lease the worker runs on this host too, so the writable outcome is now proven locally:
maintenance-temp-holders.test.tspasses 8 of 8, with scratch{ writable: true }.main(packages/ui-sdk/srcreverted): it failsTURN_SCRATCH_CHECK_IS_NOT_REFUSED_BY_A_SHORT_REFERENCE_COMMANDwith the busy refusal(held by: git).{"version":1,"kind":"brain-check-pr-receipt","head":"62934ee91fa214c81dbfa1aa152be7ad2de2d5bd","base":"origin/main","mode":"focused","startedAt":"2026-11-16T18:54:26.756Z","finishedAt":"2026-11-16T18:55:35.010Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12516.151867},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":103.92609699999957},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":68.8981010000025},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":21.901950999999826},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":55527.568512}]}Contract
The
busycode is already in the documentedreference_source/reference_worktreerefusal set. This changes which code one case returns (unavailablebecomesbusy) and states the new 30 s bound indocs/integration-contract/mcp.mdin the sameCONTRACT:commit. That makes it additive: no field, shape or tool name moved.ReferenceTransport.resolvegains an optionaladmissionWaitMsinput. It is ui-server internal, not a package export.Changed guard (proportionate containment)
busy. A scratch check past its bound leaves only that turn's scratch area read-only.reference tool refusal (busy): ...,worker scratch area is read-only this turn: ...). The agent gets a retry message.a fetch refused past its bound after a successful resolution is busy tooshows one request refused without anything published. The other tests show the next request succeeds once the holder finishes.Collisions
bun scripts/collisions.ts --json --pr 4080at fix head 2616ed6 (the later commits change only this PR's own two test files and revert the probe):reference-transport.tsand on the three docs whose citations this PR repairs.reference-source.ts, a temporary mutation there).None is a lock.
Checklist
.changeset/4079-reference-maintenance-admission.md).docs/reflect the change. Citations my line shifts moved are repaired.Anything left open
scripts/prove-reference-pool.tsmatchesmain.scratch-mask-query.ts) and the bridge mask's scratch query still refuse at once when busy. They do not run at a turn's start.🤖 Generated with Claude Code