Skip to content

Commit c05bed4

Browse files
fix(server): a settled workflow member's transcript is read to its end
Each transcript read stops at the 512 KB cap, and the settled read marked the transcript fully read after one chunk. A member whose transcript grew past the cap lost its final answer. Reads now repeat until the reader reports no complete lines left, and only a transcript read to its end counts as final. A half-written last line no longer counts as truncation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent dd9d609 commit c05bed4

4 files changed

Lines changed: 95 additions & 19 deletions

File tree

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13959,6 +13959,60 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1395913959
),
1396013960
);
1396113961

13962+
it.effect("reads a settled workflow member's transcript to its end past the read cap", () =>
13963+
Effect.scoped(
13964+
Effect.gen(function* () {
13965+
const harness = yield* makeWorkflowHarness;
13966+
// About 1.3 MB of early replies: more than the launch frame's read
13967+
// and the settled frame's read together, at 512 KB each.
13968+
const filler = "x".repeat(16 * 1024);
13969+
NodeFS.writeFileSync(
13970+
NodePath.join(harness.transcriptDir, "agent-a1.jsonl"),
13971+
Array.from({ length: 80 }, (_, index) =>
13972+
memberAssistantLine(`line-early-${index}`, `msg_early_${index}`, [
13973+
{ type: "text", text: `${index} ${filler}` },
13974+
]),
13975+
).join("") +
13976+
memberAssistantLine("line-final", "msg_final", [
13977+
{ type: "text", text: "FINAL ANSWER" },
13978+
]),
13979+
);
13980+
yield* harness.runtime.startTurn(
13981+
makeClaudeTestTurnInput({
13982+
threadId: harness.threadId,
13983+
providerThread: harness.providerThread,
13984+
now: yield* DateTime.now,
13985+
attemptId: RunAttemptId.make("attempt-claude-workflow-member-long-transcript"),
13986+
text: "Run the alpha workflow.",
13987+
attachments: [],
13988+
}),
13989+
);
13990+
yield* launchWorkflow({ harness, snapshotUuid: "00000000-0000-4000-8000-000000001390" });
13991+
const threadId = workflowMemberEvents(harness.events, 1)[0]?.subagent.childThreadId;
13992+
yield* harness.offerAndWait(
13993+
workflowNotification({
13994+
uuid: "00000000-0000-4000-8000-000000001391",
13995+
status: "completed",
13996+
}),
13997+
);
13998+
const texts = threadMessages(harness.events, threadId)
13999+
.filter((event) => event.message.role === "assistant")
14000+
.map((event) => event.message.text);
14001+
assert.lengthOf(texts, 81);
14002+
assert.equal(texts.at(-1), "FINAL ANSWER", "the answer past the first read is shown");
14003+
yield* Queue.offer(
14004+
harness.sdkMessages,
14005+
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001392", result: "Done." }),
14006+
);
14007+
yield* Queue.take(harness.terminalReceipts);
14008+
}).pipe(
14009+
Effect.provide(
14010+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
14011+
),
14012+
),
14013+
),
14014+
);
14015+
1396214016
it.effect("re-reads a workflow member's transcript after a restart without new items", () =>
1396314017
Effect.scoped(
1396414018
Effect.gen(function* () {

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

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4697,28 +4697,42 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
46974697
let textShown = !restarted && previous?.textShown === true;
46984698
let resultShown = !restarted && previous?.resultShown === true;
46994699
let transcriptRead = false;
4700-
if ((readTranscript || readLiveTranscript) && agentId !== undefined) {
4701-
const read = yield* readWorkflowAgentTranscript({
4702-
transcriptDir,
4703-
agentId,
4704-
cursor: transcriptCursor,
4705-
...(adapterOptions.environment.CLAUDE_CONFIG_DIR === undefined
4706-
? {}
4707-
: {
4708-
configDir: path.resolve(
4709-
session.cwd,
4710-
adapterOptions.environment.CLAUDE_CONFIG_DIR,
4711-
),
4712-
}),
4713-
}).pipe(Effect.option);
4714-
if ((yield* Ref.get(sessionSubagentsByTaskId)).get(taskId) !== input.coordinator)
4715-
return;
4716-
if (Option.isSome(read)) {
4700+
// Each read is capped, so keep reading until the transcript has no
4701+
// more complete lines; a settled member's answer may be past the cap.
4702+
let transcriptDrained = true;
4703+
if (
4704+
(readTranscript || readLiveTranscript) &&
4705+
transcriptDir !== undefined &&
4706+
agentId !== undefined
4707+
) {
4708+
const readNext = (cursor: WorkflowAgentTranscriptCursor) =>
4709+
readWorkflowAgentTranscript({
4710+
transcriptDir,
4711+
agentId,
4712+
cursor,
4713+
...(adapterOptions.environment.CLAUDE_CONFIG_DIR === undefined
4714+
? {}
4715+
: {
4716+
configDir: path.resolve(
4717+
session.cwd,
4718+
adapterOptions.environment.CLAUDE_CONFIG_DIR,
4719+
),
4720+
}),
4721+
}).pipe(Effect.option);
4722+
transcriptDrained = false;
4723+
while (!transcriptDrained) {
4724+
const read = yield* readNext(transcriptCursor);
4725+
if ((yield* Ref.get(sessionSubagentsByTaskId)).get(taskId) !== input.coordinator)
4726+
return;
4727+
if (Option.isNone(read)) break;
47174728
transcriptRead = true;
4729+
const advanced = read.value.cursor.offset !== transcriptCursor.offset;
47184730
transcriptCursor = read.value.cursor;
47194731
for (const line of read.value.lines) {
47204732
if (yield* projectSubagentTranscriptLine(target, line)) textShown = true;
47214733
}
4734+
// A line longer than the cap can't advance; stop rather than spin.
4735+
transcriptDrained = !read.value.truncated || !advanced;
47224736
}
47234737
}
47244738
if (settled) {
@@ -4756,6 +4770,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
47564770
(!restarted && previous?.finalTranscriptRead === true) ||
47574771
(readTranscript &&
47584772
transcriptRead &&
4773+
transcriptDrained &&
47594774
textShown &&
47604775
input.coordinator.task.status !== "running"),
47614776
transcriptCursor,

‎apps/server/src/orchestration-v2/workflowAgentTranscript.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export const readWorkflowAgentTranscript = Effect.fn("orchestration.readWorkflow
8989
endOffset: file.endOffset,
9090
lineCount: lines.length,
9191
});
92-
return { lines, cursor: { offset: file.endOffset, identity: file.identity } };
92+
return {
93+
lines,
94+
cursor: { offset: file.endOffset, identity: file.identity },
95+
// More complete lines may follow past the per-read cap.
96+
truncated: file.truncated,
97+
};
9398
},
9499
);

‎apps/server/src/orchestration-v2/workflowFileRead.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export const readContainedWorkflowFile = Effect.fn("orchestration.readContainedW
104104
const consumed = lineEnd === 0 && bytesRead === input.byteCap ? bytesRead : lineEnd;
105105
return {
106106
contents: read.subarray(0, lineEnd).toString("utf8"),
107-
truncated: start + consumed < stat.size,
107+
// Only the cap can leave complete lines unread; a half-written
108+
// last line is not truncation.
109+
truncated: stat.size - start > input.byteCap,
108110
startOffset: start,
109111
endOffset: start + consumed,
110112
identity,

0 commit comments

Comments
 (0)