Skip to content

fix(runtime): converge session cancellation before checkout reuse - #822

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/checkout-idle-reuse
Sep 19, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/checkout-idle-reuse

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Cancelling a session could leave its checkout claimed even after execution stopped, preventing a new conversation from starting. Cancellation now converges through the canonical runtime lifecycle and reports completion only after proving that the session no longer blocks checkout reuse. Session history is retained.

Pending cancellation returns HTTP 202 with settlement evidence and a typed blocker when available. CLI, SDK and harness consumers validate that evidence; terminal orphan cleanup releases only the exact internal writer after rechecking generation and ownership. Unknown tool outcomes remain fenced.

Related issue

Closes #821

Change type

  • Bug fix
  • Documentation
  • Test

User and compatibility impact

POST /sessions/{id}/cancel adds required execution_settled and per-run settlement fields. HTTP 200 means settled; HTTP 202 means cancellation is still pending. The CLI waits up to ten seconds and reports incomplete cleanup truthfully. SDK cancellation returns SessionCancellationResult. Clients must not infer checkout availability from a terminal display status alone.

Architecture and complexity delta

  • Canonical owner extended: run lifecycle cancellation and the session context coordinator's shared checkout-idle proof.
  • Existing implementations and callers searched: session handlers, run store, writer reservations, tool ledger, CLI/thin client, SDK and harness cleanup.
  • Replaced active-run-only cancellation completion and status-only client checks. No new storage tables or independent lifecycle state machine.
  • Database connection guards make cancellation during transaction setup safe; settlement and writer release remain generation- and owner-fenced.
  • Harness baseline extraction matches this branch's canonical sweeper initializer. Abstract Unix socket tests run on Linux and explicitly skip unsupported hosts.

Verification

Completed during implementation:

  • cargo check --locked -p astra-cli --all-targets: passed.
  • Targeted clippy for services, runtime, thin client and harness with -D warnings: passed.
  • make test-contract: 16 passed.
  • Thin-client unit suite: 190 passed; harness unit suite: 499 passed.
  • SDK typecheck and tests: 338 passed, 13 skipped.
  • Real MatrixOne checkout-reuse integration suite: 7 passed in a fresh isolated database.
  • Cancellation regressions: 6 offline and 6 MatrixOne cases passed; wire contract passed; all 5 delayed-BEGIN interruption points passed.
  • Independent GPT-6 review completed with no remaining findings after cancellation-safe connection fixes.

Final harness compatibility verification:

  • make format-check and git diff --check: passed.
  • macOS fresh-database contract suite: 14 passed, 2 Linux-only tests skipped.
  • Linux container (Python 3.12, PyYAML, git and procps): python -m unittest scripts.harness.test_benchmark_model_seed scripts.harness.test_case_history scripts.harness.test_fresh_database_contract scripts.harness.test_work_surface_live: all 42 passed, including both abstract socket tests. Shell syntax checks and bash scripts/harness/test_local_gateway_contract.sh passed.

Public entrypoints covered: session cancellation HTTP response, CLI cancellation polling, SDK response validation and harness exact-session cleanup. Unhappy paths include pending settlement, ambiguous/disconnected database operations, retained terminal authority, unresolved tools, ownership races and invalid cancellation proof. No schema migration is introduced.

Final checklist

  • Tests updated at the owning layers.
  • Public and design documentation updated.
  • Diff checked for credentials, private URLs, customer data and generated files.
  • Conventional Commit PR title.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of e125200: no actionable correctness findings identified. Posting as a comment because GitHub does not allow the authenticated PR author to approve their own PR.

Traced session-wide cancellation intent, retained terminal-run discovery, generation-scoped settlement evidence, exact writer/reservation release, the shared checkout-reuse proof and lock order, terminal tool reconciliation, cancellation-safe connection handling, and the HTTP/CLI/SDK response contracts. Unknown tool outcomes and externally supplied or pre-admission writers remain fenced; pending cancellation does not persist a cancelled Session projection. The one-second server budget is explicitly cooperative, with a separate hard deadline in the CLI.

Validation performed: SDK typecheck passed; SDK tests passed (338 passed, 13 skipped); git diff --check passed. Python fresh-database contract tests: 14 passed, 2 blocked by this environment's AF_UNIX socket restrictions. Rust and live MatrixOne tests were not run locally because this environment lacks the Rust toolchain and a configured database. Test Suite and Static Checks are still in progress at review time; this review does not replace those CI gates.

@XuPeng-SH
XuPeng-SH merged commit 5796410 into main Sep 19, 2026
26 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/checkout-idle-reuse branch September 19, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(runtime): converge cancellation before reporting checkout reuse readiness

1 participant