Skip to content

ui-server: a turn's first reference_source call is refused by the turn's own maintenance admission #4079

Closed

Description

@schlessera

Out of scope

The fixture-level contention in #3628 (two in-memory apps share one domain) and #3019 (in-memory fixtures use the per-user fallback ledger). Changing the default allowance or budget for every maintenance command. The reference pool's own allocation and accounting. Provider-facing tool text beyond the refusal's code and message.

Context

One app with a file-backed database, so with its own admission domain, refuses its own first reference_source call of a turn. The cause is contention with that same turn's worker sandbox preparation for the maintenance temporary-storage budget.

  • By default every maintenance command reserves the whole budget: allowance and budget are both 256 MiB (DEFAULT_MAINTENANCE_TEMP_BYTES, packages/ui-sdk/src/server/worker-state-limits.ts:151-152). Admission refuses rather than waits when the budget is held (if (held + BigInt(limits.allowanceBytes) > BigInt(limits.budgetBytes)), packages/ui-sdk/src/server/maintenance-temp-budget.ts:236).
  • Turn start prepares the worker sandbox. Its scratch check runs a maintenance command (resolveScratchMountSteps(brain, options.maintenance), packages/ui-sdk/src/server/worker-launcher.ts:967).
  • The reference transport runs each Git command as a maintenance command too (const run = options.run ?? runMaintenanceWorker, packages/ui-server/src/brain/reference-transport.ts:111).
  • So a reference call that overlaps the turn's scratch check is refused, or the scratch check is refused and the turn's .brain/scratch/ goes read-only.
  • The refusal also escapes unclassified. operate rethrows a non-invalid resolve error as is (const check = await transport.resolve, packages/ui-server/src/brain/reference-source.ts:302-305). The tool then answers the generic unavailable with no retry guidance (function refusal(error: unknown), packages/ui-server/src/brain/reference-tools.ts:66-71), rather than busy.

Observed in the opt-in integrated reference cell (scripts/prove-reference-pool.ts --integrated). It was run on hosted runtime_host through a temporary probe in PR #4072 (heavy feedback run 43810765015, checkout 4e63c9983). The scripted Claude turn calls reference_source as soon as the turn starts. Its app logged both sides of the race 136 ms apart:

worker scratch area is read-only this turn: .brain/scratch/ could not be checked (Maintenance temporary storage is busy: this command needs 256 MiB, 1 maintenance reservations hold 256 MiB of the separate 256 MiB budget (held by: git). ...)
reference tool failed: Maintenance temporary storage is busy: this command needs 256 MiB, 1 maintenance reservations hold 256 MiB of the separate 256 MiB budget (held by: command). Nothing ran. ...

The tool returned {"ok":false,"code":"unavailable","message":"The reference service could not complete this request."}. Run 43794917101 failed the same way at the same step. The cell passed on a native host when it was added (#2860), so how often the two overlap depends on the host's timing. A real model usually needs longer than the scratch check before its first tool call, but nothing guarantees that.

Scope

  • A reference acquisition in a turn no longer fails because of that turn's own maintenance commands. Choose one in the PR: a bounded admission wait for reference transport commands, ordering the turn's sandbox checks before its tools are offered, or a separate allowance for reference Git commands. Each must remain inside the existing budget; none may be an unbounded wait.
  • A maintenance-busy refusal that still reaches the reference service becomes a classified busy refusal with retry guidance, never the generic unavailable.

Acceptance criteria

  • A test holds the maintenance budget the way the turn's scratch check does, then issues a reference_source call in the same app. The call succeeds after the holder finishes, within a stated bound. The test fails on main for the reason quoted above.
  • With the budget held past that bound, the tool answers code: "busy" with a retry message. A test proves it; on main it fails with unavailable.
  • The turn's scratch area stays writable when a reference call starts in the turn's first moments, proven by a test.
  • bun scripts/prove-reference-pool.ts --integrated passes its first reference_source call on both backends on hosted runtime_host, through a probe like PR test(ui-server): qualify EDQUOT, cancellation and crash recovery under the Git workload (#3513) #4072's, with the receipt linked.

Verification

Focused bun run test for the reference source, tools and maintenance budget; bun run check:pr --base origin/main; hosted heavy feedback for the integrated cell as above. No network or provider keys.

Contract impact

Possibly additive: the reference tool's refusal code for this case changes from unavailable to the existing busy code. Assess against docs/integration-contract.md in the PR.

Blocks the backend-latency criterion of #3513.

Activity

  1. added
    type: fixSomething is broken and must behave the way it is documented.
    area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.
    area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    on Nov 16, 2026
  2. added this to the 0.45.0 milestone on Nov 16, 2026
  3. added
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    on Nov 16, 2026
  4. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Readiness review (2026-11-16): the cited lines still hold on main at eb3c53a (DEFAULT_MAINTENANCE_TEMP_BYTES at worker-state-limits.ts:151-152, the refusal at maintenance-temp-budget.ts:236, the scratch check at worker-launcher.ts:967, the transport's run at reference-transport.ts:111, operate's resolve at reference-source.ts:302-305 and refusal at reference-tools.ts:66-71). The acceptance criteria are checkable and the scope leaves the approach to the PR within stated limits, so this is agent-ready.

  5. self-assigned this
    on Nov 16, 2026
  6. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-ec61586c. Branch: fix/4079-reference-maintenance-admission.

    path collisions: #4002 (reference source/tools/transport), #4072 (reference source, temporary probe)

  7. schlessera commented on Nov 16, 2026

    @schlessera
    OwnerAuthor

    Merged in #4080 as c67d588c2 through the integration lease (orchestrator merge queue for 0.45.0). Candidate confirmation passed on the exact head; the squash's own main run carries the post-merge heavy categories.

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

Metadata

Metadata

Assignees

Labels

agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.type: fixSomething is broken and must behave the way it is documented.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions