-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(coding-agent): hold goal continuations while subagent work is unsettled #1610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a6a507a
Hold goal continuations while subagent work is unsettled
snimu 0d18252
Add the changelog fragment and the continuation-quiescence unit suite
snimu 6365c15
Make the continuation resume wake, retry, and queue in order
snimu e42bbfa
Respect abort suspension and goal replacement in the resume
snimu 230e367
Count resumed continuations
snimu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fixed `/goal` re-prompting a parent that had correctly delegated to subagents and ended its turn: the continuation now waits until descendant work settles, then resumes automatically. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/coding-agent/test/goal-continuation-quiescence.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { AgentSession } from "../src/core/agent-session.js"; | ||
|
|
||
| type Harness = { | ||
| _goalState: { status: string; objective?: string; continuationsUsed: number }; | ||
| _goalContinuationAwaitsRlmWork: boolean; | ||
| _disposed: boolean; | ||
| _disposing: boolean; | ||
| _sessionInputAdmissionPauses: Set<symbol>; | ||
| _sessionInputPumpSuspended: boolean; | ||
| _hasUnsettledRlmQuiescenceWork: () => boolean; | ||
| _stopGoalContinuationForTerminalMessage: () => boolean; | ||
| _ensureGoalRuntimeActive: () => void; | ||
| _setGoalState: (goal: unknown) => void; | ||
| _createPreparedTurnAction: ReturnType<typeof vi.fn>; | ||
| _admitSessionInput: ReturnType<typeof vi.fn>; | ||
| }; | ||
|
|
||
| const getGoalContinuation = Reflect.get(AgentSession.prototype, "_getGoalContinuationMessages") as ( | ||
| this: Harness, | ||
| context: { message: unknown; context: unknown }, | ||
| ) => Promise<unknown[]>; | ||
| const maybeResume = Reflect.get(AgentSession.prototype, "_maybeResumeGoalContinuationAfterRlmWork") as ( | ||
| this: Harness, | ||
| ) => void; | ||
|
|
||
| function harness(overrides: Partial<Harness> = {}): Harness { | ||
| return { | ||
| _goalState: { status: "active", objective: "ship it", continuationsUsed: 0 }, | ||
| _goalContinuationAwaitsRlmWork: false, | ||
| _disposed: false, | ||
| _disposing: false, | ||
| _sessionInputAdmissionPauses: new Set(), | ||
| _sessionInputPumpSuspended: false, | ||
| _hasUnsettledRlmQuiescenceWork: () => false, | ||
| _stopGoalContinuationForTerminalMessage: () => false, | ||
| _ensureGoalRuntimeActive: () => {}, | ||
| _setGoalState: function (this: Harness, goal: unknown) { | ||
| this._goalState = goal as Harness["_goalState"]; | ||
| }, | ||
| _createPreparedTurnAction: vi.fn((schedule: string, _text: string, _images: unknown, options: unknown) => ({ | ||
| schedule, | ||
| options, | ||
| })), | ||
| _admitSessionInput: vi.fn(), | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| const context = { message: { role: "assistant", stopReason: "stop" }, context: {} }; | ||
|
|
||
| describe("goal continuation vs unsettled subagent work", () => { | ||
| it("defers the continuation while descendant work is unsettled", async () => { | ||
| const mode = harness({ _hasUnsettledRlmQuiescenceWork: () => true }); | ||
| await expect(getGoalContinuation.call(mode, context)).resolves.toEqual([]); | ||
| expect(mode._goalContinuationAwaitsRlmWork).toBe(true); | ||
| expect(mode._goalState.continuationsUsed).toBe(0); | ||
| }); | ||
|
|
||
| it("continues normally when no descendant work is pending", async () => { | ||
| const mode = harness(); | ||
| const messages = await getGoalContinuation.call(mode, context); | ||
| expect(messages).toHaveLength(1); | ||
| expect(mode._goalContinuationAwaitsRlmWork).toBe(false); | ||
| expect(mode._goalState.continuationsUsed).toBe(1); | ||
| }); | ||
|
|
||
| it("resumes a deferred continuation exactly once, unqueued, idle-waking, and counted", () => { | ||
| const mode = harness({ _goalContinuationAwaitsRlmWork: true }); | ||
| maybeResume.call(mode); | ||
| maybeResume.call(mode); | ||
| expect(mode._admitSessionInput).toHaveBeenCalledTimes(1); | ||
| const [action, options] = mode._admitSessionInput.mock.calls[0]!; | ||
| expect((action as { options: { resumeIfIdle: boolean } }).options.resumeIfIdle).toBe(true); | ||
| expect(options).toBeUndefined(); | ||
| expect(mode._goalState.continuationsUsed).toBe(1); | ||
| }); | ||
|
|
||
| it("keeps the deferral while admission is paused and retries after release", () => { | ||
| const paused = harness({ | ||
| _goalContinuationAwaitsRlmWork: true, | ||
| _sessionInputAdmissionPauses: new Set([Symbol("pause")]), | ||
| }); | ||
| maybeResume.call(paused); | ||
| expect(paused._admitSessionInput).not.toHaveBeenCalled(); | ||
| expect(paused._goalContinuationAwaitsRlmWork).toBe(true); | ||
|
|
||
| paused._sessionInputAdmissionPauses.clear(); | ||
| maybeResume.call(paused); | ||
| expect(paused._admitSessionInput).toHaveBeenCalledTimes(1); | ||
| expect(paused._goalContinuationAwaitsRlmWork).toBe(false); | ||
| }); | ||
|
|
||
| it("keeps the deferral while the pump is suspended after an abort", () => { | ||
| const mode = harness({ _goalContinuationAwaitsRlmWork: true, _sessionInputPumpSuspended: true }); | ||
| maybeResume.call(mode); | ||
| expect(mode._admitSessionInput).not.toHaveBeenCalled(); | ||
| expect(mode._goalContinuationAwaitsRlmWork).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps the deferral and rolls back the count when admission throws", () => { | ||
| const mode = harness({ | ||
| _goalContinuationAwaitsRlmWork: true, | ||
| _admitSessionInput: vi.fn(() => { | ||
| throw new Error("admission race"); | ||
| }), | ||
| }); | ||
| maybeResume.call(mode); | ||
| expect(mode._goalContinuationAwaitsRlmWork).toBe(true); | ||
| expect(mode._goalState.continuationsUsed).toBe(0); | ||
| }); | ||
|
|
||
| it("stays deferred while work remains and drops the deferral for inactive goals", () => { | ||
| const busy = harness({ _goalContinuationAwaitsRlmWork: true, _hasUnsettledRlmQuiescenceWork: () => true }); | ||
| maybeResume.call(busy); | ||
| expect(busy._admitSessionInput).not.toHaveBeenCalled(); | ||
| expect(busy._goalContinuationAwaitsRlmWork).toBe(true); | ||
|
|
||
| const inactive = harness({ _goalContinuationAwaitsRlmWork: true }); | ||
| inactive._goalState = { status: "paused", objective: "ship it", continuationsUsed: 0 }; | ||
| maybeResume.call(inactive); | ||
| expect(inactive._admitSessionInput).not.toHaveBeenCalled(); | ||
| expect(inactive._goalContinuationAwaitsRlmWork).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.