Skip to content

Commit 3cfbc36

Browse files
fix(server): keep queued Claude workflow members pending (pingdotgg#25325)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 8b21cbd commit 3cfbc36

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18217,7 +18217,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1821718217
phaseTitle: "Alpha",
1821818218
model: input.model ?? "claude-opus-5[1m]",
1821918219
promptPreview: input.prompt ?? "Reply with exactly: A1",
18220-
...(input.startedAt === undefined ? {} : { startedAt: input.startedAt }),
18220+
// Claude reports a scheduled member as `start` and only sets startedAt once it runs.
18221+
...(input.startedAt === undefined && input.state !== "start"
18222+
? {}
18223+
: { startedAt: input.startedAt ?? 0 }),
1822118224
...(input.lastProgressAt === undefined ? {} : { lastProgressAt: input.lastProgressAt }),
1822218225
...(input.durationMs === undefined ? {} : { durationMs: input.durationMs }),
1822318226
...(input.attempt === undefined ? {} : { attempt: input.attempt }),
@@ -18234,6 +18237,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1823418237
phaseIndex: 1,
1823518238
phaseTitle: "Alpha",
1823618239
promptPreview: "Reply with exactly: A2",
18240+
...((input.secondState ?? input.state) === "start" ? { startedAt: 0 } : {}),
1823718241
...(input.state === "done" ? { resultPreview: "A2 excerpt" } : {}),
1823818242
},
1823918243
],
@@ -18727,6 +18731,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1872718731
uuid: "00000000-0000-4000-8000-000000001005",
1872818732
state: "start",
1872918733
secondState: "queued",
18734+
startedAt: DateTime.toEpochMillis(memberStartedAt),
1873018735
}),
1873118736
);
1873218737
yield* harness.until(() => coordinatorTurnItems().length > turnItemsBeforeRepeat);
@@ -18750,6 +18755,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1875018755
uuid: "00000000-0000-4000-8000-000000001017",
1875118756
state: "start",
1875218757
secondState: "queued",
18758+
startedAt: DateTime.toEpochMillis(memberStartedAt),
1875318759
label: "alpha:review",
1875418760
prompt: "Review the change",
1875518761
model: "claude-sonnet-4-6",

‎apps/server/src/orchestration-v2/Adapters/claudeWorkflowProgress.test.ts‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ describe("mergeClaudeWorkflowProgress", () => {
7474
expect(workflow?.agents[2]).not.toHaveProperty("completedAt");
7575
});
7676

77+
it("keeps a started member queued until the provider reports its startedAt", () => {
78+
const scheduled = mergeClaudeWorkflowProgress({
79+
previous: undefined,
80+
message: snapshotFrame([agent({ state: "start", queuedAt: 1000 })]),
81+
});
82+
expect(scheduled?.agents[0]?.state).toBe("queued");
83+
const started = mergeClaudeWorkflowProgress({
84+
previous: scheduled,
85+
message: snapshotFrame([agent({ state: "start", queuedAt: 1000, startedAt: 21_000 })]),
86+
});
87+
expect(started?.agents[0]).toMatchObject({ state: "running", startedAt: 21_000 });
88+
});
89+
7790
it.each(["something-new", "toString", "constructor", "__proto__"])(
7891
"treats unrecognised state %s as still running rather than settled",
7992
(state) => {
@@ -133,7 +146,14 @@ describe("mergeClaudeWorkflowProgress", () => {
133146
agents: first.agents.map((member) => ({ ...member, effort: "max", speed: "standard" })),
134147
},
135148
message: snapshotFrame([
136-
{ type: "workflow_agent", index: 1, label: "alpha:one", state: "start", attempt: 2 },
149+
{
150+
type: "workflow_agent",
151+
index: 1,
152+
label: "alpha:one",
153+
state: "start",
154+
attempt: 2,
155+
startedAt: 3000,
156+
},
137157
]),
138158
});
139159
expect(second?.agents).toEqual([
@@ -142,6 +162,7 @@ describe("mergeClaudeWorkflowProgress", () => {
142162
label: "alpha:one",
143163
state: "running",
144164
attempt: 2,
165+
startedAt: 3000,
145166
phaseIndex: 1,
146167
phaseTitle: "Alpha",
147168
},
@@ -171,12 +192,14 @@ describe("mergeClaudeWorkflowProgress", () => {
171192
])("keeps member state when the same attempt regresses from %s to %s", (state, staleState) => {
172193
const first = mergeClaudeWorkflowProgress({
173194
previous: undefined,
174-
message: snapshotFrame([agent({ state, attempt: 2, resultPreview: "Current result" })]),
195+
message: snapshotFrame([
196+
agent({ state, attempt: 2, startedAt: 1010, resultPreview: "Current result" }),
197+
]),
175198
});
176199
const second = mergeClaudeWorkflowProgress({
177200
previous: first,
178201
message: snapshotFrame([
179-
agent({ state: staleState, attempt: 2, resultPreview: "Old result" }),
202+
agent({ state: staleState, attempt: 2, startedAt: 1010, resultPreview: "Old result" }),
180203
]),
181204
});
182205
expect(second?.agents).toEqual(first?.agents);

‎apps/server/src/orchestration-v2/Adapters/claudeWorkflowProgress.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ function parseAgent(entry: unknown): OrchestrationV2WorkflowAgent | null {
5353
const label = text(field(entry, "label"));
5454
if (index === undefined || label === undefined) return null;
5555
const reportedState = text(field(entry, "state")) ?? "";
56-
const state = Object.hasOwn(AGENT_STATES, reportedState)
57-
? (AGENT_STATES[reportedState] ?? "running")
58-
: "running";
56+
const startedAt = timestamp(field(entry, "startedAt"));
57+
// Claude marks members `start` when scheduled; they only run once a concurrency slot sets startedAt.
58+
const state =
59+
reportedState === "start" && startedAt === undefined
60+
? "queued"
61+
: Object.hasOwn(AGENT_STATES, reportedState)
62+
? (AGENT_STATES[reportedState] ?? "running")
63+
: "running";
5964
return {
6065
index,
6166
label,
@@ -69,7 +74,7 @@ function parseAgent(entry: unknown): OrchestrationV2WorkflowAgent | null {
6974
...optional("toolCalls", count(field(entry, "toolCalls"))),
7075
...optional("durationMs", count(field(entry, "durationMs"))),
7176
...optional("queuedAt", timestamp(field(entry, "queuedAt"))),
72-
...optional("startedAt", timestamp(field(entry, "startedAt"))),
77+
...optional("startedAt", startedAt),
7378
// Execution duration excludes startup waits; terminal progress carries the end instant.
7479
...optional(
7580
"completedAt",

0 commit comments

Comments
 (0)