Skip to content

fix(muse): keep panes working while background workflows run - #39211

Draft
nwparker wants to merge 2 commits into
mainfrom
fix/muse-background-workflows
Draft

nwparker wants to merge 2 commits into
mainfrom
fix/muse-background-workflows

Conversation

@nwparker

@nwparker nwparker commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Note

Parked as a draft, not planned to merge. It depends on Muse's undocumented session log (session.jsonl), so any Muse release could change that format and quietly break workflow status. It also has known gaps: overlapping workflows turn done together when the first finishes, and pressing Esc doesn't stop a workflow, so the row stays working until the workflow actually ends. #38911 already covers background subagents using documented hooks. Next step: ask the Muse team for a documented workflow-completion hook, then redo this on top of it.

Refs #28090
Linear: STA-10361

Builds on #38911 (merged). This PR only adds the workflow layer.

What this adds

#38911 holds a finished Muse turn open while a spawned background subagent runs, using documented hooks only. Muse workflows (the workflow tool) need more: the lead's Stop comes before the first workflow agent's SubagentStart, and Muse fires no hook when a workflow ends. This PR adds a best-effort workflow hold:

  • Start: the documented workflow tool PostToolUse result {"status":"launched","taskId":…}. Only a live hook starts tracking; nothing in the log can start it.
  • End, whichever comes first:
    • the session log (session.jsonl) settling that task_id as completed, failed or cancelled;
    • the Stop of the run Muse wakes the lead in (a run with no UserPromptSubmit).
  • Yields to:
  • Holding only a workflow shows the row as working in monitoring mode. Once a workflow agent starts, it shows as working. transcriptPollUpdate now also republishes on a workingMode change.
  • Earlier-process fix kept: a Muse killed mid-workflow (kill -9) leaves its workflow.run.native task at started forever. Tracking only starts from live hooks, and SessionStart clears it, so that stale record can never hold a resumed session.

⚠️ Undocumented log format

How a workflow ends is read from Muse's session.jsonl task records (payload.kind: "task", payload.task_id, payload.event.kind). This is not a documented interface. The fallback, if a future Muse version stops writing those records or changes their shape:

  • The row stays held only until the wake run's Stop (a hook), or until 10 minutes pass without child activity.
  • If the log file can't be found, workflows never hold the row.

Live verification (real Muse Code 1.4.14 TUI)

Muse ran in tmux in a scratch directory with Orca's generated managed hooks file. Every hook was posted to a real AgentHookServer built from this branch:

Case Timeline
sleep 40 workflow lead Stop 22:42:47 → working (monitoring); agent starts → working; SubagentStop 22:43:34 → monitoring; log completed → done 22:43:36; wake Stop 22:43:39 → done
sleep 120 workflow held working through Esc and Ctrl-C (Muse fired no Interrupt and kept the workflow running) → done 22:50:22 when it finished
/exit → "Exit anyway" with a workflow running SessionEnd (reason other) 22:51:13 → done 22:51:14

Headless trace (muse exec): the launch taskId matched the log's workflow.run.native task. Its completed record came 0.6 s after the agent's SubagentStop, and 14 s before the wake run's Stop.

Tests

  • server-muse-session-log-poll.test.ts: a launched workflow holds the row in monitoring until the log settles it. The hold is also released if the log disappears.
  • muse-events.test.ts: the wake run's Stop ends a workflow the log never settled.

Checks

  • pnpm tc passes.
  • Scoped suites pass: src/shared/agent-hook-listener, src/main/agent-hooks, src/main/muse, src/wsl-guest, src/shared/agent-status, muse-session-log (243 files, 1541 tests).
  • ORCA_CODE_QUALITY_BASE=origin/fix/muse-background-subagents-done pnpm check:changed: 24 of 25 checks passed. The unit-test check failed. It selects the whole cross-version / runtime unit set, and four tests failed under machine load: orcad-chat-restart-offer, two runtime-rpc-long-poll-transport keepalive tests, and one cross-version-agent-session-wire test. Re-run on their own with --maxWorkers=2, all three files passed (54/54). None of them touch Muse code.

Known limits

  • A wake Stop releases every workflow launched in earlier runs, so two overlapping workflows can release together when the first one ends.
  • Esc and Ctrl-C don't stop a running workflow in Muse 1.4.14 and fire no Interrupt, so the row stays held until the workflow ends. That matches what Muse is doing.
  • Not verified on older Muse versions.
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​142 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​124

Hold the lead Stop through the shared child-work fold while UUID children
are live between SubagentStart and SubagentStop. A child that sends no hook
for 10 minutes stops holding the row. Interrupt (subscribed async, as Muse
requires), SessionStart and SessionEnd clear tracked children, and the
existing transcript-poll replay of the held Stop then reaches done.

Fixes #28090
Best-effort layer on top of the subagent hold. A workflow starts holding
the row from the documented `workflow` PostToolUse result
({status: "launched", taskId}) and stops on the first of: its task
settling (completed/failed/cancelled) in Muse's undocumented session.jsonl,
or the Stop of the run Muse wakes the lead in. It also yields to the
10-minute inactivity limit, Interrupt, SessionStart/SessionEnd, and an
unreadable log. Only live hooks start tracking, so work logged by an
earlier Muse process can never hold a resumed session.

Refs #28090

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.

1 participant