Skip to content

fix(cli): preserve session state across reopen - #1315

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/1314-reopened-session-clock
Nov 17, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/1314-reopened-session-clock

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Capability assessment: Unchanged: CLI continuation already owns terminal-state recovery; this corrects its existing local journal semantics without adding capabilities or changing runtime profiles.

Summary

Reopening a CLI session discarded terminal facts before the latest session-start marker. A committed conversation at turn 5 could then reject the next response as turn 1. A failed-only session also reset from turn 1 to 0 and reused the failed turn's number.

Recover all successful and failed terminal facts for the same session ID in one pass. Turn allocation, display history, usage, recent tools and the last terminal event now share that recovery scope. Start/end markers describe attachments; a genuinely new session uses a new ID.

Related issue

Closes #1314

Change type

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

User and compatibility impact

Reopening after success or a first-turn failure preserves local recovery facts and permits the next response to commit. Untyped historical journals also retain earlier facts across reopen markers; allocation stays above their highest recorded turn even if an older process restarted its counter. No journal rewrite, format migration, configuration or API change is required.

Display history remains separate from canonical model messages. Existing canonical validation, account/privacy boundaries and independent local/Server clocks still apply.

Architecture and complexity delta

  • Canonical owner extended: session_runtime::restored_journal_state_from_append_order_events.
  • Searched existing canonical replay, session startup/new-session identity, interactive admission/settlement, explicit restore, headless turn allocation and workspace recovery.
  • Removed session-start partitioning, the first-canonical-commit special case and the separate backwards last-event scan. The single fold borrows the last terminal event and clones it once on return.
  • No added state machine, persistent field, storage projection, SQL, request, file read or parallel execution path.
  • Consolidated duplicate segment tests and extended existing failure/admission fixtures through real settlement and another reopen.

Verification

make format-check
CARGO_NET_OFFLINE=true make lint
git diff --check
env -u NO_COLOR cargo nextest run --locked --offline -p astra-cli --lib --profile ci \
  -E 'test(cli::session::) | test(cli::slash::slash_session::resume_tests::) | test(cli::turn::turn_entry::) | test(cli::turn::turn_commit::) | test(cli::turn::turn_success::) | test(tests::resume_tests::)'

All static checks passed, including workspace Clippy with warnings denied. The offline selection passed 331/331 tests. Three updated recovery/admission regressions first failed on the previous implementation and then passed with this change.

  • Public entrypoints: local interactive admission, real primary commit/sidecars, another reopen, and explicit Server canonical restore followed by further commits.
  • Unhappy paths: failed-only first turn, repeated starts, historical counter restarts, append failure/retry, concurrent local advancement, corrupt/unreadable journals, authorization/cancellation and privacy rejection.
  • Database/live-provider verification: not applicable; production changes only local journal recovery. Provider/HTTP fixtures are deterministic and no SQL/schema boundary changes.

Final checklist

  • Tests cover the recovery owner and existing product entrypoints.
  • Updated the lifecycle contract and removed the obsolete legacy reset assumption.
  • Checked the diff for credentials, private URLs, customer data and generated files.
  • Conventional Commit title.

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

Recover all terminal facts in one pass instead of inferring session lifetime from the first successful canonical commit. Reopening a failed-only session must not reuse its allocated turn.
@XuPeng-SH XuPeng-SH changed the title fix(cli): preserve canonical session state across reopen fix(cli): preserve session state across reopen Nov 17, 2026
@XuPeng-SH
XuPeng-SH merged commit f000f7e into matrixorigin:main Nov 17, 2026
41 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/1314-reopened-session-clock branch November 17, 2026 12:57
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]: Reopening a CLI session resets its local turn clock and loses recovery facts

1 participant