Skip to content

fix: show Session rollback results when remote-controlling a CLI host - #3707

Merged
bobleer merged 3 commits into
openBitFun:mainfrom
bobleer:fix/peer-relay-history-rewrite
Nov 3, 2026
Merged

bobleer merged 3 commits into
openBitFun:mainfrom
bobleer:fix/peer-relay-history-rewrite

Conversation

@bobleer

@bobleer bobleer commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #3688. When Desktop remote-controls a CLI host (Peer Device Mode), a rollback succeeds on the host, but the rolled-back turns stay on screen. Rolling back one of them again then fails with Not found: Session rollback target was not found.

Desktop logs confirm the sequence: the first rollback_session_to_turn completed in 109 ms with no error, and the composer showed the restored prompt. The second request targeted a turn the host had already hidden.

Root cause:

  • After a rollback the host emits SessionHistoryChanged. For a paged relay stream, invalidate_paged_history restarts the stream under a new epoch. The new epoch sends no tombstones for dropped turns, and its replay numbers revisions again from the same range below 2^52.
  • The controller's HostStreamSubscriber sees the epoch change, emits relay://session-gap, and replays the latest page.
  • The Web UI never rebuilt its record replica. Replayed records could even be ignored as older revisions, and dropped turns were never removed. reloadAuthoritativeSession does nothing on a device surface, so the rollback service didn't correct the view either.

Fix:

  • HostStreamSubscriber adds resync: true to the gaps it emits itself; a full replay always follows those. Host-appended gaps (report_source_gap, same epoch, no replay) don't carry the flag.
  • RelaySessionHistory reacts to a resync gap. It renders the records already received, then the store reduces the replay into a fresh replica. When the replay's ready event arrives, rendered turns the replay no longer carries are removed. Optimistic turns, which have no storage index yet, are kept.
  • After a completed rollback on a device surface, SessionRollbackService removes the retired turns right away (retireRelaySessionTurns), so the view matches the host before the stream restarts.
  • Found while reviewing: reloading an already-open device-surface Session (which the rollback service does) set historyState back to hydrating, and nothing set it to ready again unless the stream restarted. On a host whose stream answers with tombstones instead of restarting, the composer then refused the next message (canSubmit: false). An open, ready subscription now stays ready.

Type and Areas

Type: bug fix

Areas: web UI (flow_chat, relay history), remote connect (stream subscriber), Peer Device Mode

Motivation / Impact

Rollback in Peer Device Mode now visibly takes effect. Other host-side history rewrites (undo/redo, changes from another controller or the CLI TUI) also show up on the controller instead of leaving stale turns.

Verification

  • node scripts/run-vitest.mjs run src/flow_chat/services src/flow_chat/session-stream src/flow_chat/store/FlowChatStore.test.ts (web-ui): 986 passed. The same suite on main gives 981, plus 5 new tests:
    • a restarted stream rebuilds from its replay, including replayed revisions lower than the old ones
    • a host-appended gap keeps the rendered turns
    • rollback removes retired turns right away
    • RelaySessionHistory resyncs only on a flagged gap for its own Session
    • reloading an open relay Session keeps it ready
  • node scripts/run-vitest.mjs run src/flow_chat src/app/components/NavPanel: 5119 passed
  • tsc --noEmit (web-ui): clean
  • cargo test --locked -p openbitfun-services-integrations --no-default-features --features remote-connect --lib remote_connect::host_stream_subscriber::tests: 9 passed. The restart test now asserts the resync flag.
  • Remote scenarios: Peer Device Mode covered at unit level only. The original failure was diagnosed from real Desktop-to-CLI logs. I did not rerun a live Desktop-to-CLI session after the fix.

Reviewer Notes

  • Compatibility: the flag is produced by the controller's own Rust subscriber and consumed by the same build's Web UI, so mixed peer versions are unaffected. An older desktop without the flag keeps today's behaviour.
  • After a resync with more pages remaining, the view shows only the latest page plus hasMore, the same as a fresh open. Older pages load on demand.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (none needed)

🤖 Generated with Claude Code

bobleer and others added 3 commits November 3, 2026 13:10
When the host restarts a session stream (for example after a rollback
rewrites a paged history), the new epoch replays its latest page under
fresh revisions and sends no tombstones for dropped turns. Mark the
controller-side `relay://session-gap` with `resync: true` so the Web UI
can rebuild its records from that replay. Host-appended gaps stay inside
one epoch and omit the flag.

Co-Authored-By: Claude <noreply@anthropic.com>
In Peer Device Mode the controller renders a record replica that only
grew. After a rollback on the CLI host, the rolled-back turns stayed on
screen, and rolling back one of them again failed with "Session rollback
target was not found".

- Rebuild the replica from the replay after a restarted host stream and
  drop rendered turns the replay no longer carries once it is ready.
- Drop the turns a completed rollback retired right away, so the view
  matches the host before its stream restarts.

Co-Authored-By: Claude <noreply@anthropic.com>
Reloading a device-surface Session whose relay subscription is already
open marked it hydrating, but the open subscription announces no second
first page. After a rollback on a host whose stream answers with
tombstones instead of restarting, the Session stayed hydrating and its
composer refused the next message. Keep an open, ready subscription
ready.

Co-Authored-By: Claude <noreply@anthropic.com>
@bobleer
bobleer merged commit 4b387ce into openBitFun:main Nov 3, 2026
13 checks passed
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