Skip to content

Restore terminal modes and the frame after a host replays a trimmed log - #299

Closed
smarzban wants to merge 4 commits into
mainfrom
fix/replay-restore
Closed

smarzban wants to merge 4 commits into
mainfrom
fix/replay-restore

Conversation

@smarzban

@smarzban smarzban commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Why

#297 did not fix the board in T3 Code. T3 Code rebuilds a hidden terminal pane by replaying a capped log of raw output (5,000 lines or 8 MB). Once the log is trimmed, tsk's startup escape codes are gone: alternate screen, mouse, focus and paste reporting. The board replays as scattered cells and ignores clicks. Focus-in never fires, and ctrl+l redrew the board without turning the mouse back on.

What changed

  • ctrl+l and focus-in send every terminal mode again (alternate screen, mouse, focus, paste, keyboard flags), then repaint in full (repaint_on_request).
  • Every two minutes the board sends mouse, focus and paste reporting again, then paints a keyframe that rewrites every non-blank cell without clearing (paint_with_keyframe). A live terminal sees no change. A trimmed replay now always ends with a complete frame and its modes. The keyframe never touches the alternate screen or the keyboard flags: re-entering the screen can clear it, and keyboard flags stack.
  • Docs: the keys.md row and note, the Help label, and the existing Unreleased CHANGELOG line, edited rather than duplicated.

Scope

  • Covers: restoring the board after a host replays a trimmed log, automatically within two minutes or at once on ctrl+l.
  • Leaves out: T3 Code's replay itself, which is the root cause. A bug report to T3 Code is the owner's call.

Done when

# Result Proved by Proof Step
1 ctrl+l and focus-in send every mode again, then repaint every cell agent repaint_request_resends_every_mode_and_repaints_in_full; smoke 1 5
2 Every 2 min, mouse, focus and paste are sent again and every cell is rewritten, with no clear, no alternate screen and no keyboard flags agent keyframe_restores_modes_and_a_dropped_screen_without_clearing, keyframe_is_due_every_interval_and_reschedules; smoke 1 5
3 A keyframe never leaves stale text agent keyframe_on_a_paint_that_blanks_cells_leaves_no_stale_text 4
4 Docs, Help and CHANGELOG match agent diff 4
5 In T3 Code, a reopened board comes back whole and clickable within 2 min, or at once on ctrl+l owner Your steps in the report

Verification

Commit: 82f15a2. The smoke ran on 9ac9c97, and the two later commits change only tests for Windows. There, crossterm refuses keyboard flags, and supports_keyboard_enhancement is always false, so the board never asks for them. Crossterm also turns mouse capture on through the console API rather than by writing a code, so the tests don't look for one.

  1. Replay smoke, isolated TSK_STATE_DIR, TSK_CONFIG_DIR and HOME under /tmp. The board runs in a 100×30 pty. The script cuts the output log after the first paint, the way T3 Code trims it, moves the cursor, and replays only the tail into a fresh pyte screen. The "wait" run uses a build with the keyframe interval patched to 3 s (not committed):
    main 93d085e8, wait:     modes in tail: mouse=False focus=False altscreen=False | replayed: PARTIAL (15 words vs 116)
    main 93d085e8, ctrl+l:   modes in tail: mouse=False focus=False altscreen=False | replayed: FULL
    branch (3 s), wait:      modes in tail: mouse=True  focus=True  altscreen=False | replayed: FULL (matches live)
    branch, ctrl+l:          modes in tail: mouse=True  focus=True  altscreen=True  | replayed: FULL (matches live)
    
    On main, ctrl+l redraws the board but leaves the mouse off, which is the reported symptom.
  2. cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test: 2433 passed, 0 failed on 82f15a2. cargo clippy --all-targets --target x86_64-pc-windows-gnu -- -D warnings and cd site && npm test (63 passed) are clean too.
  3. Each new test was watched failing with its fix reverted by hand: the old keyframe order, a full re-send on the keyframe, and the re-send removed from repaint_on_request.

Could break

Every two minutes the board writes one extra frame, about 3 to 4 KB. Turning a mode on when it is already on does nothing in any terminal. On Windows, crossterm treats focus reporting as a no-op.

For the owner to decide

Whether to report the trimmed replay to T3 Code. The real fix there is to restore terminal modes, or save the screen itself, when it replays.

Review

Pi review panel on e942a9b: 8 of 8 seats voted (sol and opus; holistic, tests, specification-conformance, subtle-correctness). It found 7 mediums. Kept F-1/F-7 (a keyframe on a paint that blanks cells left stale text), F-4/F-5 (no test that the keyframe sends only the light set) and F-2/F-6 (no test reached the ctrl+l/focus wiring). All were fixed in 9ac9c97, and the sol seat's verify passed with no regressions.
Set aside: F-3, advisory. It asked for a test that both paint paths schedule the keyframe, and both now go through one shared helper.

T3 Code rebuilds a hidden terminal pane by replaying a capped log of raw
output. Once the log is trimmed, the startup escape codes (alternate
screen, mouse, focus, paste) are gone, so the board comes back as
scattered cells and ignores clicks; focus-in never fires.

ctrl+l and focus in now re-send every mode before the full repaint.
Every two minutes the board also re-sends mouse, focus and paste
reporting and rewrites every painted cell without clearing, so the
log's tail always holds a complete keyframe.
…review F-1, F-4, F-2)

The keyframe paint diffs against a blank frame and skips blank cells, so
landing it on a paint that blanked cells left stale text. Paint
normally first, then the keyframe pass. Pull the ctrl+l / focus-in
handling into repaint_on_request so a test reaches it.
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
herdr-tsk Ignored Ignored Preview Nov 14, 2026 8:12am UTC

PushKeyboardEnhancementFlags always takes the WinAPI path on Windows and
returns Unsupported; the board never enables it there
(supports_keyboard_enhancement is false), so only the tests asked.
EnableMouseCapture on Windows sets the console input mode instead of
writing ?1000h, so the written bytes hold paste, focus and the
alternate screen only.
@smarzban

Copy link
Copy Markdown
Owner Author

Replaced by #300: ctrl+l alone restores the modes and redraws; the 2-minute refresh and the focus redraw are dropped.

@smarzban smarzban closed this Nov 14, 2026
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