fix: preserve resumed agents after accepted turn cancellation (#3791)

This commit is contained in:
Carlos Florêncio
2026-09-18 10:33:26 +01:00
committed by GitHub
parent b1b095f0c0
commit 2f15db8a14
21 changed files with 2069 additions and 32 deletions
+7
View File
@@ -213,3 +213,10 @@ pass.
The [error scope package](../error-scope-and-history/plan.md) supersedes the session card placement and removal behavior.
Completed results here remain historical evidence. Provider recovery, timeout budgets, cancellation, and authorization remain unchanged.
The successor owns chronological error retention, ordinary scroll behavior, and shared task alerts.
## Accepted-turn cancellation successor
The [resumed turn cancellation package](../resumed-turn-cancellation/plan.md)
corrects startup authority that remains active after prompt acceptance.
It adds process-survival and follow-up assertions to the existing cancellation coverage.
This completed record and its verification results remain historical evidence.
@@ -98,3 +98,10 @@ identities use an explicit prefix, bind the first callback execution
atomically, and fail closed for untagged or compacted callbacks. Dynamic launch
callbacks preserve their originating resume context instead of borrowing the
current replacement identity.
## Accepted-turn cancellation successor
The [resumed turn cancellation package](../resumed-turn-cancellation/plan.md)
corrects startup authority that remains active after prompt acceptance.
It adds process-survival and follow-up assertions to the existing cancellation coverage.
This completed record and its verification results remain historical evidence.
@@ -0,0 +1,187 @@
---
created: 2026-09-18
status: complete
requirements:
- REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007
system_design:
- ../../specs/agents/system-design/session-recovery-failures.md
legacy_specs: []
---
# Implementation Plan: Preserve Resumed Agents After Pause
## Overview
Preserve the healthy agent process when the user pauses an accepted resumed turn.
One sequential work order implements the ownership correction and its service and browser regressions.
Implementation is complete.
## Evidence and root cause
The reported session is `7c6a9ba2-e2be-4ff8-bf56-d0e339fee3df` in task
`742b1dca-39bc-4035-856b-39240f0b9340`. The running build was `81b59416ab`.
The provider session was `01a0b19b-c373-7853-9c0e-7c68e9c2b196`.
Backend diagnostics establish this September 18 timeline in Europe/Lisbon:
| Time | Event |
| --- | --- |
| 00:32:01 | Resumed execution `5e11de73-89a6-4fb6-8f0c-a53a892859b0` accepts work. |
| 00:37:26 | The user requests turn cancellation. |
| 00:37:30.341 | The provider completes cancellation normally. |
| 00:37:30.450 | Kandev force-stops the execution as `cancelled resume startup`. |
| 00:37:33 | Kandev removes the instance and execution tracking. |
| 00:37:35 | The next user message finds no agent and requests another resume. |
| 00:37:46 | Replacement execution `94b839f4-0c9e-4a91-ba87-74c557295d16` becomes ready. |
The source confirms that `promptTask` defers attempt completion until its blocking
prompt call returns. `runExplicitCancellationOwned` invalidates that attempt.
`finishPromptExecutorDispatch` then invokes startup cleanup after normal turn cancellation.
The same defect can recur during the first turn of each replacement execution.
Evidence came from diagnostic bundle `b581ffed368b708481e536590e5d5847`.
The archive byte limit truncated older history, but the incident window is present.
This package uses the existing trace and source inspection plus deterministic service and browser regressions.
## Requirement conformance
The agents system owns provider continuity and startup attempt outcomes.
The [existing requirement](../../specs/agents/requirements/session-recovery-failures.md)
adds criteria 007.7 through 007.9 for accepted-turn cancellation and process reuse.
Criteria 007.2 through 007.4 retain startup fencing, retry, and disconnect protection.
The [design amendment](../../specs/agents/system-design/session-recovery-failures.md#accepted-turn-ownership-requirement-007)
separates startup authority from execution identity.
The completed [resume cancellation package](../resume-cancellation/plan.md)
remains the baseline. Its recorded results remain historical evidence.
Its acceptance-barrier test permits `ErrResumeAttemptCancelled` after acceptance
and never asserts process survival. This package closes that coverage gap.
Other contribution recovery, error-history, and resume-queue packages retain their scope and results.
## Scope
### In scope
- Transfer startup cancellation authority at provider acceptance.
- Preserve accepted execution callbacks, runtime identity, and normal cancellation outcomes.
- Keep model-switch fallback startup cancellable until lifecycle reports initial-prompt acceptance or failure.
- Cover lazy resume, compound resume-and-prompt, handler retry, and relevant model-switch paths.
- Preserve cancellation before readiness, queued work, and exact replacement cleanup safety.
- Prove pause and follow-up behavior on desktop and phone.
### Out of scope
- Changes to workflow parking, explicit runtime stops, archive, or restart recovery policy.
- Removal of cancellation timeout escalation when a provider does not settle.
- New UI layout, labels, APIs, schema, flags, provider fallback, or automatic replay.
- Mutation of the reported live session or implementation during this design turn.
## Technical approach
Use the accepted phase described in the owning design. Integrate it into
`resume_attempt.go`, the prompt acceptance callback, and cancellation cleanup.
The existing cancellation guard serializes transfer and cancellation.
Registry completion and tombstones retain event provenance after the transfer.
Publication errors after provider acceptance remain accepted outcomes.
Audit the compound continuation and model-switch return paths for stale startup checks.
Do not fix only the final cleanup call while leaving valid events classified as stale.
## Tests
Add `task_operations_resumed_turn_cancellation_test.go` with these named regressions:
| Test | Criteria and evidence |
| --- | --- |
| `TestPromptTask_ResumedTurnCancelPreservesExecution` | 007.7-.9: first resumed turn accepts, pauses, preserves execution/token, and accepts the next message once. |
| `TestResumeTaskSessionAndPrompt_AcceptedTurnCancelPreservesExecution` | 007.7-.8: outer compound continuation cannot reclaim an accepted runtime. |
| `TestResumeAttempt_AcceptanceCancellationOrdering` | 007.2-.4, .8: barriers prove cancellation before acceptance and after acceptance, including duplicate acceptance callbacks. |
| `TestResumeAttempt_AcceptedExecutionEventsRemainValid` | 007.2, .9: token, stream, and completion events remain valid after pause; stale/replaced events remain rejected. |
| `TestResumeAttempt_AcceptedPublicationFailureDoesNotCleanup` | 007.8: accepted publication failure causes no startup teardown, rollback, or replay. |
| `TestResumeAttempt_ModelSwitchFallbackTransfersAcceptance` | 007.8: a replacement execution launched by model-switch fallback inherits accepted-turn ownership. |
| `TestResumeAttempt_ModelSwitchFallbackCancellationBeforeInitialPromptAcceptance` | 007.7-.8: cancellation after process startup but before asynchronous initial-prompt acceptance force-cleans the replacement and fences a delayed callback. |
| `TestPromptTask_QueuedAcceptedTurnIdentityReadFailurePreservesExecution` | 007.7-.9: a queued dispatch with a nonempty incarnation transfers ownership before an injected identity-read failure and preserves the same execution for pause and follow-up. |
Use real service paths with controlled provider barriers. Assert zero forced-stop
calls after successful turn cancellation. Include both nil-error cancelled results
and the existing provider cancellation error form. Preserve unrelated queued work.
The compound regression uses the wrapped `ErrCancelEscalated` provider cancellation form.
Add handler retry cases in their existing test files if those paths differ.
A mere successful return or unchanged boot-row count does not prove process survival.
The queued-dispatch regression also observes the ordinary `afterDispatch` hook and
proves that acceptance has already revoked startup cleanup authority before that
hook or any fallible identity publication read can run.
## E2E tests
Extend `session-recovery.spec.ts` in `chromium` and
`mobile-session-resume-recovery.spec.ts` in `mobile-chrome`.
Use the existing isolated backend and mock provider.
Make the first message perform lazy resume while passive resume is disabled.
Wait for actual accepted work before clicking or tapping Pause.
After cancellation settles, submit a follow-up through the composer.
Assert a response, unchanged execution/provider identity, and no added durable boot event.
Repeat pause and follow-up on that same execution to cover later turns.
Capture the initial runtime identity after the first message is accepted and before
the first pause. For the second pause, snapshot the existing persisted response
message IDs and wait for a newly persisted response ID before pausing, so the witness
cannot match the first turn's output. Compare the runtime identity after cancellation
and after each follow-up.
The phone case retains reachable touch controls and no horizontal page overflow.
Keep existing delayed-startup cancel/retry scenarios as the negative-boundary coverage.
No rendered structure changes are planned, so an ASCII UI preview is unnecessary.
The existing task chat and mobile session layout remain the interaction exemplars.
## Work orders
- [x] [Task 01: Transfer startup ownership at prompt acceptance](task-01-transfer-startup-ownership.md)
## Verification results
Implementation is complete. The first RED run of
`TestPromptTask_ResumedTurnCancelPreservesExecution` failed with
`resume attempt cancelled: resume-1` after provider acceptance, reproducing
startup cleanup of the accepted execution. The final verification block passed:
- `pnpm install --frozen-lockfile` from `apps`: passed.
- Focused orchestrator race suite for accepted cancellation, ordering, events,
publication failure, and model-switch acceptance: passed.
- Queued accepted-turn regression with injected identity-read failure and
same-execution follow-up: passed.
- Full affected-package race suite for orchestrator, executor, lifecycle, and
task handlers: passed.
- Chromium `session-recovery.spec.ts`: 7 tests passed.
- Mobile Chromium `mobile-session-resume-recovery.spec.ts`: 4 tests passed.
- Web typecheck: passed.
- `python3 scripts/list-docs.py validate`: passed.
- `python3 scripts/lint-spec-files.py --all`: passed.
- `git diff --check`: passed.
- Model-switch lifecycle callback propagation and pre-acceptance cancellation barrier: passed.
The browser helper counts persisted `agent_boot` metadata because the boot row's
content is empty and the rendered resume label is deduplicated. The package is
uncommitted, as required by the work order.
Design validation on 2026-09-18:
- `python3 scripts/list-docs.py validate`: passed (288 decisions, 1004 specifications).
- `python3 scripts/lint-spec-files.test.py`: passed (36 tests).
- `python3 scripts/lint-spec-files.py --all`: passed.
- Package links and acceptance references: passed.
- `git diff --check`: passed.
- `git status --short -- docs/plans/resumed-turn-cancellation`: both new package files are present and untracked.
Implementation verification is complete. The package remains uncommitted for review.
## Documentation impact
Internal requirements, design, and delivery records change. Public documentation
has no new command, configuration, control, or recovery procedure to describe.
The existing cancellation ADR is sufficient for this local boundary correction.
No new ADR or system index inventory is necessary.
## Risks
- Early transfer can let cancelled startup dispatch. Late transfer can kill accepted work.
- Deleting identity evidence can reject valid events or admit stale callbacks.
- Callback publication failure can incorrectly restore startup cleanup authority.
- A guard held during provider settlement can deadlock cancellation.
- Passive browser recovery can hide the defect by launching a replacement before assertions.
@@ -0,0 +1,168 @@
---
id: "01-transfer-startup-ownership"
title: "Transfer startup ownership at prompt acceptance"
status: done
wave: 1
depends_on: []
plan: "plan.md"
requirements:
- REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007
acceptance_criteria:
- AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.2
- AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.3
- AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.4
- AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.7
- AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.8
- AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.9
system_design:
- ../../specs/agents/system-design/session-recovery-failures.md
---
# Task 01: Transfer Startup Ownership at Prompt Acceptance
## Summary
End startup cancellation authority when the provider accepts the resumed prompt.
Keep the execution identity valid so pause and follow-up use the same healthy process.
## In scope
- Implement the accepted phase and guarded authority transfer in the existing attempt registry.
- Integrate lazy and compound resume, prompt acceptance, final result handling, and exact startup cleanup.
- Audit handler retries and model switches for the same accepted boundary.
- Propagate model-switch startup acceptance and pre-acceptance failure callbacks through lifecycle.
- Add the named service regressions from the plan and desktop/phone process-reuse scenarios.
- Preserve pre-acceptance cancellation, stale-callback rejection, and unrelated queued work.
## Out of scope
New public contracts, UI components, provider policies, schema, workflow parking changes,
commits or PR delivery, and mutation of the reported live instance.
## Acceptance
1. Pausing an accepted resumed turn preserves the healthy execution and provider identity. Follow-up dispatches exactly once on that execution.
2. Cancellation before acceptance still fences startup. Accepted events remain valid while stale callbacks cannot affect a replacement execution.
3. Desktop and phone regressions pass through real cancellation and follow-up controls. Accepted publication failure causes no replay or startup cleanup.
## TDD and reproduction
First add `TestPromptTask_ResumedTurnCancelPreservesExecution` in the new test file.
Hold the resumed provider turn after its acceptance callback, then call `CancelAgent`.
Release normal provider cancellation and assert zero forced stops and unchanged execution identity.
Send another prompt and assert one delivery on that execution.
Run it before production edits. The expected failure is startup teardown of the accepted execution.
Do not accept unrelated setup failures as the red result.
Add the remaining named barrier regressions from the plan before each corresponding correction.
Use channels and bounded waits, not arbitrary sleeps.
Read the backend TDD reference before creating fixtures or subprocesses.
Write the desktop and phone scenarios before the correction and record the failing process-reuse assertion.
Use existing mock scenarios and isolated fixtures. Disable passive resume for the reproduction.
The first new message must trigger lazy resume and remain active after provider acceptance.
Use existing authorized test API reads for execution/provider identity and durable message IDs.
If the current helper lacks those fields, extend its typed read helper without adding a production endpoint.
Do not rely on the deduplicated visible resume label as the only evidence.
## Verification
Run the complete block from the repository root after implementation.
Install workspace dependencies once before the first frontend command in a fresh worktree.
The managed E2E runner rebuilds the binaries and serves the production web build.
Run the two browser suites sequentially without worker overrides.
```bash
(cd apps && pnpm install --frozen-lockfile)
(cd apps/backend && go test -race ./internal/orchestrator -run 'Test(PromptTask_(ResumedTurnCancel|QueuedAcceptedTurnIdentityReadFailure)|ResumeTaskSessionAndPrompt_AcceptedTurnCancel|ResumeAttempt_)' -count=1 -timeout=10m)
(cd apps/backend && go test -race ./internal/orchestrator ./internal/orchestrator/executor ./internal/agent/runtime/lifecycle ./internal/task/handlers -count=1 -timeout=20m)
(cd apps/web && pnpm e2e:run --project chromium tests/session/session-recovery.spec.ts)
(cd apps/web && pnpm e2e:run --project mobile-chrome tests/session/mobile-session-resume-recovery.spec.ts)
(cd apps/web && pnpm run typecheck)
python3 scripts/list-docs.py validate
python3 scripts/lint-spec-files.py --all
git diff --check
```
## Files likely touched
- `apps/backend/internal/orchestrator/resume_attempt.go`
- `apps/backend/internal/orchestrator/task_operations.go`
- `apps/backend/internal/orchestrator/task_operations_resumed_turn_cancellation_test.go` (new)
- `apps/backend/internal/orchestrator/task_operations_resume_cancellation_test.go`
- `apps/backend/internal/orchestrator/executor/executor_interaction.go` (only if acceptance propagation needs correction)
- `apps/backend/internal/agent/runtime/lifecycle/{types,manager_interaction,session}.go` (model-switch initial-prompt callbacks)
- `apps/backend/internal/task/handlers/message_handlers_resume_readiness_test.go`
- `apps/web/e2e/tests/session/session-recovery.spec.ts`
- `apps/web/e2e/tests/session/mobile-session-resume-recovery.spec.ts`
- `apps/web/e2e/helpers/session-resume-prompt-queue.ts`
- `apps/web/e2e/helpers/api-client.ts` (only if an existing identity read needs typing)
- This plan, work order, and the linked requirement/design amendment for result updates.
## Dependencies
None. Existing resume cancellation and provider acceptance callbacks are in this checkout.
## Risks
Keep transfer inside the cancellation guard, but never hold that guard during turn settlement.
Retain event provenance without keeping startup teardown authority alive.
Preserve accepted outcomes when publication fails. Do not replay ambiguous provider work.
Resume without a prompt, dispatch-only calls, and model-switch branches must retain their lifecycle rules.
## Parallelism
sequential
## Inputs
- [Requirements](../../specs/agents/requirements/session-recovery-failures.md#recovery-attempt-isolation).
- [Accepted-turn design](../../specs/agents/system-design/session-recovery-failures.md#accepted-turn-ownership-requirement-007).
- [Evidence and test matrix](plan.md).
- [Cancellation ownership ADR](../../decisions/2026-08-03-backend-owned-cancellation-progress.md).
- Existing `TestPromptTask_ResumeAttemptKeepsCancellationOutOfAcceptanceCallback` and same-execution replacement tests.
- Existing desktop and phone delayed-startup cancellation fixtures.
## Results
The first RED run of `TestPromptTask_ResumedTurnCancelPreservesExecution`
failed with `resume attempt cancelled: resume-1` after provider acceptance.
The fix adds an accepted phase to the resume-attempt registry, transfers startup
ownership at the ordinary dispatch callback and model-switch replacement boundary,
and retains the attempt identity for valid late provider events. Accepted cleanup
and invalidation are fenced while pre-acceptance cancellation remains cancellable.
The review correction makes the transfer use the captured execution identity and
occur before `afterDispatch`. It does not depend on a second session identity read,
so a queued dispatch with a nonempty incarnation cannot leave accepted work startup-
cancellable when that read fails. The new queued regression injects that failure,
observes the hook ordering, pauses the accepted turn, and verifies follow-up reuse
of the same execution.
The final verification block passed:
- `pnpm install --frozen-lockfile` from `apps`.
- Focused and full affected-package Go race suites.
- Chromium `session-recovery.spec.ts`: 7 passed.
- Mobile Chromium `mobile-session-resume-recovery.spec.ts`: 4 passed.
- Web typecheck.
- Specification catalog validation and full specification lint.
- `git diff --check`.
The accepted direct regression returns the provider's nil-error cancelled result.
The compound regression returns the wrapped `lifecycle.ErrCancelEscalated` form.
Publication failure and model-switch replacement regressions confirm that accepted
work does not trigger startup teardown or replay. The desktop and phone accepted-turn
scenarios capture runtime identity after the first accepted response, wait for a new
persisted response ID before the second pause, and compare that identity after every
pause and follow-up. The package is uncommitted and no live runtime state was changed.
The PR fixup review found that the model-switch fallback starts its initial prompt
from a lifecycle goroutine after `StartAgentProcess` returns. The implementation now
registers one-shot dispatch and pre-acceptance failure callbacks before startup,
keeps the resume attempt active until one of them settles, and transfers ownership
using the replacement execution ID captured by the launch response. The new
`TestResumeAttempt_ModelSwitchFallbackCancellationBeforeInitialPromptAcceptance`
barrier proves cancellation still force-cleans the replacement before provider
acceptance and that a delayed callback cannot revive the cancelled attempt.
Lifecycle coverage also verifies that the callback reaches the asynchronous initial
prompt acceptance point.
@@ -2,7 +2,7 @@
status: active
system: agents
created: 2026-09-11
updated: 2026-09-14
updated: 2026-09-18
owners:
- Kandev
---
@@ -60,10 +60,13 @@ This supersedes the reveal-at-top behavior from the completed startup recovery s
The task system owns durable history and shared error scope through
[task error ownership](../../tasks/requirements/task-launch-failure-recovery.md).
## Proposed recovery attempt amendment
## Recovery attempt isolation
The following requirement is draft. The existing requirements remain active.
Implementation belongs to the [resume cancellation package](../../../plans/resume-cancellation/plan.md).
Criteria 007.1 through 007.6 are implemented in the
[resume cancellation package](../../../plans/resume-cancellation/plan.md).
The accepted-turn amendment adds criteria 007.7 through 007.9. Its
implementation and verification are recorded in the
[resumed turn cancellation package](../../../plans/resumed-turn-cancellation/plan.md).
### REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007: Isolated recovery attempts
@@ -78,6 +81,10 @@ Implementation belongs to the [resume cancellation package](../../../plans/resum
- **AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.5:** A failed resume before prompt dispatch shall show the existing recovery card with the resume cause. It shall not claim that the agent is busy with a complex task. Reload shall preserve the applicable recovery action and failure details.
- **AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.6:** On desktop and phone, users shall be able to cancel startup and retry after cancellation settles. Existing recovery actions, touch targets, keyboard access, and transcript scrolling shall remain available.
- **AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.7:** After the provider accepts a resumed prompt, successful turn cancellation shall preserve the healthy agent process and saved conversation identity. The next message shall use that process without another startup, resume, or recovery error.
- **AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.8:** Cancellation concurrent with prompt acceptance shall have one outcome. Before acceptance, cancelled startup shall not dispatch. After acceptance, normal turn cancellation shall own the outcome. An accepted prompt shall not be replayed or reported as cancelled startup because its turn was paused.
- **AC-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007.9:** Desktop and phone shall support pause followed by another message during the first resumed turn and later turns. Valid responses and session updates shall continue after each pause. A further resume shall require an independently established loss or stop of the runtime.
## Out of scope
Automatic history replacement, new credential permissions, and changes to
@@ -2,7 +2,7 @@
status: draft
system: agents
created: 2026-09-11
updated: 2026-09-14
updated: 2026-09-18
requirements:
- REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-005
- REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-006
@@ -23,7 +23,7 @@ to own contribution admission and durable bootstrap failure projection.
| --- | --- |
| REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-005 | Workspace-only registration |
| REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-006 | Recovery presentation ownership; post-start recoverable failure detail; responsive amendment |
| REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007 | Proposed attempt isolation |
| REQ-AGENTS-AGENT-RESUME-RUNTIME-RECOVERY-007 | Attempt isolation; accepted-turn ownership |
The following amendments are implemented in the
[contribution resume recovery package](../../../plans/contribution-resume-recovery/plan.md).
@@ -270,3 +270,75 @@ Desktop and phone tests exercise the actual backend resume path and reload.
This applies the accepted [backend cancellation ownership decision](../../../decisions/2026-08-03-backend-owned-cancellation-progress.md).
It extends that implementation to startup attempts without a new durable state
or an alternative cancellation owner. No new ADR is required.
## Accepted-turn ownership (requirement 007)
This amendment clarifies the startup boundary in the preceding attempt
isolation design. The [repair package](../../../plans/resumed-turn-cancellation/plan.md)
records implementation and validation of criteria 007.7 through 007.9.
### Startup authority and execution identity
`resumeAttemptRegistry` owns startup cancellation authority. An attempt identity
also identifies valid runtime events after startup. These are separate responsibilities.
The registry must retain event provenance when startup cancellation authority ends.
Add an explicit accepted phase to `resumeAttempt`, protected by the registry
mutex. Transfer authority under the existing session cancellation guard.
The transition checks the current attempt and captured execution before acceptance.
It is idempotent and cannot revive an invalidated attempt.
`preparePromptDispatchCallback` receives provider acceptance through
`PromptWithDispatchCallback`. Record the accepted phase before releasing its
dispatch guard and before publication errors can select startup cleanup.
The callback is evidence of provider acceptance even when a subsequent durable
publication or `afterDispatch` hook fails. Preserve the existing accepted-error path.
Do not wait for the blocking prompt call to return before transferring authority.
`runExplicitCancellationOwned` continues to call `invalidateResumeAttempt`.
Invalidation cancels only attempts that still own startup. An accepted attempt
keeps its event identity while normal runtime cancellation settles the turn.
A cancelled turn does not cancel the accepted attempt context or confer startup
teardown authority. Shutdown and explicit runtime teardown retain their existing owners.
`finishPromptExecutorDispatch` and the compound resume continuation distinguish
accepted work from cancelled startup. Normal cancellation returns the turn outcome.
It does not roll back an accepted claim, decorate it as recovery failure, or
call `cleanupCancelledResumeAttempt`. Apply the same rule to model-switch paths
that bypass the ordinary prompt callback.
Retain normal deferred attempt completion so outer compound calls can finish
without treating the successful transfer as a missing registry owner.
Successful tombstones continue to authorize matching execution callbacks.
Both direct and identity-based startup cleanup reject accepted attempts.
Old cancelled attempts remain fenced, including reused execution IDs and retries.
Do not weaken execution generation checks or accept unknown callback identities.
### Entry points and failure boundaries
Apply the transfer to lazy message resume, `ResumeTaskSessionAndPrompt`, and
the handler retry path. Preserve the original identity across internal retry.
Resume without a prompt relinquishes startup ownership once readiness succeeds.
A later ordinary prompt must not inherit startup cancellation authority.
Before acceptance, cancellation still interrupts startup and prevents dispatch.
After acceptance, provider errors use normal prompt failure handling.
Publication failure does not authorize prompt replay or startup cleanup.
A provider that cannot settle cancellation retains the existing bounded escalation
policy. Archive, workflow parking, explicit stop, crash, and backend restart
remain independent reasons for runtime removal or recovery.
### Compatibility, presentation, and evidence
The change is process-local. It adds no durable state, public API, runtime flag,
locale string, or new interface control. Desktop and phone retain their existing
composer, pause control, cancellation progress, and transcript scroll owner.
Tests use those surfaces and require a successful follow-up on the same execution.
Visible boot-row count alone is insufficient because the UI deduplicates resume entries.
Barrier-controlled service tests prove both acceptance orderings and process
survival. They also prove valid events after cancellation and stale-event rejection.
The existing backend cancellation ADR remains authoritative. This local lifecycle
correction needs no separate ADR. Removing attempt tracking at initial readiness
is insufficient for compound resume because it leaves a pre-dispatch cancellation gap.
Removing all attempt checks would lose stale-callback protection.