Repository navigation
Description
Context
#2871 gave a Claude turn's refused end-of-turn worker cleanup an owner: a process-owned reconciler retries the close and releases the reservation once it is confirmed (retain(...) in packages/ui-backend-claude/src/worker-spawn.ts:279-281). Since #3815 (merged as #3823, 3aadc8df5) that reconciler lives in the SDK and is shared by both backends (createCleanupReconciler, packages/ui-sdk/src/server/cleanup-reconciler.ts:75-139; processCleanupReconciler, :142-150). packages/ui-backend-claude/src/cleanup-reconciler.ts:1-3 only re-exports it. It retries indefinitely with capped backoff, and Pi's worker cleanup already hands a refused turn-temp close to it (closeStorage, packages/ui-backend-pi/src/worker-launch.ts:304-311).
A launch whose own cleanup is unconfirmed is still not covered. When launchAgentWorkerAsync throws a cleanup-unconfirmed error (packages/ui-sdk/src/server/worker-launcher.ts:1343, rethrown or wrapped as WorkerIdentityCleanupError at :1389; predicate workerCleanupUnconfirmed, packages/ui-sdk/src/server/worker-identity.ts:14), createWorkerSpawn keeps the reservation charged and hands nothing on (} catch (error) { record(error); if (!workerCleanupUnconfirmed(error)) state.release(); throw error; }, packages/ui-backend-claude/src/worker-spawn.ts:191). The backend gets no handle from a launch that failed, so it has no close to retry. One runtime-state and turn-temp allowance stays charged until the server restarts. The launcher's failed-launch path decides what can be retried.
Found while implementing #2871. Not reproduced on a real host: the refusal needs a supervisor that cannot confirm cleanup during launch.
Maintainer decision — 2026-11-08, as amended by #3815
Select option 1: the existing backend cleanup reconciler owns retries. The SDK launcher exposes a retryable close on its cleanup-unconfirmed launch error; the Claude backend hands that close and the retained runtime-state/turn-temp reservation to the process-owned reconciler (processCleanupReconciler). Do not add a separate launcher-owned retry loop or accounting callback lifecycle.
Reuse the reconciler's current policy (CLEANUP_RETRY_ATTEMPTS, CLEANUP_RETRY_BASE_MS, CLEANUP_RETRY_MAX_MS, packages/ui-sdk/src/server/cleanup-reconciler.ts:62-64): a 1,000ms initial delay doubling to a 30,000ms cap, retried indefinitely. After five failed retries it logs that reconciliation continues, with the cause and the allowance still charged; it never gives up. The 2026-11-08 ruling's "five retries, then terminal refusal stays charged until restart" described the reconciler as it was then; #3815 removed that terminal give-up for every cleanup this owner holds, under proportionate containment. The ruling's choice of owner and handoff is unchanged.
Retries do not keep the process alive or hold the failed turn open. Confirmed cleanup releases the reservation exactly once. Shutdown stops scheduled retries, reports retained allowances and releases nothing, including a close that confirms only after shutdown begins.
The launcher/worker handoff is currently internal (launchAgentWorkerAsync, packages/ui-sdk/src/internal.ts:6). Inventory the actual implemented surface rather than treating an internal change as a supported error contract automatically.
Scope
Provide the selected retryable failed-launch close and hand it, with the retained reservation, to the shared process cleanup reconciler, passing the backend's existing cleanup reporter (stateOptions.reportCleanup, as at worker-spawn.ts:281) so the owner sees the worker_cleanup Activity notices #3815 added. The close must retain the exact failed-launch cleanup ownership and finish the required native/resource cleanup only after confirmation. Preserve ordinary launch failures and the existing end-of-turn owner; no separate retry infrastructure or provider authority is introduced.
Acceptance criteria
- A cleanup-unconfirmed launch error exposes a retryable close retaining the failed launch's actual cleanup ownership; the backend can distinguish it from an ordinary launch error and transfers it with its reservation to the shared reconciler.
- The close is idempotent/coalesced as needed, retries only the owned cleanup and confirms every required resource before success. It must not mark native ownership/readers or accounting released merely because a signal was sent or an error was caught.
- Refusal followed by confirmation releases runtime-state and turn-temp reservations exactly once, including a confirmation after more than
CLEANUP_RETRY_ATTEMPTSrefusals. While refusal continues the allowance stays charged and retries continue. An ordinary launch failure with confirmed cleanup keeps its current release behavior and does not enter this owner. - Reuse the reconciler unchanged: its capped backoff with no terminal give-up, unreferenced scheduling, continuing-reconciliation diagnostics,
retrying/resolvednotices through the backend's cleanup reporter, and shutdown behavior described above. Shutdown cancels scheduled retries, reports what remains held and releases nothing; no unbounded turn/shutdown wait is introduced. - Exercise the actual launcher-to-backend-to-reconciler handoff with deterministic failed-launch/supervisor doubles, including retry failure then success beyond the foreground attempt count, duplicate/concurrent close, and late confirmation after shutdown. A named mutation removing the handoff must fail the reservation assertion and pass after restoration.
- Retain actual-process/native qualification for the chosen failed-launch cleanup boundary and record its exact scope. A scripted exception alone is not proof of real-host supervisor cleanup.
- Inventory contract impact from the implemented export/error path. Keep internal coordination internal; document any actual supported package-API change under the existing contract rules. Published behavior requires an appropriate changeset.
Out of scope
- Changing the shared reconciler's policy, or the end-of-turn cleanup owner (backend-claude: a refused end-of-turn worker cleanup keeps its reservation with no owner to retry it #2871, backends, ui-server: keep reconciling uncertain worker, checkpoint and compute charges instead of giving up until restart #3815).
- Pi: post-launch refusal cleanup is backends: retain a retry owner for Pi post-launch refusal cleanup #3821; initialization failure was handled by backends, ui-server: keep reconciling uncertain worker, checkpoint and compute charges instead of giving up until restart #3815.
- New worker authority or a launcher-owned retry/callback owner.
Verification
Use a deterministic failed-launch/supervisor double at the actual launcher-to-backend boundary to distinguish unconfirmed cleanup from ordinary launch failure. Prove refusal (more than CLEANUP_RETRY_ATTEMPTS times) then eventual confirmation releases the reservation exactly once, unresolved cleanup stays charged, shutdown preserves ownership, and removing the handoff produces the named regression failure. packages/ui-backend-claude/tests/cleanup-reconciler.test.ts holds the reconciler's existing doubles. Native-process qualification follows the selected owner; a scripted error alone is not proof of real-host supervisor behavior. No live-host reproduction is claimed by this triage.
Contract impact
The selected launcher-to-backend handoff currently uses the SDK internal entry. No supported public error/callback change is assumed. Check docs/integration-contract/package-api.md against the actual implementation; any supported API change needs its corresponding authoritative documentation and CONTRACT: handling. The worker_cleanup Activity event already exists (#3815); reusing it adds no wire shape. Runtime behavior needs a changeset. No release milestone is committed by this ruling.
2026-11-04 triage at main 53b862123d7b8e4c9d039859fabdc9fc6ad4cd36: the worker-spawn catch still retains the reservation on cleanup-unconfirmed launch errors at the cited line. Added scope, verification and conditional contract guidance without selecting the retry owner.
2026-11-04 triage at main 53b862123d7b8e4c9d039859fabdc9fc6ad4cd36: Replaced the acceptance placeholder with checkable branch-specific criteria while preserving the unresolved owner choice. No new runtime qualification or implementation is claimed.
2026-11-08 decision reconciliation: selected the existing backend reconciler, explicit error-close handoff, unchanged retry/shutdown policy and confirmed-only accounting. Historical unresolved-option notes above are superseded; no implementation or new live-host reproduction is claimed.
2026-11-10 triage at main 3aadc8df5: #3815/#3823 moved the reconciler into packages/ui-sdk/src/server/cleanup-reconciler.ts and removed its terminal give-up. The policy and acceptance criteria now follow the current reconciler: indefinite capped retries, no "charged until restart". Added the cleanup-reporter handoff and the Pi exclusions (#3821). Re-verified the uncovered catch at worker-spawn.ts:191. The owner choice from the 2026-11-08 ruling is unchanged.
Activity
schlessera commentedon Nov 8, 2026
Decision (maintainer, 2026-11-08): Select option 1: the SDK launcher exposes a retryable close on the cleanup-unconfirmed launch error, and the Claude backend hands that close plus the retained reservation to the existing process cleanup reconciler from #2871.
Reuse its five bounded exponential retries (1s initial delay, 30s cap), unreferenced scheduling, terminal retained-allowance diagnostics and shutdown rules. Release accounting exactly once only after confirmed cleanup. Terminal refusal stays charged until restart; shutdown stops retries and releases nothing, even if an in-flight close confirms later. Do not add a second launcher-owned retry/accounting lifecycle.
The body now specifies the selected owner, handoff, lifecycle and meaningful boundary/mutation/native proof requirements. The current launcher handoff is internal, so assess actual supported API impact rather than assuming one. Remove
needs: decisionand addagent-ready; no otherneeds:label remains. No runtime or live-host reproduction is claimed.schlessera commentedon Nov 10, 2026
2026-11-10 triage at main
3aadc8df5: reconciled the body with #3815, delivered by #3823.packages/ui-sdk/src/server/cleanup-reconciler.ts.packages/ui-backend-claude/src/cleanup-reconciler.tsnow only re-exports it. Citations are repaired.CLEANUP_RETRY_ATTEMPTSrefusals. This supersedes only the policy half of the 2026-11-08 ruling, which said "reuse the existing policy". The owner and handoff choice (option 1: the shared reconciler, no launcher-owned retry) still stands, so no new decision is needed.worker_cleanupActivity notices backends, ui-server: keep reconciling uncertain worker, checkpoint and compute charges instead of giving up until restart #3815 added cover this path too.packages/ui-backend-claude/src/worker-spawn.ts:191.It stays
agent-ready, and no implementation is claimed.schlessera commentedon Nov 11, 2026
Claimed for implementation. Claim token:
claim-f1e3ea2a. Branch:fix/retry-cleanup-owner.Combined implementation with #3821 as requested. Collision scan is still running; no active implementation PR found for either issue.
schlessera commentedon Nov 11, 2026
Implementation handoff for
claim-f1e3ea2a: ready PR #3964, headbcc5ac40008eb05e54297a532a9c135b48c58222. It closes #3821 and #3489 together. The PR and both issues were read back on milestone 0.45.0.All scoped acceptance criteria have a verdict and supporting evidence in the PR body. Full root proof: 2,239 pass; all 301 touched-package test files: 2,854 pass with one expected delegated-cgroup capability skip; provider-history, no-console/process-exit, API report, 16-GB typecheck, lint and final check:pr passed. All four mutations fail their named assertions and pass after restoration. The exact full-suite head and the final test-only base refresh are recorded in the PR.
The native failed-launch broker boundary passed. The broader intermittent native resume failure remains documented in #2744; the ambient sandbox-note fixture failure and full cleared-environment pass are documented in #2769. Neither unrelated fixture is changed here. The collision scan found draft #3464 on the launcher path; the PR names that overlap.
No candidate confirmation or merge was performed. The coordinator owns hosted candidate proof, review and merge. Releasing this implementation claim for that handoff; the active PR preserves the work and must be checked before anyone starts another implementation.