Skip to content

Let a running parent take a sub-agent's result without a reload - #302

Merged
stippi merged 1 commit into
mainfrom
fix/flaky-queued-result-test
Nov 3, 2026
Merged

stippi merged 1 commit into
mainfrom
fix/flaky-queued-result-test

Conversation

@stippi

@stippi stippi commented Nov 3, 2026

Copy link
Copy Markdown
Owner

The release run 41593054062 failed on a_queued_result_stays_listed_until_the_parent_takes_it, which also failed in two earlier Build runs. Looking into it turned up a bug in the code under test as well.

The bug

Delivering a background sub-agent's result waits until its spawn_agent call is stored, and checked instance.session. A running agent writes to persistence only, so the instance learned of the call only when something reloaded it, such as a view loading the session. Until then delivery retried every 200 ms, and the result arrived only after the run ended, as a new turn, while the UI already showed "Result queued". Results were late, not lost.

SessionManager::is_tool_call_stored now reads persistence when the instance doesn't know the call. A failed read counts as not stored, so the next attempt reads again.

The test

  • Race: it released the parent once the agent showed as queued, which happens just before the result is queued. The parent could end its run, the result then started a turn, and that turn's GatedProvider waited forever. It now releases the child once the parent is at its gate, and the parent once the result is in the queue.
  • Time limit: under CPU load its waits ran out of the 5 s budget (12 of 66 runs). With 30 s, no run failed.

The CI log doesn't show which wait ran out, so what exactly failed the release run is not established. Both candidates are addressed.

Checks

  • The test without load_session fails without the fix and passes with it.
  • 51 runs under CPU load, no failures.
  • cargo test -p code_assistant_core, cargo fmt --check and clippy for code_assistant_core pass.
  • Not tried in the app.

Left as is

"Result queued" still shows just before the result is queued, because mark_result_queued runs before sink.finished. The window is now normally very short and only affects the display.

Delivering a background sub-agent's result waits until its spawn_agent
call is stored, and looked for the call in the session instance. A
running agent stores to persistence only, so the instance knew of the
call only after something reloaded it, such as a view loading the
session. Until then delivery kept retrying, and the result reached the
session only after the run ended, as a new turn. Look in persistence
when the instance doesn't know the call.

This also fixes a flaky test, which failed the release run 41593054062.
It released the parent as soon as the agent showed as queued, which
happens just before the result is: the parent could end its run, the
result then started a turn, and that turn's provider waited forever. It
now releases the child once the parent is at its gate and the parent
once the result is queued. Its waits also ran out under load, so they
get 30 s instead of 5 s.
@stippi
stippi merged commit ab1e916 into main Nov 3, 2026
6 checks passed
@stippi
stippi deleted the fix/flaky-queued-result-test branch November 3, 2026 16:33
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