Skip to content

backends, ui-server: keep reconciling uncertain worker, checkpoint and compute charges instead of giving up until restart #3815

Closed

Description

@schlessera

Context

Three guards keep an uncertain charge, which is correct, but stop reconciling after a fixed number of attempts. The charge then stays until a restart, and it reduces capacity or budget for every session. Verified on main 4b8db90de:

  1. Claude worker cleanup: after CLEANUP_RETRY_ATTEMPTS failed closes, the reconciler logs "stay charged until the server restarts" and stops retrying (packages/ui-backend-claude/src/cleanup-reconciler.ts:78-90). The reservation sits in the process-wide worker-state ledger shared by both backends (packages/ui-sdk/src/server/worker-state-budget.ts:1, :80). Enough stranded allowances block admission for every session.
  2. Superseded checkpoint release: the observation that replaced the old checkpoint has already committed, yet a failed release of the old one calls releaseFailed. That stops every active turn and refuses earlier-requested admissions (packages/ui-server/src/brain/turn-journal.ts:175-190). The release only reclaims space. It retries at backlog pressure, so it is not sticky, but every running turn dies. A plausible trigger is a btrfs delete failing when the carrier is low on space.
  3. Hosted compute polling: after maxFailures failed visits, the driver stops tracking the job while its reservation keeps counting toward turn, session and day budgets until a restart reattaches it (packages/ui-server/src/brain/compute-host.ts:592-601). The budget checks then refuse chats (packages/ui-server/src/brain/turn-budgets.ts:161, :177).

The pi backend has a related path. An initialization failure claims cleanup, attempts closeTurnTemp() once, and registers no retry owner (packages/ui-backend-pi/src/worker-session.ts:171, packages/ui-backend-pi/src/worker-launch.ts:301-319). This was asserted by an audit and not traced end to end; confirm it before changing it.

Out of scope

  • Releasing any charge before cleanup or settlement is positively confirmed.
  • Changing budget limits or the worker-state ledger's sizing.

Scope

  • Claude cleanup and the pi path: keep a low-frequency reconciliation owner indefinitely, with capped backoff and no terminal give-up. Release the reservation exactly once, on a confirmed close.
  • Checkpoint release: a failed release of a superseded checkpoint keeps its charge and retries. It does not stop active turns. Backpressure applies only when the retained-checkpoint bound actually blocks the next safe observation.
  • Compute: keep reconciling a job slowly after the foreground failure limit, independent of new turn admission. Settle or release when it is observed.
  • Each give-up or backoff state is visible to the owner, with its cause (see ui-server: a latched safety recorder keeps no cause, mislabels errors as capacity, and has no recovery path #3810's pattern).

Acceptance criteria

  • A Claude cleanup refused more than CLEANUP_RETRY_ATTEMPTS times is still retried, and its allowance is released once a close succeeds. No restart. Test fails on the current tree.
  • A forced failure releasing a superseded checkpoint leaves active turns running and their records complete. The release is retried and its bytes stay charged until it succeeds. Tested.
  • A compute job whose visits fail more than maxFailures times is visited again later and settles its reservation when its state becomes readable, with no restart. Tested.
  • The pi initialization-failure cleanup either has a retry owner or is shown, with a citation, to need none.
  • Mutation receipts for each: restore the terminal give-up and watch the named test fail.

Verification

Unit tests in packages/ui-backend-claude/tests, packages/ui-server/tests and packages/ui-backend-pi/tests; bun run check:pr --base origin/main.

Contract impact

None expected. Owner-visible status fields, if added, are additive.

Activity

  1. added this to the 0.45.0 milestone on Nov 9, 2026
  2. added
    type: fix
    area: ui-server
    area: backends
    priority: p1
    agent-ready
    on Nov 9, 2026
  3. self-assigned this
    on Nov 10, 2026
  4. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    Claiming #3815 for implementation and verification under #3813. Claim token: runtime-reconcile-3815-a513d326. Branch: fix/reconcile-uncertain-workers.

    Verified the cited cleanup, checkpoint, compute and Pi paths against current source. Pi initialization cleanup does lack a retry owner. The parallel #3816 work may touch turn-journal.ts; this change will stay confined to superseded checkpoint releases and their admission/hold coupling. Charges remain reserved until cleanup or settlement is confirmed.

  5. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    Implementation is preserved in #3823 at 44065742c5304b8f3babcf3ebfd5134621ddb68b, targeting milestone 0.45.0. Local preflight, TypeScript, focused runtime tests and the recorded failing-first mutations passed. The latest exact-head contract check passed; no reviews are outstanding.

    Confirmation exhausted its bounded admission attempts because #3822 currently owns the integration reservation. No selected candidate CI or merge was started for #3823; it remains draft. This is an integration handoff, not a missing implementation criterion. Once the reservation clears, fetch/rebase current main, reconcile documented status/journal overlaps, refresh preflight for any changed candidate, then run bun scripts/integrate.ts confirm 3823 --issues schlessera/brain-kit#3815 and verify the squash and automatic main proof.

    Releasing claim runtime-reconcile-3815-a513d326 while leaving the branch and PR available for the coordinating task. Separate pre-supervision Pi cleanup is recorded in #3821.

  6. removed their assignment
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: backendsarea: ui-serverpriority: p1type: fix

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions