Skip to content

Commit 31c03e7

Browse files
t3dotggclaude
andcommitted
feat(server): title background-task work-log rows with the task name
Task lifecycle events carry a human-readable description ("Typecheck mobile app", "Watch round-3 CI and bots"), but ingestion labeled every task.progress activity "Reasoning update" and task.completed rows lost the name entirely because terminal notifications don't include it. - Use the description as the task.progress summary and payload.title, falling back to the old label when it trims empty. - Remember descriptions per (threadId, taskId) in a bounded cache so task.completed rows get a payload.title too. Lookups don't consume the entry, keeping replayed terminal events titled; entries are swept with the other per-thread caches on session exit. - Mirror task.progress by emitting summary alongside detail on task.completed so clients render "name - completion summary". Server-only: clients already prefer payload.title/summary/detail when labeling work-log rows, so no web or mobile changes are needed. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 32e7844 commit 31c03e7

2 files changed

Lines changed: 184 additions & 3 deletions

File tree

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,130 @@ describe("ProviderRuntimeIngestion", () => {
29472947
).toBe("# Plan title");
29482948
});
29492949

2950+
it("titles task activities with the task description, including on completion", async () => {
2951+
const harness = await createHarness();
2952+
const now = "2026-01-01T00:00:00.000Z";
2953+
2954+
harness.emit({
2955+
type: "task.started",
2956+
eventId: asEventId("evt-named-task-started"),
2957+
provider: ProviderDriverKind.make("claudeAgent"),
2958+
createdAt: now,
2959+
threadId: asThreadId("thread-1"),
2960+
turnId: asTurnId("turn-named-task"),
2961+
payload: {
2962+
taskId: "named-task-1",
2963+
description: "Typecheck mobile app",
2964+
taskType: "local_bash",
2965+
},
2966+
});
2967+
2968+
harness.emit({
2969+
type: "task.progress",
2970+
eventId: asEventId("evt-named-task-progress"),
2971+
provider: ProviderDriverKind.make("claudeAgent"),
2972+
createdAt: now,
2973+
threadId: asThreadId("thread-1"),
2974+
turnId: asTurnId("turn-named-task"),
2975+
payload: {
2976+
taskId: "named-task-1",
2977+
description: "Typecheck mobile app",
2978+
summary: "Running tsc across the mobile workspace.",
2979+
},
2980+
});
2981+
2982+
harness.emit({
2983+
type: "task.completed",
2984+
eventId: asEventId("evt-named-task-completed"),
2985+
provider: ProviderDriverKind.make("claudeAgent"),
2986+
createdAt: now,
2987+
threadId: asThreadId("thread-1"),
2988+
turnId: asTurnId("turn-named-task"),
2989+
payload: {
2990+
taskId: "named-task-1",
2991+
status: "completed",
2992+
summary: "Typecheck finished without errors.",
2993+
},
2994+
});
2995+
2996+
const thread = await waitForThread(harness.readModel, (entry) =>
2997+
entry.activities.some(
2998+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-named-task-completed",
2999+
),
3000+
);
3001+
3002+
const progress = thread.activities.find(
3003+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-named-task-progress",
3004+
);
3005+
const completed = thread.activities.find(
3006+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-named-task-completed",
3007+
);
3008+
3009+
const progressPayload =
3010+
progress?.payload && typeof progress.payload === "object"
3011+
? (progress.payload as Record<string, unknown>)
3012+
: undefined;
3013+
const completedPayload =
3014+
completed?.payload && typeof completed.payload === "object"
3015+
? (completed.payload as Record<string, unknown>)
3016+
: undefined;
3017+
3018+
expect(progress?.summary).toBe("Typecheck mobile app");
3019+
expect(progressPayload?.title).toBe("Typecheck mobile app");
3020+
expect(completed?.summary).toBe("Task completed");
3021+
expect(completedPayload?.title).toBe("Typecheck mobile app");
3022+
expect(completedPayload?.summary).toBe("Typecheck finished without errors.");
3023+
expect(completedPayload?.detail).toBe("Typecheck finished without errors.");
3024+
});
3025+
3026+
it("titles task completion from task.started when no progress event carried the name", async () => {
3027+
const harness = await createHarness();
3028+
const now = "2026-01-01T00:00:00.000Z";
3029+
3030+
harness.emit({
3031+
type: "task.started",
3032+
eventId: asEventId("evt-fast-task-started"),
3033+
provider: ProviderDriverKind.make("claudeAgent"),
3034+
createdAt: now,
3035+
threadId: asThreadId("thread-1"),
3036+
turnId: asTurnId("turn-fast-task"),
3037+
payload: {
3038+
taskId: "fast-task-1",
3039+
description: "wait for codex review to finish",
3040+
taskType: "local_bash",
3041+
},
3042+
});
3043+
3044+
harness.emit({
3045+
type: "task.completed",
3046+
eventId: asEventId("evt-fast-task-completed"),
3047+
provider: ProviderDriverKind.make("claudeAgent"),
3048+
createdAt: now,
3049+
threadId: asThreadId("thread-1"),
3050+
turnId: asTurnId("turn-fast-task"),
3051+
payload: {
3052+
taskId: "fast-task-1",
3053+
status: "completed",
3054+
},
3055+
});
3056+
3057+
const thread = await waitForThread(harness.readModel, (entry) =>
3058+
entry.activities.some(
3059+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-fast-task-completed",
3060+
),
3061+
);
3062+
3063+
const completed = thread.activities.find(
3064+
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-fast-task-completed",
3065+
);
3066+
const completedPayload =
3067+
completed?.payload && typeof completed.payload === "object"
3068+
? (completed.payload as Record<string, unknown>)
3069+
: undefined;
3070+
3071+
expect(completedPayload?.title).toBe("wait for codex review to finish");
3072+
});
3073+
29503074
it("projects structured user input request and resolution as thread activities", async () => {
29513075
const harness = await createHarness();
29523076
const now = "2026-01-01T00:00:00.000Z";

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

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import { ServerSettingsService } from "../../serverSettings.ts";
4141

4242
const providerTurnKey = (threadId: ThreadId, turnId: TurnId) => `${threadId}:${turnId}`;
43+
const providerTaskKey = (threadId: ThreadId, taskId: string) => `${threadId}:${taskId}`;
4344

4445
interface AssistantSegmentState {
4546
baseKey: string;
@@ -53,6 +54,8 @@ const BUFFERED_MESSAGE_TEXT_BY_MESSAGE_ID_CACHE_CAPACITY = 20_000;
5354
const BUFFERED_MESSAGE_TEXT_BY_MESSAGE_ID_TTL = Duration.minutes(120);
5455
const BUFFERED_PROPOSED_PLAN_BY_ID_CACHE_CAPACITY = 10_000;
5556
const BUFFERED_PROPOSED_PLAN_BY_ID_TTL = Duration.minutes(120);
57+
const TASK_DESCRIPTION_BY_TASK_CACHE_CAPACITY = 10_000;
58+
const TASK_DESCRIPTION_BY_TASK_TTL = Duration.minutes(120);
5659
const MAX_BUFFERED_ASSISTANT_CHARS = 24_000;
5760
const STRICT_PROVIDER_LIFECYCLE_GUARD = process.env.T3CODE_STRICT_PROVIDER_LIFECYCLE_GUARD !== "0";
5861

@@ -264,6 +267,7 @@ function requestKindFromCanonicalRequestType(
264267

265268
function runtimeEventToActivities(
266269
event: ProviderRuntimeEvent,
270+
taskTitle?: string,
267271
): ReadonlyArray<OrchestrationThreadActivity> {
268272
const maybeSequence = (() => {
269273
const eventWithSequence = event as ProviderRuntimeEvent & { sessionSequence?: number };
@@ -473,9 +477,15 @@ function runtimeEventToActivities(
473477
createdAt: event.createdAt,
474478
tone: "info",
475479
kind: "task.progress",
476-
summary: "Reasoning update",
480+
summary:
481+
event.payload.description.trim().length > 0
482+
? truncateDetail(event.payload.description, 120)
483+
: "Reasoning update",
477484
payload: {
478485
taskId: event.payload.taskId,
486+
...(event.payload.description.trim().length > 0
487+
? { title: truncateDetail(event.payload.description, 120) }
488+
: {}),
479489
detail: truncateDetail(event.payload.summary ?? event.payload.description),
480490
...(event.payload.summary ? { summary: truncateDetail(event.payload.summary) } : {}),
481491
...(event.payload.lastToolName ? { lastToolName: event.payload.lastToolName } : {}),
@@ -503,7 +513,15 @@ function runtimeEventToActivities(
503513
payload: {
504514
taskId: event.payload.taskId,
505515
status: event.payload.status,
506-
...(event.payload.summary ? { detail: truncateDetail(event.payload.summary) } : {}),
516+
...(taskTitle ? { title: truncateDetail(taskTitle, 120) } : {}),
517+
// summary + detail mirror task.progress: clients label the row from
518+
// summary and keep detail for the preview/expanded body.
519+
...(event.payload.summary
520+
? {
521+
summary: truncateDetail(event.payload.summary),
522+
detail: truncateDetail(event.payload.summary),
523+
}
524+
: {}),
507525
...(event.payload.usage !== undefined ? { usage: event.payload.usage } : {}),
508526
},
509527
turnId: toTurnId(event.turnId) ?? null,
@@ -666,6 +684,27 @@ const make = Effect.gen(function* () {
666684
lookup: () => Effect.succeed({ text: "", createdAt: "" }),
667685
});
668686

687+
// Task names arrive on task.started/task.progress but not on task.completed,
688+
// so remember them per task to title the completion activity.
689+
const taskDescriptionByTaskKey = yield* Cache.make<string, string>({
690+
capacity: TASK_DESCRIPTION_BY_TASK_CACHE_CAPACITY,
691+
timeToLive: TASK_DESCRIPTION_BY_TASK_TTL,
692+
lookup: () => Effect.succeed(""),
693+
});
694+
695+
const rememberTaskDescription = (threadId: ThreadId, taskId: string, description: string) =>
696+
Cache.set(taskDescriptionByTaskKey, providerTaskKey(threadId, taskId), description);
697+
698+
// Entries are left in place after completion so replayed or duplicate
699+
// terminal events stay titled; TTL, capacity, and the session-exit sweep
700+
// bound the cache.
701+
const lookupTaskDescription = (threadId: ThreadId, taskId: string) =>
702+
Cache.getOption(taskDescriptionByTaskKey, providerTaskKey(threadId, taskId)).pipe(
703+
Effect.map((description) =>
704+
Option.filter(description, (value) => value.length > 0).pipe(Option.getOrUndefined),
705+
),
706+
);
707+
669708
const resolveThreadDetail = Effect.fn("resolveThreadDetail")(function* (threadId: ThreadId) {
670709
return yield* projectionSnapshotQuery
671710
.getThreadDetailById(threadId)
@@ -1090,6 +1129,7 @@ const make = Effect.gen(function* () {
10901129
const turnKeys = Array.from(yield* Cache.keys(turnMessageIdsByTurnKey));
10911130
const assistantSegmentKeys = Array.from(yield* Cache.keys(assistantSegmentStateByTurnKey));
10921131
const proposedPlanKeys = Array.from(yield* Cache.keys(bufferedProposedPlanById));
1132+
const taskDescriptionKeys = Array.from(yield* Cache.keys(taskDescriptionByTaskKey));
10931133
yield* Effect.forEach(
10941134
turnKeys,
10951135
(key) =>
@@ -1125,6 +1165,12 @@ const make = Effect.gen(function* () {
11251165
: Effect.void,
11261166
{ concurrency: 1 },
11271167
).pipe(Effect.asVoid);
1168+
yield* Effect.forEach(
1169+
taskDescriptionKeys,
1170+
(key) =>
1171+
key.startsWith(prefix) ? Cache.invalidate(taskDescriptionByTaskKey, key) : Effect.void,
1172+
{ concurrency: 1 },
1173+
).pipe(Effect.asVoid);
11281174
});
11291175

11301176
const getSourceProposedPlanReferenceForPendingTurnStart = Effect.fn(
@@ -1654,7 +1700,18 @@ const make = Effect.gen(function* () {
16541700
}
16551701
}
16561702

1657-
const activities = runtimeEventToActivities(event);
1703+
if (event.type === "task.started" || event.type === "task.progress") {
1704+
const description = event.payload.description?.trim();
1705+
if (description) {
1706+
yield* rememberTaskDescription(thread.id, event.payload.taskId, description);
1707+
}
1708+
}
1709+
const taskTitle =
1710+
event.type === "task.completed"
1711+
? yield* lookupTaskDescription(thread.id, event.payload.taskId)
1712+
: undefined;
1713+
1714+
const activities = runtimeEventToActivities(event, taskTitle);
16581715
yield* Effect.forEach(activities, (activity) =>
16591716
providerCommandId(event, "thread-activity-append").pipe(
16601717
Effect.flatMap((commandId) =>

0 commit comments

Comments
 (0)