Skip to content

Send terminal catalogue changes as deltas - #109

Merged
pcarrier merged 1 commit into
yas-run:mainfrom
indent-com:upstream/terminal-state-deltas
Oct 9, 2026
Merged

pcarrier merged 1 commit into
yas-run:mainfrom
indent-com:upstream/terminal-state-deltas

Conversation

@pcarrier

@pcarrier pcarrier commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

run_terminal_watch responded to every catalogue revision bump with Phase::Reset, followed by a full send_terminal_snapshot: BEGIN, then one SNAPSHOT_RECORDS event per terminal, then END. A single create, title/cwd change, exit or close therefore resent the whole catalogue to every terminal watcher. Each record was its own event, and clients ACK each event.

The cost grows with the catalogue size. On a production box running hundreds of agent subagents, the catalogue held 1,033 terminals (9 running and 1,024 exited, retained under DEFAULT_MAX_EXITED), at about 817 B per record. That made every terminal event about 0.8 MB and about 1,036 frames per watching connection. A 5s sample on the client counted 14 RESET, 14 BEGIN, 14,003 RECORDS, 14 END and 0 DELTA, and the client's event loop saturated.

The terminal watch now does what run_client_watch already does. terminal_delta_event diffs the previous and current TerminalCatalogue by handle and builds one Phase::Delta event:

  • Add for new handles
  • Replace for changed records
  • Remove (RemovedTerminal) for handles that are gone

Unchanged records are not sent. If the delta doesn't fit the event limit, it falls back to RESET plus snapshot through state_delta_reset, as the client watch does. Because the watch channel coalesces revisions, a delta can span several revisions (from_revision → to_revision).

Consumers already handle terminal deltas: @yas-run/core's YasTerminalCatalog.apply (YAS_STATE_DELTA with ADD/REPLACE/PATCH/REMOVE) and the CLI's watch_terminal_exit.

Tests:

  • New terminal_catalogue_revision_is_one_delta_with_only_changed_records.
  • terminal_cross_session_close_discards_frames_before_removal_state now accepts the removal as a DELTA Remove for the closed handle, as well as the old reset path. It still asserts that no ADD/REPLACE of the closed terminal arrives and that no frame follows.
  • cargo check -p yas-server --tests and cargo clippy -p yas-server --lib --tests -- -D warnings pass, and rustfmt --check is clean.
  • I couldn't run the test binary locally: the sandbox SIGTERMs rustc linking the yas-server lib test. CI needs to confirm both tests.

A follow-up could send TerminalPatch when only extensions change, instead of a full Replace.

View in Indent View in Slack
Tag @indent to continue the conversation here.

run_terminal_watch answered every catalogue revision with RESET plus a full
snapshot, one record per event, to every watcher. Diff the previous and current
catalogues by handle and send one DELTA of ADD/REPLACE/REMOVE records instead,
falling back to RESET plus snapshot only when the delta exceeds the event
limit, as run_client_watch already does.

@ultimator-agent ultimator-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ultimator's review of 11605b6

The terminal watch now diffs the previous and current TerminalCatalogue by handle and sends one Phase::Delta event. It falls back to RESET plus snapshot when the delta exceeds the event limit, as run_client_watch does. I found nothing wrong in the diff. I had no checkout and did not run the tests, so the new test and the changed cross-session close test still need CI to confirm.

No issues found.

Reviewed in 12s · Session · @ultimator-agent review reviews again · @ultimator-agent fix fixes the open issues

@pcarrier
pcarrier merged commit 9ab8c68 into yas-run:main Oct 9, 2026
10 of 11 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