Skip to content

bug(cli): Ctrl+C before admission acknowledgement leaves a run active #1078

Closed

Description

@loveRhythm1990

Agent | Codex | Model/tier not exposed

Summary

Interactive Ctrl+C can return the composer to an apparently idle state while the Server has already admitted the request and continues executing it. If cancellation happens before the CLI captures the SSE run ID, notify_server_to_cancel_run() skips remote cancellation entirely. A subsequent message is rejected with Session execution is busy; the earlier run can remain waiting for local tool approval that the detached client no longer presents.

This is an explicit user-cancellation race, not permission to cancel Server runs on arbitrary transport errors.

Environment and evidence

Observed with a source-built Astra 0.2.12 CLI and matching Server revision 70a5ee3ec25bb3b02d3f591675a13abc33a85159 in QA. The relevant interactive cancellation path remains present in main 9e5f6e08.

Sanitized timeline from the same session (relative to Server admission):

  1. T+0: the Server durably creates the run for the user's document-analysis request.
  2. T+1.4s: the local journal records user_interrupted (Ctrl+C) and parent turn cancelled by user. That cancellation record has no physical Server run ID.
  3. T+23.9s: resubmitting the request receives session_execution_slot_occupied; the CLI restores the draft and says no model/tool ran for this rejected attempt.
  4. Read-only Server run/projection queries show the earlier run still exists, has executed model/tool work, and is waiting for tool_approval. Its durable events include an approval_required for Bash with delivery=edge_ledger.

The Pod was Ready with zero restarts. This evidence does not establish database slowness as the cause. No live run was cancelled or modified while collecting the evidence.

Reproduction

  1. Start an interactive turn against a hosted Server using local CLI/Edge tools.
  2. Delay delivery of the admission/run header after the Server accepts the request.
  3. Press Ctrl+C before the CLI observes the run ID.
  4. Allow the admitted Server run to continue, potentially reaching an approval wait.
  5. Submit another message in the same session.

Actual: the local turn is treated as interrupted, but the Server run is not cancelled and the next message is busy-rejected.

Expected: explicit cancellation must reconcile the in-flight admission and settle cancellation for the exact admitted run, or clearly retain an unresolved state with actionable recovery. The CLI must not imply that remote execution has stopped merely because its response stream closed.

Code evidence

  • crates/astra-cli/src/cli/turn/turn_stream_runner.rs, await_stream_with_interrupts: both signal and TUI cancellation cancel the local token, call the remote notifier, and drain the stream.
  • notify_server_to_cancel_run snapshots the incremental run ID only once. If it is absent, it logs no run_id captured yet; server-side cancel skipped and returns. It does not reconcile a subsequently admitted run.
  • crates/astra-cli/src/cli/turn/turn_cancellation.rs, apply_user_cancelled_turn: records a cancelled local turn using a silent UI, even when remote cancellation has not been established.
  • crates/astra-cli/src/cli/turn/turn_failure_reporting.rs: execution-slot conflicts use the generic busy message, without identifying the active approval wait or giving the same recovery guidance as writer conflicts.

Proposed approach and boundaries

  • Keep explicit user cancellation separate from callback/parser/network detachment; do not regress fix(cli): report callback detach without promising cancellation #867's no-implicit-user-cancellation contract.
  • Reuse the existing admission identity, exact-run cancellation, and bounded settlement owners. Cover cancellation before the first admission event, not just an already-observed run ID.
  • Do not cancel an arbitrary run selected by session ID; an unrelated/newer execution must remain untouched.
  • If admission/cancellation cannot be confirmed within its bounded budget, retain and visibly report the unresolved execution rather than silently implying success.
  • Preserve session/workspace fencing and approval requirements. No automatic approval, direct database cleanup, schema change, or timeout increase as a substitute for fixing ownership.

Acceptance criteria

  • Deterministic test: Server admits a run but delays its first response; interactive Ctrl+C still settles that exact run and releases its session slot.
  • Cover cancellation before admission, after admission, after a run ID is observed, and after the run has already reached a terminal state.
  • A slow/failed cancellation cannot be reported as confirmed success or silently drop the only recovery identity.
  • A newer/unrelated run is never cancelled by recovery of the interrupted request.
  • Internal transport/callback failures still detach without becoming user cancellation.
  • The next turn is admissible after confirmed cancellation; unresolved conflicts provide actionable recovery guidance.

Related: #987 and #916 concern abandoned execution after detachment; #1064 addresses one-shot SIGINT, whereas this report is the interactive pre-run-header cancellation window.

Activity

  1. loveRhythm1990 commented on Oct 19, 2026

    @loveRhythm1990
    CollaboratorAuthor

    Agent | Codex | Model/tier not exposed

    Draft fix: #1079. Not ready for review yet.

    The change retains the original response to observe its accepted run identity, then awaits the existing exact-run cancellation within the original bounded budget. It does not look up a cancellation target by Session or execute newly received tools/approvals after cancellation. Unconfirmed cancellation remains visible with explicit recovery guidance.

    The two new shared SSE regressions were verified to fail before the fix and pass afterward. The full shared SSE crate, focused CLI cancellation tests, repeat turn-module suite, formatting, and targeted Clippy have passed. Additional stream-render regression setup is being completed; full patched QA validation has not been run. No live run, deployment, database, or release version was changed.

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions