Skip to content

fix(status): a chunk that changes no screen cell does not reset the quiet gate (#1367) - #1486

Draft
plauzy wants to merge 1 commit into
awslabs:mainfrom
plauzy:fix/1367-quiet-gate-no-cell-chunks
Draft

plauzy wants to merge 1 commit into
awslabs:mainfrom
plauzy:fix/1367-quiet-gate-no-cell-chunks

Conversation

@plauzy

@plauzy plauzy commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Status: draft. Waits on #1437 (still open, and conflicting with main; whoever merges second rebases and keeps both: this PR's -> bool signature and #1437's static method), and on CI and review.

Closes #1367

Refs #1375.

Refs #1484.

What this fixes

While agy sits at its ready prompt it repeats one 39-byte block of terminal-mode sequences (ESC[?2004h ESC[?1004h ESC[?1003h ESC[?1006h ESC[>4;2m). The block changes no screen cell, but each arrival reset the status monitor's 3 s quiet gate (STALE_PROCESSING_BUFFER_QUIET_S) and dropped the pending capture candidate. So a composite that still read PROCESSING never reached the capture-pane fallback from #558 and was never corrected. #1322 fixed the cause of #1321's wrong composite. This fixes the gate, so the next compositor defect cannot stall a seat the same way.

The recording (step 1 of the issue's plan)

An idle antigravity_cli seat, read-only for 125 s with timestamps: 60 arrivals, all the same 39 bytes, 1.99 to 2.21 s apart (mean 2.10 s). Every gap is inside the 3 s gate. The block and its arrival times are in test/providers/fixtures/agy_idle_mode_block_timed.json. The bytes hold no text or identity, so nothing needed scrubbing, and the PII guard passes.

The change (step 3)

With the pyte screen in use, _feed_screen_locked now returns whether the chunk changed the text of any row. For each row pyte marked dirty, it compares the row's written non-blank cells with the last ones it saw. A mode block marks no row, so it costs nothing extra. Feeding the recorded agy turn (91,357 chars) is within noise of main (31.1 ms vs 30.4 ms, 512-char chunks). The worst case is ms-scale: about 2 to 3 ms per chunk on a quiet machine, up to roughly 11 ms on a loaded one, and only for a fully painted 200x400 screen scrolled on every chunk (main: 0.01 to 0.15 ms). A chunk that changes no text:

  • is still appended to the rolling buffer, and still advances the output generation;
  • does not reset the quiet gate, advance the capture generation or drop a pending candidate.

A terminal's first chunk still starts the gate's clock. A failed comparison counts as a change. Raw detection (no screen) is unchanged.

Trade-off, as the issue states it: a chunk that changes only modes, the cursor or the colour of unchanged text no longer counts as activity. Status detection reads text only, so this matches what the gate is for. A TUI that animates only by colour on unchanged text, or only through its terminal title, therefore leaves the gate open while it is PROCESSING. That costs one capture-pane subprocess about every 3 s (STALE_PROCESSING_CAPTURE_INTERVAL_S), and the two-read confirm still protects the verdict. "No provider known to do this" was checked for agy only.

The test (step 2)

test/services/test_status_monitor_idle_mode_output.py runs on a fake clock with the real StatusMonitor, the real pyte compositor and the real agy provider. It replays the recorded working turn (agy_turn_end_stale_esc_to_cancel.txt, cut at "ready for input", which reads PROCESSING), then the measured idle arrivals, polling get_status() every second. Only capture-pane is faked, and it returns the ready screen of the same turn. get_status() must reach COMPLETED within 10 s.

What is measured and what is inferred:

  • The idle block and its cadence were measured on an idle pane.
  • The test replays that block after an older recorded turn (agy_turn_end_stale_esc_to_cancel.txt). That agy emits the same block at the same cadence right after a turn ends is inferred, not recorded.
  • The 10 s bound comes from the fake clock (3 s gate, then two reads 3 s apart, polled every second). No heal was recorded on a live pane.

There are three controls:

  • real output at the same cadence keeps the gate shut, with no capture;
  • raw-detection providers count every chunk;
  • a table of chunk kinds pins what counts as a change: mode block, cursor move, colour with and without text, same and new character, erase, clear and redraw in one chunk (no change) and in two (the clear counts), scroll with identical rows (no change) and with moved text, and the same rule for claude_code.

Before / after (on main at 6234f1f5, 2026-11-24)

pytest test/services/test_status_monitor_idle_mode_output.py -q --no-cov

result
main 6234f1f5 (new test and fixture copied on) 10 failed, 9 passed
this branch 19 passed

On main the heal test fails with: get_status() stayed PROCESSING for the whole recording: the mode block reset the quiet gate on each of its 60 arrivals (0 capture-pane reads). The 9 tests that pass on main are the controls and the rows where a change is expected.

Gates

pytest test/services test/providers -m "not e2e" -n auto --no-cov, temp HOME, from git archive extractions of main (6234f1f) and this branch, alternating, one run at a time, 10 runs each:

main this branch
Runs with at least one failure 5 of 10 3 of 10
Failures in total 6 5
Passed in a clean run 14438 14457 (+19 new tests)

There is no evidence of a B2 effect at 10 against 10 (5 of 10 against 3 of 10 runs with a failure, Fisher p about 0.65), and the failing tests do not exercise status_monitor. No id repeated, but the *.mcp.json fake-home family (parameter sets of test_terminal_identity_forwarding) failed on both sides. The failures are in tests that this change does not touch: *.mcp.json under the fake home that xdist workers share (#1459 gives each worker its own), the FIFO reader's file descriptor in test_fifo_reader, the 0.1 s loop-stall bound in test_startup_handler_nonblocking under load, and the #1458 teardown race (#1463). main flaked test_fifo_reader::test_data_received_across_writer_reconnects in an earlier pass as well. At 10 runs against 10, 3 against 5 is within noise.

An earlier pass of three runs per tree showed 4 failures on this branch and none on main. The 10-run comparison does not reproduce that, so I no longer think this change is linked to them.

black, isort and ruff pass on the changed files, and mypy_ratchet.py passes on 0574733 (61 fewer errors than the baseline).

Lost dispatch: pre-existing, not changed here

When a submission is dropped after notify_input_sent and the pane keeps showing the previous ready screen, started_on_last_input reads True at about 1.0 s on main, and the status reads completed. This holds with and without mode-only chunks. The path is the quiescence screen detection, which reads the stale ready screen and stamps it above the dispatch boundary. It is not the capture-pane fallback this PR changes.

I checked it on both trees with the same deterministic test (real StatusMonitor, pyte and agy provider on a fake clock; finished turn, notify_input_sent(assume_processing=True), buffer cleared as dispatch_input does, pane unchanged, the recorded mode block every ~2.1 s, polled every second for 60 s). It fails the same way on main (6234f1f) and on this branch: first started at 1.0 s, final status completed. With no chunks at all (a quiet pane) neither tree reads started. This PR does not change that behaviour, and the test is not part of it because it fails on main.

Overlap with #1437

#1437 (another author; head cbff1830, open, GitHub reports it CONFLICTING) also edits services/status_monitor.py. Checked on 2026-11-23:

Not covered: whether other providers send screen-neutral idle output. This change does not depend on it.


Co-authored-by: Kiro Agent 244629292+kiro-agent@users.noreply.github.com

…uiet gate (awslabs#1367)

While agy sits at its ready prompt it repeats one 39-byte block of
terminal-mode sequences (ESC[?2004h ESC[?1004h ESC[?1003h ESC[?1006h
ESC[>4;2m). Measured on a live idle pane: 60 arrivals in 125 s, 1.99 to
2.21 s apart, so always inside the 3 s STALE_PROCESSING_BUFFER_QUIET_S gate.
Each arrival reset the gate and dropped the pending capture candidate, so a
composite that still read PROCESSING never reached the capture-pane fallback
(awslabs#558) and was never corrected.

With the pyte screen in use, _feed_screen_locked now reports whether the chunk
changed the text of any row. For each row pyte marked dirty it compares the
row's written non-blank cells with the last ones it saw, so the cost follows
what the row holds rather than the 400-column width. A chunk that changes no text is still
appended to the rolling buffer and still advances the output generation, but
it no longer resets the quiet gate, advances the capture generation or drops a
candidate. A terminal's first chunk still starts the gate's clock, a failed
comparison counts as a change, and raw detection (no screen) is unchanged.
Colour-only changes on unchanged text count as no change, because status
detection reads text only.

- test/providers/fixtures/agy_idle_mode_block_timed.json: the recorded block
  and its arrival times (no text, no identity).
- test/services/test_status_monitor_idle_mode_output.py: on a fake clock, the
  real monitor, compositor and agy provider replay the recorded working turn
  and then the measured idle arrivals. get_status() must heal to COMPLETED
  within 10 s through capture-pane. Controls: real output at the same cadence
  keeps the gate shut with no capture, raw-detection providers count every
  chunk, and a table of chunk kinds pins what counts as a change (mode block,
  cursor move, colour with and without text, same and new character, erase,
  clear and redraw in one chunk and in two, scroll with identical and with
  moved rows, and the same rule for another screen provider).

Co-authored-by: Kiro Agent <244629292+kiro-agent@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@6234f1f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../cli_agent_orchestrator/services/status_monitor.py 87.50% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1486   +/-   ##
=======================================
  Coverage        ?   94.40%           
=======================================
  Files           ?      309           
  Lines           ?    60703           
  Branches        ?     9880           
=======================================
  Hits            ?    57308           
  Misses          ?     3395           
  Partials        ?        0           
Flag Coverage Δ
unittests 94.40% <87.50%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

Status monitor: idle output that changes no cell resets the quiet gate, so the capture-pane fallback never runs

2 participants