Skip to content

fix(agent): fix flaky Agent tests and a stale store check that paused the chat - #1496

Merged
AnthonyRonning merged 2 commits into
masterfrom
fix/agent-ui-test-backend-races
Nov 7, 2026
Merged

AnthonyRonning merged 2 commits into
masterfrom
fix/agent-ui-test-backend-races

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the intermittent Agent test failures behind last night's red nightly, plus every other intermittent failure a soak under CPU load turned up. One of them was a real bug in the app.

Root cause

Sidebar::new asks the backend for the saved sidebar order on a real tokio thread. Test screens use the dead 127.0.0.1:9 backend, so the refusal (Local account is not ready) arrives at a moment set by the OS rather than the test. Usually it lands during the fixture's last run_until_parked, so tests start with its notice already on screen. On a loaded runner it lands later:

  • Mid-test, its notice banner moves the layout after a test has measured it.
    • navigation_loading_keeps_the_header_and_composer_in_place (macOS, Nov 7): the empty state centres its column, so a banner below the composer moved it up 33px (y 453 → 420).
    • transcript_context_menu_copies_link_destinations (macOS, Nov 4 and the Nov 7 nightly): the transcript row moved, so the click point the test stored missed its link and the menu had no Copy Link.
    • test_application_vim_moves_over_the_semantic_transcript_projection (found in the soak, 2 of 15 loaded runs): the notice appeared after the test had cleared it.
  • After the bridge task's first poll, it wakes that task from a tokio thread, which gpui's test scheduler rejects as nondeterministic.
    • test_application_vim_escape_assistant_focus_and_plain_command_count builds its own window without allow_parking. It failed this way in this branch's pre-commit hook.

reset_persisted_for_test marked the order loaded but left the request in flight.

Change

The order request gets its own task (order_request) instead of joining the shared bridged_tasks. The test-only Sidebar::cancel_order_request_for_test drops it before its first poll, while it has no waker for the tokio thread to call. ChatScreen::new_without_start, the new ChatScreen::new_inner_for_test (used by all nine tests that build an unmounted screen) and reset_persisted_for_test all call it. Production code still makes the same request and handles its result the same way.

fixture_leaves_no_saved_order_request_to_raise_a_late_notice is new. It fails every time without the fix (unexpected notice: Some(Raw("Local account is not ready"))).

Stale store checks (app bug)

This PR's first CI run failed in reconnect_and_password_maintenance_preserve_saved_language ("Timed out waiting for maintenance settings refresh"). It reproduced locally in 1 of 5 full-suite runs under CPU load, and never alone.

The Maintenance event starts a store_status check. If its Maintenance reply was handled after the host's later Open event, it paused the chat again and left the settings refresh pending, and no further event resumed it. The chat stayed on "Updating local data…". In real use the window is small, because a password change usually outlasts that round trip, but the app trusted a stale reply over a newer event.

MapleApp now counts the StoreStateChanged events it handles. A check whose reply predates a newer one is dropped, because that event was already handled. a_late_maintenance_status_cannot_pause_the_reopened_chat holds the reply in the fixture host until after Open. It fails 10 of 10 without the fix and passes 20 of 20 with it.

Other test races found in the soak

  • committed_restart_retry_quit_and_close_do_not_contact_the_retired_host cleared its request log while a startup store_status was still in flight, then counted it against quit. It now waits until every call sent before retirement has been answered (AgentBackend::host_calls_in_flight_for_test). Every call checks retirement before it is sent, so the app was never contacting the retired host.
  • test_sidebar_menu_selects_grouping_and_task_order saved a Manual order to the dead backend, and the refusal could close a later menu. It now waits for that refusal right after the press. With an injected 2 or 6 ms backend delay it failed 9 of 12 runs before the change and 0 of 48 after.
  • Host lock tests asserted that a just-released flock was free. A process that another test forks at that moment (host spawning uses pre_exec, so it forks) shares every descriptor until it execs. ipc::lock_after_release waits that out for up to 5 seconds and fails on a real holder. Seen once, in a suite-wide injected-delay audit.

Testing

With a temporary tokio::time::sleep injected before backend futures (not committed):

test before after
transcript_context_menu_copies_link_destinations fails at 2–4 ms delay, at CI's assertion 0 failures at 0–50 ms
navigation_loading_keeps_the_header_and_composer_in_place fails at 2 ms, at CI's assertion 0 failures at 0–50 ms
test_application_vim_escape_assistant_focus_and_plain_command_count fails at 1–3 ms, "not deterministic" 0 failures at 0–20 ms
test_application_vim_moves_over_the_semantic_transcript_projection fails 3 of 3 with the refusal forced late 3 of 3 pass
test_sidebar_menu_selects_grouping_and_task_order fails 9 of 12 at 2 and 6 ms 0 of 48 at 0–15 ms
  • Full app suite under 18 CPU-hog processes, after the maintenance fixes: 15 runs, with no failure in the maintenance tests (before: about 1 in 5). The vim transcript test failed 2 of those 15, which led to the new_inner_for_test change.
  • Suite-wide injected-delay audit at 1, 2, 3 and 5 ms, 2 runs each: one failure, the lock test above, now fixed.
  • The pre-commit hook's lint and full Agent tests passed (app: 1325 passed). The branch was then rebased over fix(agent): report which Windows installer check failed and install in one transaction #1492 and Bump Work to 0.0.19 #1497, which touch none of these files.

Not covered

  • agent-full-macos doesn't run on PRs without ci:full. Master's push run and the next nightly will confirm it there.
  • No soak has been run on Linux yet. CI's agent-test is the first Linux run.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

AnthonyRonning and others added 2 commits November 7, 2026 13:36
Sidebar::new asks the backend for the saved order on a real tokio thread.
Test screens use the dead 127.0.0.1:9 backend, so the refusal arrived at
a moment set by the OS rather than the test:

- landing mid-test, its notice banner moved the layout after a test had
  measured it: the centered composer rose 33px
  (navigation_loading_keeps_the_header_and_composer_in_place), or the
  transcript row moved so a stored click point missed its link
  (transcript_context_menu_copies_link_destinations, Nov 4 and the Nov 7
  nightly);
- landing after the task's first poll, it woke the task from a tokio
  thread, which gpui's test scheduler rejects as nondeterministic
  (test_application_vim_escape_assistant_focus_and_plain_command_count).

The order request now has its own task. The test-only constructor and the
fixture reset drop it before its first poll. Production behaviour is
unchanged. A new test fails every time without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1496's first CI run failed in a desktop maintenance test. A full-suite
soak under CPU load then found three more tests that fail intermittently.
Each is fixed at its cause.

Store checks (a real bug, not only a test race): the Maintenance event
starts a store_status check. If its Maintenance reply was handled after
the host's later Open event, it paused the chat again and left the
settings refresh pending, and no further event resumed it. The chat then
stayed on "Updating local data". A check whose reply predates a newer
StoreStateChanged is now dropped, since that event was already handled.
`a_late_maintenance_status_cannot_pause_the_reopened_chat` holds the
reply until after Open, and it fails every time without the fix. This was
the CI failure in
`reconnect_and_password_maintenance_preserve_saved_language`.

Tests:
- `committed_restart_retry_quit_and_close_do_not_contact_the_retired_host`
  cleared its request log while a startup store_status was still in
  flight, then counted it against quit. It now waits until every call sent
  before retirement has been answered. Every call checks retirement
  before it is sent, so later calls cannot reach the host.
- Unmounted-screen tests built with `ChatScreen::new_inner`, so #1496's
  cancellation of the sidebar's startup order request did not reach them.
  Its late refusal failed
  `test_application_vim_moves_over_the_semantic_transcript_projection`.
  `new_inner_for_test` cancels it, and all nine call sites use it.
- `test_sidebar_menu_selects_grouping_and_task_order` saved a Manual
  order to the dead backend, and the refusal could close a later menu. It
  now waits for that refusal right after the press.
- Lock tests asserted that a just-released flock was free. A process that
  another test forks at that moment holds the lock until it execs.
  `lock_after_release` waits that out for up to 5 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AnthonyRonning
AnthonyRonning force-pushed the fix/agent-ui-test-backend-races branch from aea62d0 to 1299afc Compare November 7, 2026 21:36
@AnthonyRonning AnthonyRonning changed the title fix(agent): cancel the sidebar's order request in UI tests fix(agent): fix flaky Agent tests and a stale store check that paused the chat Nov 7, 2026
@AnthonyRonning
AnthonyRonning merged commit 3a09c6f into master Nov 7, 2026
23 checks passed
@AnthonyRonning
AnthonyRonning deleted the fix/agent-ui-test-backend-races branch November 7, 2026 22:38
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