Skip to content

fix(session): preserve recursive state on resume - #257

Merged
w0wl0lxd merged 4 commits into
mainfrom
fix/session-resume-restore
Aug 3, 2026
Merged

fix(session): preserve recursive state on resume#257
w0wl0lxd merged 4 commits into
mainfrom
fix/session-resume-restore

Conversation

@w0wl0lxd

@w0wl0lxd w0wl0lxd commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • persist recursive compaction transcripts in headless session writers
  • restore recursive transcript state in ACP and SDK sessions
  • retain nested tool restore callbacks and atomically validate initial child-session prompts

Validation

  • cargo fmt --all -- --check
  • cargo test -p n00n-agent --lib headless
  • cargo test -p n00n-ui --lib
  • cargo test -p n00n-acp --lib
  • cargo check --all

Dependency

Independent fix, but may require a small rebase after #254 because both harden session runtime paths.

@w0wl0lxd

w0wl0lxd commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@w0wl0lxd, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 00fdfe3a-43e0-4a78-9eee-1b9d32bf2f5d

📥 Commits

Reviewing files that changed from the base of the PR and between f5be3f3 and 749ef98.

📒 Files selected for processing (12)
  • changelog.d/session-resume-restore.fixed.md
  • n00n-acp/src/server.rs
  • n00n-agent/src/headless.rs
  • n00n-ui/src/app/queue.rs
  • n00n-ui/src/app/tests.rs
  • n00n-ui/src/chat.rs
  • n00n-ui/src/components/messages/mod.rs
  • n00n-ui/src/components/messages/tests.rs
  • n00n-ui/src/components/tool_display.rs
  • n00n-ui/src/event_loop.rs
  • src/cmd/agent.rs
  • src/sdk_mode.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@w0wl0lxd I will review pull request #257.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 495f044b4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread n00n-ui/src/chat.rs
@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes session-resume correctness by threading the recursive compaction transcript through every session-resume path (headless, ACP, SDK) and teaching the TUI's messages panel to find, snapshot, and rebake tool messages that are nested inside compaction entries rather than only looking at top-level messages.

  • Transcript persistence: SessionStore::record_turn now saves history.transcript() alongside history.as_slice(), and all resume paths (resolve_session, ACP spawn_session, spawn_interactive) accept and forward the restored transcript via a new initial_transcript field on InteractiveParams.
  • Nested tool snapshot handling: store_snapshot now searches for a tool's containing message recursively using message_contains_tool, and when the tool lives inside a compaction it invalidates and full-rebuilds the line cache rather than using the per-tool fast path; rebake_stale_snapshots and related helpers now use collect_tool_messages / find_tool_msg / find_tool_msg_mut to traverse nested compactions.
  • Initial-prompt hardening: prepare_new_session_prompt replaces the old fire-and-forget submit_text call, validating the new app is Idle before submitting and cancelling the runtime (rather than silently registering it) if the app is unexpectedly busy.

Confidence Score: 5/5

Safe to merge. All resume paths now consistently forward the compaction transcript, nested tool snapshots are correctly routed through a full cache rebuild, and the new-session prompt is validated before dispatch.

The persistence changes are additive with clear round-trip tests. The UI snapshot path for nested tools is well-guarded: the backlog early-return correctly defers rebake to drain_restore_backlog, and stale-theme snapshots for live nested tools trigger rebake immediately. The event-loop hardening tightens an existing code path without introducing new state.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
n00n-ui/src/components/messages/mod.rs Core UI change: store_snapshot, rebake_stale_snapshots, and anchor-preservation helpers are all extended to recurse through nested compaction entries; new free functions are clean and well-tested.
n00n-agent/src/headless.rs record_turn now saves transcript via history.transcript().to_vec(); spawn_interactive uses History::restored_with_transcript; two new round-trip tests added.
src/sdk_mode.rs resolve_session now returns a third Vec<TranscriptEntry>; all three resume branches correctly populate or default the transcript.
n00n-acp/src/server.rs spawn_session gains an initial_transcript parameter; session/resume path extracts stored.transcript and forwards it; session/new passes Vec::new().
n00n-ui/src/event_loop.rs SessionRequest::New now calls prepare_new_session_prompt before pushing the runtime, cancelling on error instead of silently swallowing the outcome.
n00n-ui/src/chat.rs transcript_to_display_at now collects child_restore_items from recursive Compaction arms; new test verifies each nested tool ID appears exactly once.
n00n-ui/src/app/queue.rs Adds prepare_new_session_prompt helper that validates Idle status before submitting, mapping Queued to the same error as Busy.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant EventLoop
    participant App
    participant HeadlessSpawn
    participant SessionStore
    participant MessagesPanel

    Note over Caller,MessagesPanel: Session Resume Flow

    Caller->>EventLoop: "session/resume or sdk --session=ID"
    EventLoop->>SessionStore: StoredSession::load(id)
    SessionStore-->>EventLoop: (messages, transcript)
    EventLoop->>HeadlessSpawn: spawn_interactive(initial_history, initial_transcript)
    HeadlessSpawn->>HeadlessSpawn: History::restored_with_transcript()

    Note over EventLoop,App: TUI new-session path
    EventLoop->>App: prepare_new_session_prompt(prompt)
    alt app is Idle
        App-->>EventLoop: Ok(actions)
        EventLoop->>MessagesPanel: dispatch(actions)
    else Busy or blank prompt
        App-->>EventLoop: Err(error)
        EventLoop->>HeadlessSpawn: handles.cancel()
        EventLoop-->>Caller: Err(error)
    end

    Note over HeadlessSpawn,SessionStore: After each turn
    HeadlessSpawn->>SessionStore: "record_turn(&history)"
    SessionStore->>SessionStore: save messages + transcript

    Note over MessagesPanel: Nested tool snapshot restore
    MessagesPanel->>MessagesPanel: store_snapshot(tool_id)
    MessagesPanel->>MessagesPanel: message_contains_tool() recursive
    alt nested in compaction
        MessagesPanel->>MessagesPanel: full cache rebuild
        MessagesPanel->>MessagesPanel: preserve_anchor_at()
    else top-level
        MessagesPanel->>MessagesPanel: rebuild_tool_segment()
    end
Loading

Reviews (4): Last reviewed commit: "fix(ui): retain backlogged restore snaps..." | Re-trigger Greptile

Comment thread n00n-ui/src/event_loop.rs

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Criterion

Details
Benchmark suite Current: 749ef98 Previous: f5be3f3 Ratio
fib/jit_mlua_hook 6684338 ns/iter (± 58726) 6706525 ns/iter (± 219479) 1.00
fib/jit_watchdog 2301550 ns/iter (± 5389) 2219583 ns/iter (± 14307) 1.04
fib/jit_none 2455227 ns/iter (± 52341) 2239509 ns/iter (± 27791) 1.10
fib/interp_mlua_hook 8895550 ns/iter (± 146069) 8135074 ns/iter (± 37211) 1.09
fib/interp_watchdog 4337891 ns/iter (± 29950) 4448055 ns/iter (± 100679) 0.98
fib/interp_none 4337747 ns/iter (± 12214) 4319187 ns/iter (± 114185) 1.00
buffer_rw/jit_mlua_hook 584776 ns/iter (± 13819) 590949 ns/iter (± 1780) 0.99
buffer_rw/jit_watchdog 192066 ns/iter (± 385) 192128 ns/iter (± 1436) 1.00
buffer_rw/jit_none 191900 ns/iter (± 312) 192181 ns/iter (± 2373) 1.00
buffer_rw/interp_mlua_hook 1045822 ns/iter (± 11610) 1048648 ns/iter (± 15563) 1.00
buffer_rw/interp_watchdog 582661 ns/iter (± 4165) 584712 ns/iter (± 44593) 1.00
buffer_rw/interp_none 582710 ns/iter (± 4531) 583360 ns/iter (± 2330) 1.00
splash_render_120x40 80037 ns/iter (± 1600) 58719 ns/iter (± 6499) 1.36
splash_render_200x60 112800 ns/iter (± 5746) 175680 ns/iter (± 14314) 0.64

This comment was automatically generated by workflow using github-action-benchmark.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

@w0wl0lxd

w0wl0lxd commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@w0wl0lxd I will review pull request #257.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bab2744231

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread n00n-ui/src/components/messages/mod.rs
@w0wl0lxd

w0wl0lxd commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba6a47e445

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread n00n-ui/src/chat.rs
@w0wl0lxd
w0wl0lxd enabled auto-merge (squash) August 3, 2026 13:45
@w0wl0lxd

w0wl0lxd commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 749ef9875e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@w0wl0lxd
w0wl0lxd merged commit fbdb608 into main Aug 3, 2026
31 checks passed
@linear-code

linear-code Bot commented Aug 3, 2026

Copy link
Copy Markdown

N00N-149

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.

1 participant