Skip to content

Commit 6485746

Browse files
t3dotggclaude
andcommitted
fix(server): recover task completion titles from persisted activities
The completion title lived only in the in-memory description cache, so a session exit sweep, server restart, or TTL/capacity eviction before the terminal event left the completion row untitled even though earlier task.started/task.progress activities were persisted with the name. Fall back to scanning the thread's persisted activities (newest first) when the cache misses, reusing the memoized thread detail load. Addresses review comments from cursor[bot] and macroscopeapp[bot]. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 31c03e7 commit 6485746

2 files changed

Lines changed: 109 additions & 4 deletions

File tree

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,72 @@ describe("ProviderRuntimeIngestion", () => {
30713071
expect(completedPayload?.title).toBe("wait for codex review to finish");
30723072
});
30733073

3074+
it("titles task completion from persisted activities after the description cache is swept", async () => {
3075+
const harness = await createHarness();
3076+
const now = "2026-01-01T00:00:00.000Z";
3077+
3078+
harness.emit({
3079+
type: "task.progress",
3080+
eventId: asEventId("evt-swept-task-progress"),
3081+
provider: ProviderDriverKind.make("claudeAgent"),
3082+
createdAt: now,
3083+
threadId: asThreadId("thread-1"),
3084+
turnId: asTurnId("turn-swept-task"),
3085+
payload: {
3086+
taskId: "swept-task-1",
3087+
description: "Watch round-3 CI and bots",
3088+
summary: "Polling CI checks.",
3089+
},
3090+
});
3091+
3092+
await waitForThread(harness.readModel, (entry) =>
3093+
entry.activities.some(
3094+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-swept-task-progress",
3095+
),
3096+
);
3097+
3098+
// session.exited sweeps the in-memory description cache; the completion
3099+
// that follows must recover the name from persisted activities.
3100+
harness.emit({
3101+
type: "session.exited",
3102+
eventId: asEventId("evt-swept-task-session-exited"),
3103+
provider: ProviderDriverKind.make("claudeAgent"),
3104+
createdAt: now,
3105+
threadId: asThreadId("thread-1"),
3106+
payload: {},
3107+
});
3108+
3109+
harness.emit({
3110+
type: "task.completed",
3111+
eventId: asEventId("evt-swept-task-completed"),
3112+
provider: ProviderDriverKind.make("claudeAgent"),
3113+
createdAt: now,
3114+
threadId: asThreadId("thread-1"),
3115+
turnId: asTurnId("turn-swept-task"),
3116+
payload: {
3117+
taskId: "swept-task-1",
3118+
status: "completed",
3119+
summary: "CI is green.",
3120+
},
3121+
});
3122+
3123+
const thread = await waitForThread(harness.readModel, (entry) =>
3124+
entry.activities.some(
3125+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-swept-task-completed",
3126+
),
3127+
);
3128+
3129+
const completed = thread.activities.find(
3130+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-swept-task-completed",
3131+
);
3132+
const completedPayload =
3133+
completed?.payload && typeof completed.payload === "object"
3134+
? (completed.payload as Record<string, unknown>)
3135+
: undefined;
3136+
3137+
expect(completedPayload?.title).toBe("Watch round-3 CI and bots");
3138+
});
3139+
30743140
it("projects structured user input request and resolution as thread activities", async () => {
30753141
const harness = await createHarness();
30763142
const now = "2026-01-01T00:00:00.000Z";

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,41 @@ import { ServerSettingsService } from "../../serverSettings.ts";
4242
const providerTurnKey = (threadId: ThreadId, turnId: TurnId) => `${threadId}:${turnId}`;
4343
const providerTaskKey = (threadId: ThreadId, taskId: string) => `${threadId}:${taskId}`;
4444

45+
// Fallback when the in-memory description cache no longer has the task name
46+
// (server restart, session-exit sweep, TTL/capacity eviction): earlier
47+
// task.started/task.progress activities for the task are persisted with it.
48+
function findTaskTitleInActivities(
49+
activities: ReadonlyArray<OrchestrationThreadActivity> | undefined,
50+
taskId: string,
51+
): string | undefined {
52+
if (!activities) {
53+
return undefined;
54+
}
55+
for (let index = activities.length - 1; index >= 0; index -= 1) {
56+
const activity = activities[index];
57+
if (!activity || (activity.kind !== "task.started" && activity.kind !== "task.progress")) {
58+
continue;
59+
}
60+
const payload =
61+
activity.payload && typeof activity.payload === "object"
62+
? (activity.payload as { taskId?: unknown; title?: unknown; detail?: unknown })
63+
: undefined;
64+
if (payload?.taskId !== taskId) {
65+
continue;
66+
}
67+
const title =
68+
typeof payload.title === "string"
69+
? payload.title
70+
: activity.kind === "task.started" && typeof payload.detail === "string"
71+
? payload.detail
72+
: undefined;
73+
if (title && title.trim().length > 0) {
74+
return title;
75+
}
76+
}
77+
return undefined;
78+
}
79+
4580
interface AssistantSegmentState {
4681
baseKey: string;
4782
nextSegmentIndex: number;
@@ -1706,10 +1741,14 @@ const make = Effect.gen(function* () {
17061741
yield* rememberTaskDescription(thread.id, event.payload.taskId, description);
17071742
}
17081743
}
1709-
const taskTitle =
1710-
event.type === "task.completed"
1711-
? yield* lookupTaskDescription(thread.id, event.payload.taskId)
1712-
: undefined;
1744+
let taskTitle: string | undefined;
1745+
if (event.type === "task.completed") {
1746+
taskTitle = yield* lookupTaskDescription(thread.id, event.payload.taskId);
1747+
if (!taskTitle) {
1748+
const threadDetail = yield* getLoadedThreadDetail();
1749+
taskTitle = findTaskTitleInActivities(threadDetail?.activities, event.payload.taskId);
1750+
}
1751+
}
17131752

17141753
const activities = runtimeEventToActivities(event, taskTitle);
17151754
yield* Effect.forEach(activities, (activity) =>

0 commit comments

Comments
 (0)