cron: log model + token usage per run#18172
Conversation
Additional Comments (2)
Additionally, The type needs to be extended: And Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cron/run-log.ts
Line: 4:16
Comment:
**`CronRunLogEntry` missing new telemetry fields**
`appendCronRunLog` accepts `entry: CronRunLogEntry`, but this type does not include the `model`, `provider`, or `usage` fields that `server-cron.ts:216-218` now passes. Because the call site uses an object literal, TypeScript's excess property checking should reject this at compile time.
Additionally, `readCronRunLogEntries` (lines 98-115) reconstructs entries by explicitly copying only the known fields — so even though the data is written to the JSONL file (via `JSON.stringify`), reads through this function will strip `model`, `provider`, and `usage`, making the new telemetry invisible to the gateway API.
The type needs to be extended:
```suggestion
export type CronRunLogEntry = {
ts: number;
jobId: string;
action: "finished";
status?: "ok" | "error" | "skipped";
error?: string;
summary?: string;
sessionId?: string;
sessionKey?: string;
runAtMs?: number;
durationMs?: number;
nextRunAtMs?: number;
model?: string;
provider?: string;
usage?: {
input_tokens?: number;
output_tokens?: number;
total_tokens?: number;
cache_read_tokens?: number;
cache_write_tokens?: number;
};
};
```
And `readCronRunLogEntries` should be updated to copy these fields back when reading.
How can I resolve this? If you propose a fix, please make it concise.
Several non-best-effort error returns (here, line 596, 638, 724, 735) omit Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cron/isolated-agent/run.ts
Line: 583:588
Comment:
**Telemetry lost on delivery error paths**
Several non-best-effort error returns (here, line 596, 638, 724, 735) omit `...telemetry` even though the agent run completed successfully and consumed tokens. Since this PR is specifically about persisting usage telemetry, these paths will silently drop the `model`/`provider`/`usage` data from the cron run log entry. Consider spreading telemetry on error returns too:
```suggestion
return withRunSession({
status: "error",
error: resolvedDelivery.error.message,
summary,
outputText,
...telemetry,
});
```
How can I resolve this? If you propose a fix, please make it concise. |
Adds best-effort token telemetry (input/output/total when provider returns usage) to cron run JSONL records and includes a local report script to summarize token usage by job over a time window.
No cost estimation included.
Greptile Summary
Adds best-effort token telemetry (
model,provider,usage) to cron run JSONL records and includes a localscripts/cron_usage_report.tsto summarize token usage. The telemetry fields are correctly threaded through the cron service layer (state.ts→timer.ts→server-cron.ts) and the isolated agent runner (run.ts).CronRunLogEntrytype not updated (compile error): TheCronRunLogEntrytype insrc/cron/run-log.tswas not extended withmodel,provider, andusage. The call site inserver-cron.ts:216-218passes these as an object literal toappendCronRunLog(filePath, entry: CronRunLogEntry), which will fail TypeScript's excess property check. Additionally,readCronRunLogEntriesexplicitly reconstructs entries from only the old fields, so the gateway API will strip telemetry data when reading logs back.run.ts(lines 583, 596, 638, 724, 735) don't spread...telemetry, silently dropping usage data when delivery fails after a successful agent run.Confidence Score: 2/5
CronRunLogEntrytype inrun-log.tslacks the newmodel/provider/usagefields, which should produce a TS excess-property error whenserver-cron.tspasses them toappendCronRunLog. ThereadCronRunLogEntriesfunction also strips these fields on read-back. These are fixable issues but they prevent the feature from working as intended without a follow-up change.src/cron/run-log.tsneedsCronRunLogEntrytype andreadCronRunLogEntriesupdated.src/cron/isolated-agent/run.tserror return paths should include telemetry.Last reviewed commit: 098a205
(2/5) Greptile learns from your feedback when you react with thumbs up/down!