Skip to content

Commit 2063409

Browse files
committed
fix(server): keep agent linkage and settle stopped sessions at startup
Two gaps in background-agent settlement. The fold copied only the newest row's payload onto the synthesized terminal row, so when later lifecycle rows carried just a task id and a status the settled row lost agentKind and its workflow grouping — and once the start row aged out of the client's activity window, that row was the only one left and the agent disappeared from the panel. Startup also skipped threads whose session was already stopped, so a process that died between marking a session stopped and settling its children left those rows running on every later boot. Linkage is now merged across every row for a task, newest non-empty value winning, and covers the full set ingestion stamps minus per-row state. Startup settles any thread it does not own regardless of session status, reading every candidate thread's task history in one batched, chunked query instead of a query per thread. Implemented by Claude Opus 5 via Claude Code.
1 parent df0fd6c commit 2063409

6 files changed

Lines changed: 353 additions & 109 deletions

File tree

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,8 +3785,10 @@ describe("selectLiveAgentTasks", () => {
37853785
]);
37863786

37873787
expect(live.map((task) => task.taskId).toSorted()).toEqual(["live-explicit", "live-implicit"]);
3788+
// The status row carried no title; the start row's survives the merge.
37883789
expect(live.find((task) => task.taskId === "live-explicit")?.linkage).toEqual({
37893790
agentKind: "agent",
3791+
title: "one",
37903792
});
37913793
});
37923794

@@ -3823,6 +3825,58 @@ describe("selectLiveAgentTasks", () => {
38233825
expect(live.map((task) => task.taskId).toSorted()).toEqual(["other-1", "other-member-1"]);
38243826
});
38253827

3828+
it("keeps linkage from earlier rows when a later row carries only a status", () => {
3829+
// Terminal and status-patch rows commonly carry nothing but taskId and
3830+
// status. If the settled row copied only that newest payload it would
3831+
// land with no agentKind — and once the start row falls out of the
3832+
// client's activity window, the client would read the settled row as
3833+
// background work and drop the agent from the panel entirely.
3834+
const live = selectLiveAgentTasks([
3835+
row("a1", "task.started", {
3836+
taskId: "wf-member-1",
3837+
...agent,
3838+
taskType: "local_agent",
3839+
title: "math_one",
3840+
role: "general-purpose",
3841+
agentPath: "agents/math_one",
3842+
timelineBypass: true,
3843+
model: "gpt-5-codex",
3844+
effort: "high",
3845+
parentAgentId: "wf-1",
3846+
workflowName: "release",
3847+
agentIndex: 2,
3848+
phaseIndex: 1,
3849+
phaseTitle: "Implement",
3850+
attempt: 1,
3851+
outputFile: "/tmp/out.md",
3852+
}),
3853+
row("a2", "task.updated", { taskId: "wf-member-1", status: "running" }),
3854+
]);
3855+
3856+
expect(live).toEqual([
3857+
{
3858+
taskId: "wf-member-1",
3859+
linkage: {
3860+
agentKind: "agent",
3861+
taskType: "local_agent",
3862+
title: "math_one",
3863+
role: "general-purpose",
3864+
agentPath: "agents/math_one",
3865+
timelineBypass: true,
3866+
model: "gpt-5-codex",
3867+
effort: "high",
3868+
parentAgentId: "wf-1",
3869+
workflowName: "release",
3870+
agentIndex: 2,
3871+
phaseIndex: 1,
3872+
phaseTitle: "Implement",
3873+
attempt: 1,
3874+
outputFile: "/tmp/out.md",
3875+
},
3876+
},
3877+
]);
3878+
});
3879+
38263880
it("carries the newest linkage onto the live task", () => {
38273881
const live = selectLiveAgentTasks([
38283882
row("a1", "task.started", { taskId: "child", ...agent, title: "old-name" }),

0 commit comments

Comments
 (0)