feat(web): show Claude workflow phases and members in Lineage #12598
MergedBil0000(GitHub profile, opens in a new tab)merged 90 commits into
main fromrefs/pull/12598/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/chat/ThreadLineageWorkflowRow.tsx lines 37 to 39OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -0,0 +19,21 @@19+20+function MemberRow({21+ member,22+ onOpen,23+}: {24+ member: RuntimeSubagent;25+ onOpen: (threadId: string) => void;26+}) {27+ const threadId = member.childThreadId;28+ return (29+ // Flex so the row button's flex-1 has something to stretch against;30+ // without it the button shrink-wraps and the elapsed time floats mid-row.31+ <li className="flex items-center">32+ <Button33+ size="sm"34+ variant="ghost"35+ disabled={threadId === null}36+ onClick={() => threadId !== null && onOpen(threadId)}37+ className={cn(38+ THREAD_DETAILS_PANEL_LINK_ROW_CLASS,39+ "h-6 gap-2 pl-7 pr-2.5 text-[12px] font-normal sm:h-6 sm:text-[12px]",
- packages/contracts/src/orchestrationV2.ts lines 3605 to 3614OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -2879,15 +2963,18 @@2963+ "not-regular-file": "Workflow file is not a regular file.",2964+ "changed-during-read": "Workflow file changed between resolution and open.",2965+ "read-failed": "Workflow file read failed.",28792966 } as const;288029672881-export class OrchestrationGetWorkflowScriptError extends Schema.TaggedError<OrchestrationGetWorkflowScriptError>()(2882- "OrchestrationGetWorkflowScriptError",2968+export class OrchestrationWorkflowFileError extends Schema.TaggedError<OrchestrationWorkflowFileError>()(2969+ "OrchestrationWorkflowFileError",28832970 {28842971 reason: Schema.Literals([28852972 "invalid-path",28862973 "root-unavailable",28872974 "not-found",28882975 "outside-root",2889- "not-js",2976+ "wrong-extension",28902977 "not-regular-file",28912978 "changed-during-read",28922979 "read-failed",28932980 ]),
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts lines 5366 to 5367OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4991,3 +5360,8 @@49915360 liveQuery.nativeThreadId,49925361 message.task_id,49935362 );5363+ // A workflow frame is worth an update even with an empty description:5364+ // it carries the phase plan, the member roster and the run's usage.5365+ const workflowProgress = field(message, "workflow_progress");5366+ const carriesWorkflowTelemetry =5367+ Array.isArray(workflowProgress) && workflowProgress.length > 0;apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 3452OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3263,0 +3432,21 @@3432+ id: nodeId,3433+ threadId: parentThread.id,3434+ runId: null,3435+ parentNodeId: input.coordinator.childRootNodeId,3436+ origin: "provider_native" as const,3437+ createdBy: "agent" as const,3438+ driver: CLAUDE_PROVIDER,3439+ providerInstanceId: parentThread.providerInstanceId,3440+ providerThreadId: null,3441+ childThreadId,3442+ nativeTaskRef: {3443+ driver: CLAUDE_PROVIDER,3444+ nativeId: memberKey,3445+ strength: "strong" as const,3446+ },3447+ prompt,3448+ title: member.label,3449+ model,3450+ status,3451+ result: member.result ?? null,3452+ startedAt: now,apps/server/src/orchestration/workflowFileRead.ts line 87OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -0,0 +68,21 @@68+ );69+ }70+71+ // TOCTOU-safe read (review finding): open FIRST, then verify what was72+ // actually opened via the file descriptor. Re-checking the path after73+ // open would race against a swap; fstat on the handle cannot. The two74+ // containment checks fail with their own tagged reasons (not manufactured75+ // Errors folded into read-failed); "read-failed" is reserved for genuine76+ // platform failures with the real cause attached.77+ const read = yield* Effect.tryPromise({78+ try: async () => {79+ const handle = await NodeFSP.open(resolved, "r");80+ try {81+ const stat = await handle.stat();82+ if (!stat.isFile()) {83+ return { failure: "not-regular-file" as const };84+ }85+ // The opened inode must be the same one realpath resolved to: a86+ // process swapping the path between realpath and open changes the87+ // inode, which this comparison catches.88+ const pathStat = await NodeFSP.lstat(resolved);
- apps/server/src/orchestration/workflowAgentAnswers.ts lines 54 to 58OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -0,0 +37,21 @@37+38+ for (const line of contents.split("\n")) {39+ if (line.trim().length === 0) continue;40+ let entry: unknown;41+ try {42+ entry = JSON.parse(line);43+ } catch {44+ // A capped read can cut the final line mid-object; drop it and keep the rest.45+ continue;46+ }47+ if (text(field(entry, "type")) !== "assistant") continue;48+ if (field(entry, "isMeta") === true) continue;49+50+ const message = field(entry, "message");51+ const content = field(message, "content");52+ if (!Array.isArray(content)) continue;53+ const body = content54+ .filter((block) => text(field(block, "type")) === "text")55+ .map((block) => text(field(block, "text")))56+ .filter((value): value is string => value !== undefined)57+ .join("\n\n");apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 3383OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -3263,0 +3363,21 @@3363+ * coordinator's progress snapshot — but everything the user expects3364+ * from a subagent (a thread to open, a prompt, an answer) is expressed3365+ * by the same events, so this emits exactly the sequence3366+ * updateClaudeSubagentNode emits rather than inventing a parallel3367+ * shape. Members hang off the coordinator's thread, not the run's, so3368+ * a fan-out of fifty does not bury the parent's lineage.3369+ */3370+ const projectClaudeWorkflowMembers = Effect.fnUntraced(function* (input: {3371+ readonly coordinator: ActiveClaudeSubagent;3372+ readonly workflow: OrchestrationV2SubagentWorkflow;3373+ }) {3374+ const parentThread = input.coordinator.childThread;3375+ if (parentThread === null) return;3376+ const now = yield* DateTime.now;3377+ const seen = yield* Ref.get(workflowMemberStates);3378+3379+ for (const member of input.workflow.agents) {3380+ // Derived from the coordinator's own ids, not from its task id:3381+ // a task id is unique only within one provider thread, and the3382+ // coordinator's node id already carries that scoping.3383+ const memberKey = `${input.coordinator.task.id}:agent:${member.index}`;
juliusmarminge requested changes
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 5592OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4032,3 +4343,5 @@40324343 readonly result?: SDKResultMessage;40334344 }) {40344345 yield* reasoningDeltas.flushTurn(input.context.nativeTurnId);4346+ if (input.status !== "completed") {4347+ for (const [taskId, subagent] of yield* Ref.get(sessionSubagentsByTaskId)) {packages/client-runtime/src/state/subagentRuntime.ts lines 946 to 947OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -826,13 +940,8 @@826- for (const member of workflowMembers) {827- if (member.phaseIndex !== null && !derived.has(member.phaseIndex)) {828- derived.set(829- member.phaseIndex,830- member.phaseTitle ?? `Phase ${member.phaseIndex + 1}`,831- );832- }833- }834- return Array.from(derived.entries())835- .map(([index, title]) => ({ index, title }))836- .slice()837- .sort((a, b) => a.index - b.index);838- })();940+ // Union, not either/or: the declared plan lags the members, because the941+ // provider only admits a phase once something in it starts. Members seed942+ // the map; the declared titles then overwrite whatever they guessed.943+ const phaseTitles = new Map<number, string>();944+ for (const member of workflowMembers) {945+ if (member.phaseIndex === null) continue;946+ phaseTitles.set(member.phaseIndex, member.phaseTitle ?? `Phase ${member.phaseIndex + 1}`);947+ }apps/server/src/orchestration/workflowAgentAnswers.ts line 94OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -0,0 +68,21 @@68+ turns.push(body);69+ }70+71+ return turns;72+}73+74+export const readWorkflowAgentAnswers = Effect.fn("orchestration.readWorkflowAgentAnswers")(75+ function* (input: { readonly transcriptDir: string; readonly agentId: string }) {76+ if (!AGENT_ID_PATTERN.test(input.agentId)) {77+ return yield* Effect.fail(78+ new OrchestrationWorkflowFileError({ reason: "invalid-path", path: input.agentId }),79+ );80+ }81+ const file = yield* readContainedWorkflowFile({82+ path: NodePath.join(input.transcriptDir, `agent-${input.agentId}.jsonl`),83+ extension: ".jsonl",84+ byteCap: TRANSCRIPT_BYTE_CAP,85+ tail: true,86+ });87+ return parseWorkflowAgentAnswers(88+ file.truncated ? file.contents.slice(file.contents.indexOf("\n") + 1) : file.contents,
Bil0000(GitHub profile, opens in a new tab) changed the title
- apps/web/src/components/chat/ThreadRelationshipsControl.tsx line 579OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -390,3 +417,19 @@390417 )}391418 </>392419 );420+ // A workflow wraps this row; everything else renders it directly.421+ const relationshipLink = (422+ <Tooltip>423+ <TooltipTrigger424+ delay={200}425+ render={426+ <Button427+ size="sm"428+ variant="ghost"429+ disabled={node?.missing === true}430+ onClick={() => openThread(threadId)}431+ className={`${THREAD_DETAILS_PANEL_LINK_ROW_CLASS} ${workflowGroup ? "h-12 sm:h-12" : ""}`}432+ />433+ }434+ >435+ {relationshipContent}
Bil0000(GitHub profile, opens in a new tab) closed this
Bil0000(GitHub profile, opens in a new tab) reopened this
Sign in to join this conversation.






macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed