fix: recover tmux terminal streams after server restart - #597
Open
TiantianFlow wants to merge 1 commit into
Open
fix: recover tmux terminal streams after server restart#597TiantianFlow wants to merge 1 commit into
TiantianFlow wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Restores tmux terminal output and inbox delivery after server restarts.
Changes:
- Reattaches FIFO readers and tmux pipe targets.
- Seeds terminal status from pane snapshots.
- Reconciles pending inbox messages and adds recovery tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
terminal_service.py |
Implements persisted terminal recovery. |
status_monitor.py |
Adds snapshot-based status seeding. |
api/main.py |
Runs recovery and reconciliation during startup. |
test_terminal_recovery.py |
Tests recovery wiring and backend skipping. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+239
to
+240
| _rearm_pipe() | ||
| status_monitor.seed_from_snapshot(terminal_id, snapshot) |
Comment on lines
+213
to
+215
| snapshot = backend.get_history( | ||
| session_name, window_name, tail_lines=PIPE_LIVENESS_TAIL_LINES | ||
| ) |
| # Recovery publishes initial status before the consumer tasks get their first | ||
| # scheduling turn. Reconcile once here so a callback already pending at | ||
| # restart is not left waiting for the periodic sweep. | ||
| await asyncio.to_thread(inbox_service.reconcile_orphaned_messages, registry) |
| list_terminals.return_value = [ | ||
| {"id": "abc12345", "tmux_window": "tech_lead-a1b2"} | ||
| ] | ||
| status_monitor.seed_from_snapshot.return_value = TerminalStatus.COMPLETED |
Comment on lines
+506
to
+510
| self._buffers[terminal_id] = output[-state_buffer_max:] | ||
| # A persisted terminal is quiescent at recovery time. Do not let a | ||
| # prior process's debounce state suppress its first real status. | ||
| self._bursting[terminal_id] = False | ||
| detected = self._detect_status(terminal_id, output[-state_buffer_max:]) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #597 +/- ##
=======================================
Coverage ? 91.26%
=======================================
Files ? 182
Lines ? 24463
Branches ? 0
=======================================
Hits ? 22326
Misses ? 2137
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
cao-servercan restart while tmux-backed terminals intentionally remain alive. The old process's FIFO reader threads disappear, but tmux continues forwarding pane output to the old FIFO target. The restarted server therefore receives no output for those persisted terminals, leaves their status asunknown, and cannot deliver pending worker callbacks because InboxService only delivers to ready terminals.This was reproduced with a live Claude Tech Lead: two worker reports remained
pendingeven though the Tech Lead was visibly idle.Fix
For tmux-backed terminals at API startup:
pipe-panetarget;Event-inbox (Herdr) backends are explicitly skipped because they do not use tmux/FIFO output capture.
Validation
Automated
2 passed.These are deliberately narrow unit tests; they do not yet exercise end-to-end inbox delivery or failure/multi-pane cases.
Live end-to-end validation
cao-server; the existing Claude Tech Lead and OpenCode Builder tmux panes remained running.unknowntocompleted.Scope / follow-up
This is a tmux restart-recovery fix. CAO's intended topology is one terminal per window/pane. Before marking this ready, follow up with a guard for manually split panes plus end-to-end/failure-path coverage.