Skip to content

fix(provider-omp): show subagents spawned by OMP's task tool - #31

Open
GustavBlack wants to merge 5 commits into
mainfrom
fix/omp-task-subagent-cards
Open

GustavBlack wants to merge 5 commits into
mainfrom
fix/omp-task-subagent-cards

Conversation

@GustavBlack

Copy link
Copy Markdown
Collaborator

Problem

When the OMP provider (omp --mode rpc) spawns subagents with its built-in task tool, the thread shows the call as one generic tool row: no subagent cards, no live progress, and background runs are never tracked. The Pi adapter this provider reuses projects subagent cards only when the tool is named subagent (the pi-subagents extension's name); OMP's fan-out tool is named task, so every call falls through to the dynamic_tool item. (#30)

Fix

  • PiFlavor gains subagentToolName (pi: subagent, omp: task), and the adapter's subagent projection is gated on the flavor instead of a hardcoded tool name — so a Pi user's own custom task tool is not misread.
  • OMP SingleResult mapping: output → result text, assignment/task → prompt, exitCode/stopReason → status. Pi results are unaffected (assignment is absent in the pi-subagents shape, so precedence falls back to task exactly as before).
  • Running cards are built from details.progress[], which OMP streams on tool_execution_update while results[] is still empty.
  • Background runs are tracked by details.async.jobId (previously only pi's asyncId), keep the session ingesting after the coordinator's turn ends via the existing background_work.updated pending signal, and settle from the <task-result> blocks OMP delivers through wait tool results.

Evidence

  • Three replay tests drive the adapter with frames recorded from a live omp 19.2.0 --mode rpc session — foreground blocking (async.enabled: false), parallel batch, and async background + wait. All three failed by timeout before the fix and pass after it: vp test run packages/provider-pi/src/server/adapter.test.ts → 175 pass / 2 skip / 1 fail.
  • The one failing test (recovers a historical Pi fork recorded before turns stored the session file) fails identically on main on this Windows machine — a path-separator assertion in the forkThread code, unrelated to this change.
  • Typecheck is clean for provider-pi and provider-omp; vp run check:changed format/lint/knip pass. Its remaining typecheck/test failures reproduce on clean main (t3, workflow-authoring) and are pre-existing.
  • Not yet done: an integrated pass in a real client (test-t3-app); this change is adapter-side and is exercised by the replay tests. Happy to add client screenshots in a follow-up comment.

Surfaces

  • Providers: OMP gains card projection; Pi behavior unchanged (the new gate resolves to subagent for pi, and the field precedence keeps pi mappings identical).
  • Contracts/protocol: additive only, no wire changes.
  • One deviation from the issue's proposal worth flagging: the issue proposed tracking background runs "until they settle" without naming a settle channel — the recorded sessions show OMP delivers settled results only through wait tool results, so the adapter parses the <task-result> blocks there (gated on a tracked run actually containing the id, so a Pi user's custom wait tool can never misfire).

Model/harness: ONI coding-agent harness (exact underlying model id not visible to the agent itself — can amend this line).

The Pi adapter projected subagent cards only for the tool named
"subagent" (pi-subagents). OMP's fan-out tool is named "task", so its
calls fell through to generic dynamic_tool rows: no cards, no live
progress, and background runs untracked.

PiFlavor gains subagentToolName (pi: "subagent", omp: "task") and the
adapter now projects OMP task calls: SingleResult.output for result text,
assignment/task for the prompt, exitCode for status, running cards from
details.progress[], background runs tracked by details.async.jobId and
settled from the task-result blocks omp delivers through wait results.

Replay tests recorded from omp 19.2.0 RPC cover foreground, parallel and
async sequences.
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L labels Nov 26, 2026
@MiaAI-Lab

Copy link
Copy Markdown
Owner

Not merged yet. The approach (flavor-gated subagentToolName) is right, but the OMP projection leaks running state:

  1. Orphan running card (foreground). Cards from progress[] are keyed recordString(entry, "id") ?? index, while cards from results[] are keyed recordNumber(result, "step") ?? index. OMP results carry id/index but no step, so …:subagent:WriteGamma (running) and …:subagent:0 (completed) are different subagents and the first spins forever. Use one key in both branches and assert in the test that the running subagent's id is the one that completes.
  2. completed ignored in the progress branch. An aborted/errored task whose end frame still has results: [] and running/pending progress entries leaves cards running after the tool ended. Map non-terminal statuses to interrupted/failed when completed is true.
  3. Background runs that never settle, which keeps background_work pending: true and the session loaded until OMP exits:
    • a spawn frame with async.jobId but no progress[].id is tracked with an empty member set that can never reach zero (fall back to {jobId} or don't track);
    • statuses other than completed/failed/error/aborted (cancelled, timeout, …) are skipped instead of settled;
    • the <task-result> regex requires an exact attribute order;
    • nothing drops a turn's OMP runs on Stop/abort or when the agent never calls wait.
  4. Pi path not fully gated. The progress[] fallback, the output preference in piSubagentOutput, the dropped !emitted guard and the wait hook also run for Pi. Gate them on the flavor so Pi behaves exactly as on main.

Please add failing-first tests for 1–3 (aborted/unknown status, jobId spawn without progress ids, turn ending without wait).

Review of PR #31 found the OMP projection leaking running state and
reaching into Pi's paths. Addressing each finding:

- One member key across progress and results cards (id, then step/index),
  so the running card is the card that completes; the replay test now
  asserts the running subagent's id is the one that settles.
- progress[] cards map to interrupted/failed when the tool ends without
  results (isError picks failed over interrupted).
- Background runs track members as id -> agent, falling back to the job
  id when a spawn carries no progress ids; every parsed task-result block
  settles its member (completed/failed/error as-is, anything else as
  interrupted); task-result attributes parse in any order; runs still
  tracked when the agent settles are dropped as interrupted, releasing
  background_work.
- The OMP-only paths (progress fallback, output preference, tracking
  guard, wait hook) are gated on the flavor, leaving Pi's behavior
  identical to main.

Failing-first tests cover each case: orphan key, errored end without
results, jobId-only spawn, cancelled status, attribute order, and
agent_settled without wait.
@GustavBlack

Copy link
Copy Markdown
Collaborator Author

Thanks for the review — all four findings confirmed against source and addressed in b0d67b1, each with a failing-first test.

1. Orphan running card (foreground) — fixed. Both branches key members the same way now: id, then step ?? index in the results branch and id, then async.jobId, then index in the progress branch, so the running card and the completing card share one id. The foreground replay test now asserts the running subagent's id is the one that settles — it failed exactly as described before the fix.

2. completed ignored in the progress branch — fixed. The projection now receives isError from the tool frame: when the tool ends without results, non-terminal progress statuses end as interrupted (isError: false) or failed (isError: true). Test: errored end frame with results: [] and running progress → card ends failed.

3. Background runs that never settle — fixed in four parts:

  • Members are an id → agent map that falls back to {jobId} when a spawn carries no progress[].id, so the job can settle by its own id.
  • Every parsed <task-result> block settles its member: completed/failed/error map to themselves, anything else (cancelled, timeout, …) to interrupted — nothing is skipped.
  • Attributes parse in any order (per-attribute match over the tag contents) instead of one fixed-order regex.
  • agent_settled drops still-tracked OMP runs — members go out interrupted and background_work clears when the turn has nothing left pending. This runs before the interrupted early-return, so the Stop/abort path is covered too.
  • Tests: jobId-only spawn settles via wait; a cancelled status settles interrupted; attribute order swapped parses; agent_settled without wait → interrupted cards + pending released.

4. Pi path not fully gated — fixed. One ompTaskDetails flag, derived from the flavor's subagentToolName, now gates the progress[] fallback, the output preference in piSubagentOutput, the tracking guard (pi's !emitted behavior restored), and the wait hook. Pi's paths are behaviorally identical to main; the existing pi-subagents tests pass unchanged.

One flag while testing 3: OMP 19.2.0 emits agent_end (plus session_settled) where the adapter hooks agent_settled. I could not verify in this environment whether the driver normalizes one into the other, so the no-wait teardown may not fire against a live OMP until that is confirmed — the replay tests exercise the adapter contract either way, and I'd rather flag it than claim it verified.

Evidence: 8 OMP replay tests, 6 of them red-first (orphan key, errored end without results, jobId-only spawn, cancelled status, attribute order, settle-without-wait). Full adapter file: 180 pass / 2 skip / 1 fail — the pre-existing Windows fork-separator test that fails identically on main. Typecheck clean for provider-pi and provider-omp.

Model/harness: ONI coding-agent harness.

OMP never emits Pi's `agent_settled`. Its RPC ends a stretch of agent
activity with `agent_end` per run followed by one `session_settled`
(coding-agent/src/modes/rpc/rpc-session-settle.ts), so the teardown added
for review could not fire in a live OMP session: background `task` runs
still tracked at agent end kept `background_work.updated pending: true`.

The `agent_settled` case now also matches `session_settled`, gated on the
OMP flavor so Pi's path is unchanged. The failing-first test replays
omp 19.2.0 frames (`agent_end` then `session_settled`) and asserts the
running card's id is the one that settles interrupted, with the run
released.

Verified against live omp 19.2.0 RPC: `session_settled` arrives once per
turn after each `agent_end`, and no `agent_settled` frame exists.
@GustavBlack

Copy link
Copy Markdown
Collaborator Author

Follow-up to my reply above. TL;DR: the OMP teardown in b0d67b1d10 hung on agent_settled, which OMP never emits; cd61215218 hooks the frame it actually sends. The four review findings are unchanged and still addressed.

The mismatch. OMP's RPC ends a stretch of agent activity with agent_end per run, then one session_settled (packages/coding-agent/src/modes/rpc/rpc-session-settle.ts). There is no agent_settled frame anywhere in omp, so dropUnsettledOmpRuns() could not fire against a real omp child: background task runs still tracked at agent end would keep background_work.updated pending: true.

Fix (cd61215218). The agent_settled case now also matches session_settled, gated on the OMP flavor (if (event["type"] === "session_settled" && !ompTaskDetails) return;), so Pi's behavior is identical to main. dropUnsettledOmpRuns() already skips non-omp runs.

Failing-first test. "interrupts OMP runs still tracked when omp's session settles" replays the real frame order (agent_end → session_settled), captures the running card's id and asserts the same id settles interrupted, plus pending: false. With the adapter hunk stashed the test times out waiting for the settle; with it, it passes.

Evidence it's the right frame, live. Two omp 19.2.0 RPC sessions driven directly against the CLI:

  • one turn: ready → agent_start → agent_end → prompt_result → session_settled; zero agent_settled
  • two turns in one session: agent_start → agent_end → session_settled → agent_start → agent_end → session_settled — one settle per turn, not only at session end

Checks. adapter.test.ts: 181 pass, 2 skip, 1 fail — the pre-existing Windows-only path assertion at adapter.test.ts:3277 (backslash vs slash in the --fork argument), which fails the same way on main. effect-tsgo --noEmit in packages/provider-pi exits 0; format, lint and knip pass.

Not done / out of scope. updateProviderSession("ready") at adapter.ts:2483 (wake buffering) still keys on agent_settled only — pre-existing, untouched here. The teardown is proven at adapter level with replayed frames, not from a live T3 session making a real task call.

@MiaAI-Lab

Copy link
Copy Markdown
Owner

Re-reviewed at cd61215218: the four earlier findings are addressed, and packages/provider-pi/src/server/adapter.test.ts passes 184/184 here on Linux (the Windows path failure doesn't reproduce). One blocker remains: session_settled now calls dropUnsettledOmpRuns() (packages/provider-pi/src/server/adapter.ts:2776-2778), and your own live trace shows omp sends one session_settled per turn. That marks every background task run interrupted and clears background_work as soon as the coordinator turn that spawned it ends, and a later wait can no longer settle it because the run has already been removed from piAsyncRuns (adapter.ts:1731) — the opposite of #30's goal that background tasks keep updating after the turn. Please check omp's rpc-session-settle.ts for whether session_settled waits for running async jobs; if it doesn't, keep runs tracked across session_settled, drop them only on Stop/abort or session close, and add a test that spawns async in one turn and settles via wait in the next. Separately, session_settled now also drives the shared settle path (finalizeTurn / scheduleSettleProbe) for every OMP turn, which is a turn-lifecycle change that deserves its own test.

(Review notes prepared with Claude Code on behalf of the maintainer.)

…sion settle

Review blocker on #31: `session_settled` fires once per turn, and omp's
settle predicate excludes deliveries it has suppressed (a `wait` in
flight, a foreground job, a user-interrupted run). Dropping every tracked
run at `session_settled` therefore killed runs that were still live: the
card was marked interrupted while its job still worked, and a later `wait`
could not settle it because the run was already gone from `piAsyncRuns`.

Tracking now ends only with evidence:

- Runs settle from `<task-result>` blocks wherever omp emits them: `wait`
  tool results and the `async-result` custom message it records when a job
  finishes without a waiting agent (same envelope, now parsed once).
- A stopped turn still abandons its runs at `session_settled` (they cannot
  keep running after Stop), and a closing transport drops them with the
  process.
- A background spawn's `tool_execution_end` no longer interrupts its own
  cards: `details.async.state: "running"` means the job continues, so its
  progress rows keep their status. Aborted/errored calls still end
  non-terminal members as interrupted/failed. A spawn that already settled
  is not tracked at all (previously a pending leak).

Failing-first: "settles an OMP background run from its async-result
delivery", "settles an OMP background run from a wait in a later turn",
"interrupts OMP runs when the stopped session closes" (all three fail on
the previous commit; the first two assert the running card's id is the one
that settles, and that `background_work` clears). Plus "settles the OMP
turn when omp's session settles" for the turn-lifecycle path the review
asked to cover.

adapter.test.ts: 184 pass, 2 skip, 1 fail (pre-existing Windows fork-path
assertion at :3277, fails identically without this change). Typecheck,
format and lint clean for packages/provider-pi.
`recovers a historical Pi fork recorded before turns stored the session
file` built its fixture paths as `${dir}/original.jsonl` from the OS temp
directory. The fork scans that directory with `path.join`, so on Windows
the adapter passes `C:\tmp\x\original.jsonl` to `--fork` while the test
expected the mixed-separator `C:\tmp\x/original.jsonl`: the same file, a
different string, and the only failing test in adapter.test.ts on Windows.

Join the fixture paths the way production does. On POSIX `path.join`
yields the identical strings, so the assertion is unchanged there.

adapter.test.ts is now 185 pass / 2 skip / 0 fail on Windows.
@GustavBlack

Copy link
Copy Markdown
Collaborator Author

Re-reviewed blocker addressed at 5f3ea951aa. Answer to your question first: omp's session_settled does not wait for running background jobs.

isSessionSettled (packages/coding-agent/src/session/session-settle.ts) reads only isRunActive, isStreaming, hasAdmittedSubmission, queuedMessageCount and the scheduled-turn probe — never wakeSources. And #wakeSources() (agent-session.ts:3879) deliberately omits jobs it suppressed: a job watched by an in-flight wait, a foreground job, an acknowledged delivery. After a user interrupt it returns undefined outright (#agentInitiatedTurnsSuppressed, agent-session.ts:3923). The run does pause with awaitingAsyncWork while a non-suppressed job can wake it, which is why the ordinary spawn-then-finish path settles late — but the predicate alone guarantees nothing, exactly as you said. So tracking no longer ends on it.

What changed (6149df5920):

  1. Teardown only with evidence. dropUnsettledOmpRuns() is now called only inside the interrupted branch of session_settled/agent_settled (a stopped turn cannot keep cards running) and unconditionally in the transport-close handler (adapter.ts:3136), so a session that dies still releases background_work. A normal session_settled leaves piAsyncRuns intact.
  2. A real settle path for background results instead of a teardown fallback. The <task-result> parser became settleOmpTaskResults(text) and now also runs on the async-result custom message_end — that is where omp delivers a finished job when nobody calls wait, and its <system-notice> carries the envelope verbatim (session/async-job-delivery.ts:141, prompts/tools/async-result.md; escapeHarnessTags only escapes harness tags, so task-result survives). Both paths settle members by the same key.
  3. Two bugs the new tests exposed, also fixed. A background spawn's tool_execution_end used to map its own still-running progress rows to interrupted, because completed meant "the tool call ended" while details.async.state was still "running"; the run keeps its reported statuses now, and an aborted/errored call still ends non-terminal members as interrupted/failed. And a spawn that already reports a settled async state is no longer tracked at all — previously it registered a run nothing could settle (a pending: true leak the old teardown was masking).
  4. Your second ask: the turn-lifecycle path has its own test. session_settled → scheduleSettleProbe → finalizeTurn is covered by "settles the OMP turn when omp's session settles" (turn.terminal completed). Behavior there is unchanged.

Tests (all in packages/provider-pi/src/server/adapter.test.ts):

  • "settles an OMP background run from its async-result delivery" — spawn async, agent_end + session_settled, then the async-result message; asserts the card that settles is the one that was spawned (id captured on the spawn event), status completed not interrupted, and background_work clears.
  • "settles an OMP background run from a wait in a later turn" — your scenario: spawn in turn 1, session_settled, turn 2 calls wait, same identity assertion.
  • "interrupts OMP runs when the stopped session closes" — Stop on a paused turn terminates the connection; the tracked run must not survive as pending.
  • "interrupts OMP runs still tracked when a stopped turn settles" — the abort path (interruptTurn → agent_end + session_settled) still interrupts and releases.
  • "settles the OMP turn when omp's session settles" — the turn-lifecycle test above.

Red-first: I stashed only adapter.ts and reran. "…from its async-result delivery" fails on its assertion (the interrupted card arrives first); "…from a wait in a later turn" and "…when the stopped session closes" both time out because the card never settles. With the change restored, all pass.

Results. vp test run packages/provider-pi/src/server/adapter.test.ts: 185 pass, 2 skip, 0 fail on Windows. effect-tsgo tsrs --noEmit in packages/provider-pi exits 0; vp fmt --check and vp lint clean on both files. The two tests that pass before and after ("…when a stopped turn settles", "…when omp's session settles") are regression/characterisation guards, not red-first ones.

Also included, deliberately separate (5f3ea951aa): the last Windows-only failure in this file — the historical-fork test built its fixture paths as ${dir}/original.jsonl while the fork lookup scans the directory with path.join, so on Windows we compared C:\tmp\x\original.jsonl against C:\tmp\x/original.jsonl. The fixture now uses NodePath.join, matching production; on POSIX the strings are identical. It is a test-only change in its own commit, so it can be dropped from this PR if you would rather keep the diff scoped to the OMP projection.

Not covered / still open:

  • No live omp session this round (the configured model here 404s), so the new settle paths are proven at adapter level with replayed omp frames, not from a live task spawn inside T3.
  • Cross-turn card updates are asserted at adapter level; that the projection accepts a subagent.updated for an already-terminal turn from a later turn's wait is not verified end-to-end here.
  • updateProviderSession("ready") at adapter.ts:2483 (wake buffering) still keys on agent_settled only — pre-existing, untouched.

Model/harness: ONI coding-agent harness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants