Repository navigation
[Bug] rlm.collect(timeout_ms>0) returns running children at once in daemon sessions (held task prompt) #4020
Replies: 1 comment
|
Update: this still reproduces on current Repro on Same cells on the same commit with the fix: Port: one commit on top of ad16133: valkyriweb@de87e30 (6 files, +95/-5, with the Checks (Linux x86_64, Rust 1.98.1):
I did not run the workspace-wide gates ( If you would take this, I can open a PR on invitation, or a maintainer is welcome to pick up the commit directly. |
Uh oh!
There was an error while loading. Please reload this page.
Version: prime-agent 0.10.2 (stable, aarch64-apple-darwin). Also seen on 0.10.0. Source checked against
mainat 42a07c1.Summary
In a daemon-backed session (the TUI attached to a daemon),
await rlm.collect(names, timeout_ms=N)called in the same turn asrlm.spawn(...)returns at once withstatus='running',settled=False. Repeating it returns at once again. The children do not start until about 60 s later.The
rlm.collectdocstring says a positivetimeout_ms"blocks only this kernel call until the runs settle or the timeout elapses".Repro (TUI attached to a daemon)
Ask the agent to run these as separate python_repl calls in one turn:
Observed (daemon + TUI client):
The same cells under
-p --mode json(print host) behave as documented: the first collect blocks 37.7 s and returns both('done', True).In a 16-session conformance run on 0.10.2, 13 of 27
rlm.collectcalls with a positivetimeout_msreturned in under 0.1 s with unsettled children. Code that trusts one blocking collect then proceeds with empty answers (for example, a verifier judged empty reviews).Root cause
SupervisorChildSessions::spawn(crates/pa-daemon/src/rlm_children/host.rs) holds the child's task prompt until the spawning parent turn completes (wait_turn_done, bounded byTURN_DONE_WAIT_SECS = 60). A turn completes only atEngineEvent::Done, which is the end of the whole agent run.collectin the same turn then:refresh_record, which returns early becauseprompt_admittedis still false, so the row staysrunning;wait_for_child, which sendswait_for_idleto the child worker. The worker has not received its prompt, so it is idle and answers at once;running.The parent turn cannot complete while a blocking collect parks it, so the hold can only end by its 60 s timeout. Every in-turn collect before that returns at once.
Proposed fix
When
collectgets a positive budget, release the held task prompts of its own targets and wait for their admission inside the same budget, before the idle wait:ChildRecordgainsprompt_release: Arc<AtomicBool>. The spawn's held task passes it towait_turn_done, which now also ends when that flag is set.prompt_admission: Notifyfires when a detached prompt task admits, fails, or exits for a closed parent.collectwithtimeout_ms > 0setsprompt_releaseon its targets only, wakes the waiters, then waits per target untilprompt_admitted, a settled status,closed_by_parent, or the deadline.A
timeout_ms=0poll releases nothing and keeps today's ordering. Children that the collect does not name, including spawns later in the same turn, still wait for the turn boundary.Interaction with #3987. After admission, collect reads the child at once. On
mainwithout #3987's grace re-check inrefresh_record, a worker that has just accepted its prompt can read idle once, so collect could settle itdonewith no answer. This fix should land after #3987, or with it.git apply --checkof #3987 on this branch is clean.Branch with the patch and a regression test (
a_blocking_collect_mid_turn_releases_the_held_task_prompt, which fails without the fix): valkyriweb/prime-agent@main...fix/collect-releases-held-task-prompts (2 commits, includes a.changesfragment)Gates run on Linux: Linux x86_64, Rust 1.98.1 (CI's pin):
cargo fmt --checkok; the new test passes with the fix and fails without it (("running", None)vs("done", Some(..)));cargo clippy -p pa-daemon --all-targets -- -D warningsok;cargo test -p pa-daemon --lib1207 passed, 8 ignored.Happy to adjust the approach; I understand PRs need an invitation.
All reactions