Skip to content

fix(cli): separate server resume authority from local turn accounting - #1067

Merged
XuPeng-SH merged 5 commits into
mainfrom
fix/cli-server-resume-authority
Oct 19, 2026
Merged

XuPeng-SH merged 5 commits into
mainfrom
fix/cli-server-resume-authority

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

An explicit Server-canonical TUI restore could be replaced by the local journal at the next turn. Mixing the independent Server and local clocks also tagged file edits with historical turn numbers, allowing current-turn rollback to affect earlier files.

Keep authenticated Server continuation authority across consecutive turns while allocating local execution, rollback, checkpoints, traces and commits from the leased local journal. Server admission owns its turn sequence, and terminal feedback is validated by accepted session/run/model and receipt identity. Resume authentication reuses captured-owner refresh, including one typed pre-execution 401 retry.

Local trace recovery retains the canonical publishing turn alongside each cached trace, so delayed journal/workspace repair cannot replace newer live evidence or mistake a session head for trace freshness.

The real restore/write/rollback regression also exposed accumulated async polling stack at the first tool callback. The shared stream entrypoint now heap-pins its owned future for every CLI caller, preserving the existing cancellation, drain and settlement scopes.

Related issue

Closes #1063.

Change type

  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test

User and compatibility impact

Explicit Server restores retain canonical conversation content across turns; local rollback and persistence use the correct local sequence even when either replica is ahead or the local journal is empty. Stream execution fits ordinary caller stacks without a larger CI/test stack. No configuration or dependency changes beyond rebasing current main. Removed predicted Server-turn inputs and updated all runtime-feedback callers; no legacy compatibility path remains.

Architecture and complexity delta

  • Canonical owners extended: existing local journal allocation/CAS and execution lease, Server canonical resume/admission, captured-owner authentication, terminal SSE receipts, atomic owner-scoped workspace updates, and the shared CLI stream entrypoint.
  • Existing callers searched: restore, interactive admission, stream construction, auth retry, feedback ingestion, local settlement, one-shot execution and workspace inspection.
  • Superseded code removed: duplicated admission token resolution, unnecessary transcript materialization, predicted Server sequence input, and redundant consumer-side future boxing.
  • No parallel lifecycle, clock, storage projection, credential refresh or compatibility shim. The same stream future remains awaited and dropped within existing cancellation/drain/lease scopes.
  • Performance: an explicit Server-restored attachment performs one authenticated resume read per turn, bounded by the existing 30-second deadline and cancellation token. All CLI streams add one heap allocation for their execution future; no throughput claim is made.

Verification

Validated against rebased main 70a5ee3ec25bb3b02d3f591675a13abc33a85159 with pinned Rust 1.97.0. Ordinary-stack checks leave RUST_MIN_STACK unset. Rust ThreadSanitizer uses nightly-2026-10-12, instrumented standard library, an explicit Linux target and isolated disk build artifacts.

  • cargo test --locked -p astra-cli --lib tests::resume_tests::server_restore_real_turn_keeps_rollback_checkpoint_and_journal_on_local_clock -- --exact --nocapture: passed on the ordinary stack.
  • Prebuilt mock_mcp_server, then cargo nextest run --locked -p astra-cli --lib --bins --profile ci: 4899 passed, 20 skipped. The first full run hit an unchanged 1-second registration/mock-arrival check; exactly three direct controls and one bounded complete rerun passed without source or deadline changes.
  • cargo nextest run --locked -p astra-turn-core -p astra-services --lib --profile ci -E 'package(astra-turn-core) or test(session_journal::) or test(session_workspace::)': 3565 passed.
  • Incremental SCA: cargo clippy --locked -p astra-cli -p astra-turn-core -p astra-services --all-targets -- -D warnings: passed.
  • Incremental race UT: RUSTFLAGS=-Zsanitizer=thread CARGO_INCREMENTAL=0 cargo +nightly-2026-10-12 nextest run -Zbuild-std --target x86_64-unknown-linux-gnu --locked -p astra-cli -p astra-turn-core -p astra-services --lib --profile ci --test-threads 2 -E 'package(astra-turn-core) or test(session_journal::) or test(session_workspace::) or test(cli::session::session_startup::) or test(cli::session::session_restore_client::) or test(/resume/) or test(cli::turn::) or test(tests::chat_stream_tests::) or test(/context_trace|context_panel|context_window|context_breakdown/)': 3996 passed, no race report. Scope includes all turn-core tests, services journal/workspace, CLI restore/admission/turn/settlement and context consumers. The real two-turn restore/tool regression passed under TSan as well; tests outside this expression were not counted as covered.
  • make format-check, python3 scripts/ci/validate_repository.py, and diff whitespace validation: passed.
  • Compiler layout and compiled poll-frame comparison confirm reduced parent state/stack while preserving the stream body; the shared-entry regression enforces a pointer-sized returned future.
  • GitHub CI for the updated PR head is pending; historical CI is not substituted for these current-code checks.
  • Public entrypoint exercised: a deterministic loopback fixture calls actual restore and the normal TUI turn entrypoint twice through admission, Server SSE tool callbacks, write/current-turn rollback and local settlement; local-ahead, Server-ahead and empty-local cases. Assertions cover historical file preservation, current file rollback, local journal/checkpoint/trace clocks and accepted Server feedback after hydration.
  • Unhappy paths exercised: owner/session/attachment changes, native origin binding, typed 401 once-only refresh, repeated 401/403/refresh failure, unowned bearer isolation, cancelled/timed-out admission, failed primary append, and workspace publication across an intervening local commit.
  • Database verification: not applicable; affected services paths are local journal/workspace operations. No database schema, query, paid provider or deployment changed.

Final checklist

  • Tests cover the owning layers and existing consumers.
  • Updated the runtime lifecycle contract.
  • Checked the diff for sensitive information and generated files.
  • Conventional Commit title.

@XuPeng-SH
XuPeng-SH marked this pull request as ready for review October 18, 2026 12:59

@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.

Code recommendation: APPROVE for 910d1921afbf311a88e7aa58e348c58425ff8824. No blocking findings in the final 10-file change after independent source and evidence review. This is a COMMENT review because the connected account is also the PR author; it is not an approval vote.

The fix separates transient official Server request inputs from the existing leased local journal allocation and commit base. I checked consecutive turns in both clock directions, empty replicas, failed-append rollback and reattachment, owner/session/attachment changes, captured-owner expiry/skew and typed 401 retry, environment bearer isolation, cancellation and timeout, and workspace publication across an intervening local commit. The explicit-owner lease/workspace entrypoints reuse the existing fences and atomic update; canonical CAS and stale-sidecar guards remain intact. The final helper change is confined to cfg(test).

Fresh verification found all 15 exact required contexts successful from GitHub Actions App 15368, with all 40 check runs paginated through an empty terminal page. Actual CLI CI checked out merge f6e95f01e0a2a6175e2febad2d762c161909b40b (this head plus current main f0dd007b, including native CA trust): 4883 library/binary tests passed, plus 3 supervisor tests. The new restore/clock/race/auth tests passed by exact name. Services CI passed 5452 tests, including both explicit-owner regressions. Lint actually ran Clippy, formatting and audit successfully; audit retained 3 allowed warnings. Separate validation checkout 46b6339b passed all 4 helper-calling tests; release 81f45c64 does not contain the cfg(test) helper correction.

The optional live harness remains red on this exact head: 17/18 passed; flash_child_question_parent_answer failed its hard child-adoption check with question_unanswered. I inspected its own safe log and did not substitute another PR's result. This review does not claim all checks green or completed integrated live TUI acceptance. No Cargo or provider calls were initiated by the reviewer.

Source binding: tree 4937d75bceb2bb7796c85f4ac8f5f1b138d028b6; diff SHA-256 e30bd2579771148ecc1f689e45d8e79471accc204b948fd36c4e2755551b6647 against PR base ee07dcfc. The worktree and all changed-file hashes were unchanged before submission.

@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.

Historical supplement to review 5563404667, anchored to its reviewed commit 910d1921afbf311a88e7aa58e348c58425ff8824: combined cancellation/resume acceptance remains ON HOLD.

Fresh PR metadata now shows head 86610bf018e2f7edd0d643299b068cecdf18ede3 and base c2f8f47582cd0761d68c643b0f8e5187d65d10b6. That is a later merge of main. I have not completed the exact-head formal gates or code review for 86610bf0, and this historical COMMENT grants it no code approval. The original review and its anchor remain unchanged.

The subsequent real combined test on integration 81f45c643d24afd326000e8a9313f68ece0f2e75 failed. SIGINT during Bash produced structured interrupted / user_interrupted / partial JSON and exit 5, and exact-run cancellation reported execution_settled=true. Nevertheless, a same-session one-shot resume after a further 25.042-second observation window returned exit 5 with an authoritative interrupted Server result after 9 rounds. Local write_file/Bash work was refused with workspace_ownership_unsettled; the requested new file was not written, while the old delayed effect remained absent. The successful cancellation observations therefore do not establish successful cancellation-and-resume acceptance.

I independently compared the actual integration's shell and sandbox-helper source with baseline 13797cce49dce352669c9ccc4f8d28f75712144e: edge_tools/shell.rs is byte-identical (SHA-256 8c608a1aed5e66fa65419e109d3f28004ca1f5a6967d07c89305bb7b6a93a72c), as is astra-sandbox/src/process_isolation.rs (2aa515aedcb0d84600d5f15257a0b6db314189df1f01cab7c9642aa381b7b7a1). The existing settle_subreaper_children path returns None immediately if child enumeration fails after waitpid(..., WNOHANG) reports zero, instead of obtaining the canonical ECHILD receipt. That existing local settlement/ownership-fence path explains the failure boundary; a settled Server run does not clear the persistent local quarantine. This case exercised the one-shot entrypoint, not this PR's TUI restore/admission clock path, and does not demonstrate a defect in the reviewed Server/local clock or owner-workspace changes.

The earlier code recommendation applies only to the inspected 910d1921 TUI changes and their stated evidence. It must not be used as acceptance for one-shot resume, every entrypoint, or the complete combined release. The existing SIGINT repair must preserve canonical settlement proof and ownership guards, and the corrected behavior must pass real validation before this hold is lifted. A new proof must not silently clear the old workspace fence. No new approval vote, readiness change, product edit, Cargo run, provider call or replay was performed by this reviewer.

@XuPeng-SH XuPeng-SH changed the title fix(cli): preserve explicit server resume across turn admission fix(cli): separate server resume authority from local turn accounting Oct 18, 2026
Peng Xu and others added 5 commits October 19, 2026 11:46
Keep local journal allocation consistent across restore, tool mutation, rollback,
checkpoints and traces. Bind remote feedback to accepted execution identities
instead of predicting a Server turn. Recover one typed pre-execution resume
401 through the captured credential owner and preserve native origin binding.

Add real two-turn rollback coverage, auth rejection matrices and updated
runtime lifecycle documentation without compatibility shims.
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.

[Bug]: TUI turn admission overwrites explicit Server resume with local journal state

1 participant