feat(06-02): wire token usage tracking, session accumulation, and rotation into worker pipeline

- Add inputTokens/outputTokens fields to worker run-finished messages and workerMessageSchema
- Wire sessionService into WorkerServiceDependencies and ServiceGraph lazy slot
- Add token accumulation and rotation evaluation in run-finished handler
- Add 7 wiring integration tests verifying accumulation, rotation, and guard paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 4.6 committed 2026-03-26 23:03:23 -04:00
1 parent e54c632fd6
commit 5271f7ee5d
4 files changed
+228

No files matched your search

+8
View File
@@ -65,6 +65,8 @@ type ChildMessage =
sessionDisplayId: string | null;
costUsd: number | null;
unattributedCost: boolean;
inputTokens: number | null;
outputTokens: number | null;
};
const parentPort = process.parentPort;
@@ -236,6 +238,8 @@ async function startRun(job: RunJob) {
sessionDisplayId: result.sessionDisplayId ?? null,
costUsd: typeof result.costUsd === "number" ? result.costUsd : null,
unattributedCost: !result.costUsd,
inputTokens: result.usage?.inputTokens ?? null,
outputTokens: result.usage?.outputTokens ?? null,
});
} catch (error) {
post({
@@ -251,6 +255,8 @@ async function startRun(job: RunJob) {
sessionDisplayId: null,
costUsd: null,
unattributedCost: true,
inputTokens: null,
outputTokens: null,
});
} finally {
cancelledRuns.delete(job.runId);
@@ -279,6 +285,8 @@ function cancelRun(runId: string) {
sessionDisplayId: null,
costUsd: null,
unattributedCost: true,
inputTokens: null,
outputTokens: null,
});
return;
}