Skip to content

backend-claude: a refused end-of-turn worker cleanup keeps its reservation with no owner to retry it #2871

Closed

Description

@schlessera

Blocked by #2854

Context

On the in-progress #2854 implementation, a Claude turn awaits its worker's runtime-state and turn-temp handle cleanup before it releases the turn's runtime-state reservation (the async cleanup continuation in packages/ui-backend-claude/src/worker-spawn.ts on the #2854 implementation branch). A separate-UID worker's last handle closes its identity broker there. If the supervisor cannot confirm that cleanup, the close rejects, the turn fails and the reservation stays charged, as the ruling on #2854 requires.

Nothing retries it afterwards. The cleanup runs once, in the worker completion's finally. finish() only awaits the same rejected completions (the finish completion join on that branch), and the turn calls it once (turn.finishWorker, packages/ui-backend-claude/src/sdk-options.ts:142). The handle itself stays retryable: a later closeAsync() asks the broker again. But no owner calls it, and nothing would then release the reservation. One runtime-state allowance stays held until the server restarts. A launch whose own cleanup is unconfirmed is retained the same way (packages/ui-backend-claude/src/worker-spawn.ts:177).

Pi retries its turn-temp close once, because two lifecycle points call the same single-flight close (promote and the prompt's finally, packages/ui-backend-pi/src/worker-session.ts).

Observed in review of the #2854 change. Not reproduced on a real host: the refusal needs a supervisor that cannot confirm cleanup.

Scope

Needs scoping. Decide whether the Claude backend should own a retry of a refused end-of-turn cleanup, and if so who triggers it (a later finish(), the next turn's admission, a periodic reconciliation) and how often.

Maintainer ruling required

Which owner retries unconfirmed Claude end-of-turn cleanup and releases retained accounting after confirmation?

  1. A bounded server-owned reconciliation owner retains the retryable handle and reservation, retries transient cleanup failures, and releases exactly once only after confirmation.
  2. A later explicit finish/admission triggers retry; define the owner and what happens when no later turn arrives.
  3. Keep the reservation until restart, with an explicit accepted limitation and no automatic retry.

Recommendation (not approved): Option 1, with finite attempts/backoff, shutdown ownership and observable terminal failure. No retry cadence or owner is approved yet.

Completion evidence: a maintainer comment selecting the branch and its failure/ownership semantics; then fold that ruling into checkable acceptance and the applicable decision record before adding readiness.

Out of scope

Acceptance criteria

To be written once scoped. For example: after a refused end-of-turn cleanup, a later retry that the supervisor confirms releases the turn's reservation exactly once. A test shows this, and it fails without the retry.

Verification

bun run test packages/ui-backend-claude.

Contract impact

None expected. /internal types only.

Source distinction: inspected main still uses synchronous handle closes at packages/ui-backend-claude/src/worker-spawn.ts:250-258. The reported async-cleanup behavior is a review finding of open #2854, not delivered main behavior. Recheck its final implementation before selecting the retry repair.

2026-10-25 triage at main 827861e1fa71cd4a26b52f1ef0f96b849381acdf: Exposed the unresolved architecture/policy question with options, consequences and an explicitly unapproved recommendation; retain the open implementation prerequisite and distinguish branch evidence from current main. No ruling or runtime proof is invented.

Activity

  1. added
    type: fixSomething is broken and must behave the way it is documented.
    area: backendsAgentBackend implementations and the seam they share.
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    blockedWaiting on another issue or an upstream dependency. Say which in the body.
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    on Oct 25, 2026
  2. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    2026-10-25 triage at main 827861e1fa71cd4a26b52f1ef0f96b849381acdf: Exposed the unresolved architecture/policy question with options, consequences and an explicitly unapproved recommendation; retain the open implementation prerequisite and distinguish branch evidence from current main. No ruling or runtime proof is invented.

  3. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #2854 is closed, so scripts/sync-project.ts is removing the blocked label.

  4. removed
    blockedWaiting on another issue or an upstream dependency. Say which in the body.
    on Oct 25, 2026
  5. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-25): Option 1. A bounded server-owned reconciliation owner retains the retryable handle and the reservation, retries transient cleanup failures with finite attempts and backoff, and releases the reservation exactly once, only after confirmation. It owns shutdown (stops cleanly, reports what is still held) and makes terminal failure observable (Activity/log with the held allowance). Never release on an unconfirmed close. Acceptance: a test with a supervisor that refuses N times then confirms shows the reservation held until confirmation and released exactly once; a permanently refusing supervisor ends in an observable terminal failure with the allowance still charged; shutdown during retry neither releases nor hangs; mutations for each.

  6. added
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    and removed
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Oct 25, 2026
  7. added this to the 0.45.0 milestone on Oct 25, 2026
  8. self-assigned this
    on Nov 3, 2026
  9. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming (token claim-2871-07e66837), branch fix/2871-claude-cleanup-retry from main adf371ffab5d. Implementing the 2026-10-25 ruling (option 1): a bounded, process-owned reconciliation owner in the Claude backend that retains the refused handles and the reservation, retries with finite attempts and backoff, releases once only after confirmation, stops on shutdown without releasing, and logs terminal failure with the held allowance. Collision report on the cited files: closure-only overlaps with open drafts (#3056, #3059, #3069, #3116, #3293), no path collisions; pi files (#2918) untouched.

  10. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Draft PR #3490 implements the 2026-10-25 ruling at head 0f7bb08c7.

    • The local proof passed: typecheck, build, lint, check:pr, a failing-first receipt and six mutations. All are in the PR body.
    • The remaining package-suite failures are the same 49 on main. This host has no unprivileged user namespaces, so hosted CI has to run them.
    • Hosted ready-candidate proof and the merge are still to do.
    • Follow-up backend-claude: a launch whose own cleanup is unconfirmed keeps its reservation with no retry owner #3489 (needs: decision) covers the launch-time unconfirmed cleanup that this ruling does not cover.
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: backendsAgentBackend implementations and the seam they share.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