refactor(fb15c): split SubagentRunner into modules - #171
Conversation
dirac-run
left a comment
There was a problem hiding this comment.
Requested follow-up: await this.runProgress.flush() changes recorder flushing from fire-and-forget to part of the awaited run lifecycle. A slow or stuck filesystem append can now delay terminal completion, despite the PR being described as behavior-preserving. Please either preserve the previous non-blocking behavior or explicitly document and test the new completion contract, ideally with a bounded wait.
a7c4c7e to
52a0cba
Compare
|
Follow-up needed: The recorder flush issue is fixed, but the extraction dropped the terminal phase transition from When timeout or parent cancellation wins Please restore |
- Introduce SubagentRunTypes for shared run/result/progress/stats/tool types. - Extract pure helpers into SubagentRunHelpers (usage state, stats, tool serialization, tool-call preview/normalization, best-effort result). - Update SubagentToolExecutor and SubagentAbortHandler to import from the new modules and tighten any[]/any types. Co-Authored-By: Alexandros Salapatas <alexsal.alex@gmail.com>
Move phase tracking, liveness, heartbeat, activity markers, runtime progress snapshot and diagnostic details out of SubagentRunner into SubagentRunState. Co-Authored-By: Alexandros Salapatas <alexsal.alex@gmail.com>
- Extract progress enqueueing, draining, terminal/flush/summary behavior into SubagentRunProgress. - Convert SubagentRunner into a run-orchestration adapter that delegates status to SubagentRunState and progress to SubagentRunProgress. - Re-export public types from ./SubagentRunTypes for backward compatibility. Co-Authored-By: Alexandros Salapatas <alexsal.alex@gmail.com>
- shouldCompactBeforeNextRequest never read modelId - remove stray blank line in import block
await flush() blocked terminal completion on slow fs append. back to void flush() (pre-split behavior). regression test: run() resolves with hung flush.
enterPhase(phaseForStatus(...)) was dropped when recordTerminal moved to SubagentRunProgress. on timeout/parent-cancel, phase stayed "cancelling" instead of transitioning to "cancelled". regression test asserts cancelled phase on cancel.
52a0cba to
2937b59
Compare
|
LGTM. |
refactor(fb15c): split SubagentRunner into modules
Summary
Split the 1033-line
SubagentRunner.tsinto focused modules undersrc/core/task/tools/subagent/:SubagentRunTypes.ts— run status/result/progress/tool-call typesSubagentRunHelpers.ts— pure functions (tool-call parsing, result blocks, best-effort result)SubagentRunState.ts— phase/liveness/heartbeat trackingSubagentRunProgress.ts— progress queue/drain + recorder flushSubagentRunner.tsbecomes the orchestration adapter.Why
FIX-BACKLOG FB-15c — single responsibility: runner keeps orchestration; state, progress, types, and pure helpers are separate units.
Review follow-ups
1. Flush blocking terminal completion
Reviewer flagged
await this.runProgress.flush()in thefinallyblock: it changed recorder flushing from fire-and-forget to part of the awaited run lifecycle, so a slow or stuck filesystem append could delay terminal completion.Fix: restored the pre-split fire-and-forget behavior —
void this.runProgress.flush()instead ofawait. Errors are still handled internally bySubagentRunProgress.flush()(try/catch →reportRecorderFailure).Regression test:
does not block terminal completion on a slow recorder flush— stubsrecorder.flush()to hang forever; assertsrun()still resolves withCOMPLETEDand thatflush()was called.2. Terminal phase stuck on "cancelling"
Reviewer flagged that
recordTerminalwas missing theenterPhasecall after extraction. On timeout/parent-cancel, the terminal progress reportedstatus: cancelledwhilephaseremainedcancelling.Fix: restored
this.enterPhase(this.phaseForStatus(result.status), "subagent run settled", { status: result.status })beforerunProgress.recordTerminal()inSubagentRunner.recordTerminal().Regression test:
reports cancelled phase on parent cancel, not cancelling— triggers parent abort, collects progress updates, asserts every cancelled-status update hasphase: "cancelled".Notes / Caveats
master.AgentConfigLoaderEPERM on TCC-protected~/Documents/Diracis environment-specific (machine has no Full Disk Access); not from this PR.Verification
tsc -p tsconfig.unit-test.json --noEmit— only pre-existingsrc/shared/storage/types.tsbaseline error.biome checkon touched files — 1 pre-existing warning (not from these changes).SubagentRunner.test.ts— new regression tests passing (2/2 targeted).SubagentRunRecorder.test.ts— 4/4 passing.SubagentBuilder.test.ts— 5/5 passing.Closes FB-15c (FIX-BACKLOG).