Repository navigation
fix(cli): settle interactive cancellation across admission - #1079
mergify[bot] merged 4 commits into
Conversation
|
Review of Overall: the PR targets the right defect from #1078. Previously the interactive path took a single snapshot of the run ID and silently skipped Server cancellation when it was empty. The fix stays inside the boundaries the issue sets:
The SSE change also looks correct. The identity check runs per event inside the chunk loop, so a tool or approval in the same chunk is never dispatched, and the grace is absolute despite keepalives. The tests cover this well. I found one behavioral problem that I think should be fixed before merge, plus a few smaller points. 1. Cancelling before dispatch now waits 10s and reports a false "may still be active" (should fix)
Now consider Ctrl+C before the POST is sent, for example during payload preparation (the "Preparing…" phase):
Before this PR, the same Ctrl+C returned immediately as a clean local cancellation. With this PR, the user waits 10 seconds, and the warning is false because nothing was ever admitted. Following the guidance runs a Session-level cancel. That could stop a run owned by another writer in the same Session, which is exactly what this PR otherwise avoids. The same 10s wait applies when the response finishes without an identity, for example an admission rejection that arrives after Ctrl+C.
Suggestion: run the steps one after the other instead of joining them. First drain, which already waits up to the grace period for the identity and stops right at it. Then issue the exact-run cancellation with the remaining deadline if a run ID was observed. This removes the polling loop. It also needs a way to tell "never dispatched" (clean local cancel, no warning) apart from "dispatched but no identity observed" (correctly unconfirmed). A typed marker on the failure would be better than matching the error string. 2. Smaller points
3. Coverage against the #1078 acceptance criteria
4. PR descriptionThe Verification section still says the stream-render suite rerun is "in progress". Please update it with the final result. CI checks for the changed crates were still pending when I reviewed. Basis: code reading of the diff and the surrounding code at |
The main finding is valid. Addressed in 7f3e191 (
Verification on this update:
The PR description's earlier stream-render rerun note had already been updated to 139/139 passed; that suite was also rerun successfully on this commit. No assertion was weakened or test skipped to obtain these results. The real patched CLI-to-QA journey, including proving subsequent admission against a live Server execution slot, has not been run. No Server state machine, database, deployment, or release version was changed. The PR remains draft / not ready for review. |
|
Fixed the CLI stack-overflow regression in commit Cause and fixThe base The new async cancellation settlement enlarged the ordinary turn's future even when cancellation was not selected. The admission bookkeeping wrapper also embedded the large inner stream future in its poll frame despite returning a boxed outer future. Cold tool-callback initialization then exhausted the test thread's stack. A/B checks showed that moving only one of these two boundaries to the heap was insufficient.
Verification
The first complete local run, using macOS's default symlinked temporary directory, had 4,912 passes and two unrelated privacy/file-undo failures ( Local verification was on macOS; Linux and broader workspace/live gates remain for CI. No QA or production environment was changed. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes on exact head 454dfe694ff4a044dcaec65d13c8a4f6df6d20c8: one reproducible pre-dispatch cancellation gap remains, detailed inline.
I reviewed all 11 changed files and the interactive owner → stream entry → payload/retry → authenticated HTTP send → shared SSE → exact-run cancellation → failure/next-turn settlement call chain.
- Design and correctness: retaining the same response, capturing only its root run identity, sharing the cancellation deadline, and using the existing exact-run settlement helper are appropriate. The new guard still precedes an asynchronous bearer wait; cancellation during that wait can start a new execution after Stop.
- Independent local evidence: 7 existing
interactive_canceltests and all 3 shared SSEcancelled_admissiontests passed. The actual-entry dispatch-evidence regression passed. A reviewer-only integration probe throughstream_chat_sse, the production HTTP/SSE consumer and settlement helper passed delayed admission → exact DELETE → a second turn in the same session (2 admissions, 1 exact cancellation). A second actual-entry probe blocked the admission BearerProvider, cancelled before any POST, then released it: the server received 1 POST instead of 0, asserted that the token was already cancelled, and returned a newly observed run. Only test code was temporarily added in an isolated checkout; it was retained as an evidence patch and then removed. - Isolation and cost: no database/schema/query changes, new global registry, or Session-based target lookup. Owner/run scoping and the existing bounded cancellation helper remain canonical. That helper can poll every 25 ms within the shared deadline; this is bounded, not a demonstrated concurrency/DB-cost result. The additional normal-path inner heap allocation and cancellation-only heap allocation trade allocation cost for stack headroom. Current-head CI independently passes the real restore/write-file regression and both disclosed privacy tests; I did not repeat the author's macOS A/B measurement.
- Complexity accounting: implementation +236/-63 = +173; tests +576/-0 = +576; documentation +22/-0 = +22. Total +834/-63 = +771, including comments/blank lines in their owning category. There is no substantive pure relocation to deduct. The added request-local fact and opt-in SSE deadline have real consumers; the old detached cancellation notifier is removed. The remaining dispatch-boundary issue prevents accepting the added complexity as a complete repair.
- CI and target: current required contexts were re-read from allowed main-branch metadata and rulesets, with complete check/review pagination: 12 success + 3 explained scope skips, GitHub Actions App 15368. Scope jobs 117962777639 and 117962776908 plus the workflow conditions explain core/web/SDK exclusions. Current-head CLI CI reports 4,952 passing tests; the turn-core/services/plan job reports 5,456. No result was inherited from the earlier failing PR heads.
- Optional live evidence: Harness run 39223082664 finished 17/18, failing
flash_missing_child_model_fail_closed: two rejected/not-executed agent calls, first missing/description, versus an expected single call. The affected changes do not modify the tool schema, model prompt, or child-model selection. I found no causal connection to cancellation; that is a source-based inference, not a claim that this failed run passed or that a live baseline was rerun.
The PR's reported base and actual merge-base are 9e5f6e08f7043644a9fb9afec9d0a39403f4ce30; live main advanced to 6074382318e85c5b1d01272016f4fd11f2766167 (#1058). I inspected its browser-launch/login/TUI delta: no changed-file overlap, unchanged bearer/stream owners, and a clean local merge-tree. The combined tree was not built.
Limits: local transport probes used a supported read-only tool allowlist and an explicit fixture executor identity because this sandbox's canonical home and /tmp ownership prevent ordinary mutating-workspace admission. Those prerequisite failures were not treated as product regressions. No real Server/DB execution-slot, native OS-signal/TUI, Windows/WSL, concurrent-user/load, production/QA, or paid-provider verification was performed.
454dfe6 to
2ca9abd
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Approve exact head 2ca9abde0c01896498210b685c568f585827106e, reviewed against both merge-base and current main c08cf4bb2bb0a458d1fd8d923212f12e91b979a7. No material findings remain after reviewing all 12 changed files and the admission/authenticated-send/SSE/cancellation/render/failure/next-turn call chain.
Previous finding verified closed. Review 5569262862 and comment 4312090457 remain evidence for original commit 454dfe69 (original R1517/position 46); their placement on this head at R1518/47 does not make them a current-head review. The single-attempt and retry paths now share one authenticated send helper. It awaits credentials before calling the existing payload factory, with no intervening await before send. That places cancellation, budget refresh and sticky dispatch evidence at the correct boundary while retaining a response once sending begins.
Independent verification on this head:
- The original reviewer-only real-
stream_chat_ssebearer-wait reproducer now passes: cancelling before releasing the bearer leaves 0 POSTs, rather than the previous 1. The shipped first-attempt/retry bearer regression also passes, including retaining the earlier physical dispatch when a retry is stopped. - The independent delayed-admission → exact cancellation → next turn probe passes with 2 admissions and 1 exact DELETE. The 7 existing
interactive_canceltests pass. All 200 ThinClient library tests pass. - The broad
server_admission_filter finishes 36 passed, 1 failed locally. The failure is the unchangedone_shot_edge_registration_requires_server_admission_and_honors_deadlinefixture indexing an empty registration-request list. I traced its pre-POST materialization call and independently invoked that same API: this sandbox returns read-only-filesystem for canonical~/.astra/edge-materializations. This path precedes the modified helper and is unchanged by this PR; the same test passes in current-head CI. This local failure is disclosed, not counted as a pass or bypassed. - Current-head CI logs independently confirm 4,985 CLI tests passed, including the bearer regression, real restore/write-file stack regression, and both previously disclosed privacy tests. The core/bridge job passes 3,990 tests, including authenticated-send protocol, shrinking-budget and expired-admission tests. Source diff checks pass. The first three rebased commits have identical patches by range-diff; the relevant source is byte-identical to the previously reviewed versions before the fourth commit's focused fix. No old-head CI result was substituted.
Design, isolation and cost. The original physical response and its root identity remain authoritative; the captured owner and existing exact-run helper own remote cancellation. Internal callback/transport detach does not gain user-cancel authority. Unknown identity, failed/pending cancellation and force-exit stay unconfirmed; same-chunk tools/approvals are suppressed for opted-in hosts, zero-grace hosts retain their existing handling, and the one total cancellation budget remains bounded. Busy-slot rejection retains draft/recovery guidance. No database schema/query/transaction, global registry or parallel durable state machine is added. Cancellation still uses the existing bounded 25 ms polling helper, so this review makes no concurrency/DB-cost scale claim. The extra stream/cancellation heap boundaries trade allocation cost for stack headroom; the public single-attempt wrapper also clones its JSON Value once to share the send owner. The normal CLI factory already owned its payload clone.
Complexity accounting, including comments and blank lines in their owning category: implementation +262/-67 = +195; tests +674/-0 = +674; documentation +26/-0 = +26; total +962/-67 = +895. No substantive pure relocation is being credited. The net implementation growth is a cost, justified here by exact-run recovery, one consumed request-local dispatch fact, bounded opt-in identity drain, and a shared authenticated send boundary replacing the detached notifier without duplicating a transport or cancellation protocol.
Optional live result: Harness 39258408422 completed 17/18, failing same_model_fanout_handoff_flash: two rejected/not-executed calls, zero successful fanout and zero children; one outcome reports invalid_request, the other not_reported. The safe summary explicitly does not identify the invalid input, and judge decision diagnostics are unreported. I checked the unchanged case and relevant normal/control flow; these changes do not modify fanout schemas, child admission, tool arguments or adoption. I found no demonstrated causal link to this patch. That is an attribution limit, not a claim that the live case passed, was an infrastructure failure, or was rerun.
Limits: local stream probes used the supported read-only tool allowlist, explicit fixture executor identity and temporary local state because this sandbox cannot initialize the canonical identity/coordination roots. Only reviewer test code was temporarily added in the isolated checkout and then removed; product sources and both checkouts are clean. No real Server/DB execution-slot, native OS-signal/TUI, Windows/WSL, multi-user/load, QA/production or paid-provider validation was performed. Required contexts/sources, complete pagination, identity, open state, exact head, prior body hashes/original anchors and sole reviewer ownership are rechecked before submission; current admission is 13 successful required contexts + 2 officially scope-excluded web/SDK checks, App 15368.
Merge Queue Status
This pull request spent 16 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
Summary
Fix the interactive cancellation/admission race reported in #1078. This does not publish a binary or change a running environment.
Rebased onto upstream
mainatc08cf4bb2bb0a458d1fd8d923212f12e91b979a7. The three existing commits replayed without conflicts or patch changes.Related issue
Closes #1078
Related contracts: #867, #987 and #1064. This addresses explicit interactive cancellation, not automatic cancellation on internal failure.
Change type
User and compatibility impact
Interactive Ctrl+C/TUI cancellation waits for confirmation of the exact admitted run within the existing ten-second budget. A second interrupt may force an unverified exit; that is not presented as confirmed cancellation. Cancellation while admission credentials are pending does not start a new Server execution when they resolve.
No Server API, database schema, dependency, release version or configuration changes. Other SSE hosts retain default immediate-cancellation behavior. The existing public ThinClient method signatures are unchanged. No production/QA sessions were modified or cancelled.
Architecture and complexity delta
SseStreamHostexposes an opt-in identity-only drain, defaulting to zero. ThinClient's existing authenticated send path owns the final per-attempt preparation boundary.cancel_exact_run_until_settled_with_deadlineand the existing recovery text.Verification
Current rebased tree, using the canonical macOS temporary directory (
TMPDIR=/private/tmp):cargo test --locked -p astra-cli --lib server_admission_ -- --nocapture: 37 passed, including the new real-entry HTTP regression.cargo test --locked -p astra-thin-client --lib: 200 passed.cargo build --locked -p astra-cli --bin mock_mcp_server: passed; prepares the existing MCP fixture before the complete library inventory.cargo nextest run --locked -p astra-cli -p astra-thin-client -p astra-turn-core --lib --profile ci --test-threads 2 --retries 0 --status-level fail --final-status-level fail: 8,500 passed, 23 skipped; retries disabled.cargo clippy --locked -p astra-cli -p astra-thin-client -p astra-turn-core --all-targets -- -D warnings: passed.cargo fmt --all -- --check: passed.python3 -m unittest discover -s scripts/ci -p 'test_*.py': 132 tests, OK with 5 existing skips. The first run without canonicalTMPDIRhad two macOS/varversus/private/varpath comparisons fail; rerunning with the canonical directory passed without changing tests or assertions.python3 scripts/ci/validate_repository.py: passed.git diff --check: passed.Public entrypoint: the new regression calls the real
stream_chat_sseagainst a local HTTP peer and a gated BearerProvider. It cancels while the first admission's bearer is pending (zero POSTs remain zero, with positive not-dispatched evidence), and while a retry's bearer is pending (one earlier POST remains one, with sticky dispatched evidence). It continues polling the same future after cancellation instead of dropping and recreating it.Other covered unhappy paths include delayed run identity, same-chunk tool/approval suppression, absolute grace deadline despite keepalives, unknown identity, rejected and pending cancellation, completion racing cancellation, and busy admission with draft recovery. Existing HTTP/SSE settlement coverage requires only the original response plus exact-run cancellation, with no local tool effect, Session lookup or replay.
Earlier local runs disclosed an absent MCP fixture and an intermittent transcript-persistence assertion; neither was hidden by weakening assertions or adding skips. The fixture is now explicitly built before the full inventory. The prior optional live harness run reported 17/18, failing
flash_missing_child_model_fail_closed; this follow-up does not claim that live run passed or rerun it.Database verification is not applicable: Server transitions, schema, queries and transactions are unchanged. Real Server/DB execution-slot, QA/production, native OS-signal/TUI, Windows/WSL, load and paid-provider validation were not run. Full-workspace and platform gates remain CI responsibilities. The existing macOS compact-unwind linker warning is not treated as a passing or failing assertion.
Final checklist