Repository navigation
fix(cron): retain completed prompt usage after retry errors - #149767
Conversation
Publish completed prompt facts before continuation persistence and settle billing once across success and error paths. Preserve the original failure, suppress interim acknowledgement delivery, and retain lifecycle guards when persisting usage.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 1:57 AM ET / 05:57 UTC. ClawSweeper reviewWhat this changesThe PR preserves completed scheduled-prompt usage and cost when a later retry fails, while sharing accounting settlement across success and error paths. Merge readiness✅ Ready for maintainer review This remains a useful follow-up to the merged retry-accounting work: current main still loses completed usage when the continuation throws. No blocking correctness defect was found, and the protected maintainer PR should remain open. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway scheduler runs agent prompts and may retry an interim acknowledgement before delivering a final answer. Cron accounting converts completed prompt results into run telemetry, session billing, and diagnostic events. flowchart TD
A[Scheduled agent job] --> B[Execute prompt]
B --> C[Capture completed usage]
C --> D{Continuation outcome}
D -->|Completed| E[Finalize result]
D -->|Failed| F[Preserve original error]
E --> G[Settle accounting once]
F --> G
G --> H[Guarded session write and run telemetry]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +36, Tests +178. Total +214 across 5 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain completed billing facts in the run owner, settle them once, and preserve the existing separation between billing, final context adoption, and guarded session persistence. Do we have a high-confidence way to reproduce the issue? Yes: complete an acknowledgement prompt with usage, then throw during its continuation; current main bypasses final accounting and returns no usage. Source confirms the path, and the PR reports a matching Gateway reproduction; this review did not execute it. Is this the best way to solve the issue? Yes. The patch reuses existing accounting and guarded persistence, preserves successful-run behavior, and avoids a second billing owner or storage migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 932846b521c0. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…#149767) Publish completed prompt facts before continuation persistence and settle billing once across success and error paths. Preserve the original failure, suppress interim acknowledgement delivery, and retain lifecycle guards when persisting usage.
Follows #149697 (merged).
What Problem This Solves
Fixes missing cron usage when a retry after an acknowledgement throws or is cancelled, even though the first prompt already consumed tokens.
User Impact
Failed scheduled runs retain completed prompt usage and cost while preserving the original error. The interim acknowledgement is not delivered, and accounting cannot overwrite a replacement session. No configuration or migration is required.
Why This Change Was Made
The execution owner now records completed prompts before continuation persistence can fail. Success and error handling share one accounting settlement, so usage and diagnostics are recorded once even if later persistence or delivery fails. Final-result context adoption stays separate, and session writes retain their existing lifecycle checks.
Evidence
f7b6ec34117, an isolated Gateway and registered synthetic harness completed a prompt with 10 input tokens, 20 output tokens, and 3 cache-read tokens, then threwAgentHarnessPreflightErrorduring the retry. The cron CLI reported the originalSynthetic cron retry preparation failed.error, but run usage was absent instead of totaling 33 tokens.4f1114ee2b2385df80796e96ea6ebc9946e10a29, followed by both registered-harness cases through the actual isolated Gateway and public cron CLI. Each retained 10 input, 20 output and 3 cached tokens (33 total), with session cost $0.0000515. The thrown error and the returned-abort diagnostic were preserved. Each emitted exactly one terminal failure webhook with the same usage, omitted diagnostic/summary fields according to the existing webhook contract, and contained no interim acknowledgement. Owned processes and isolated state were cleaned up.