Skip to content

fix(cron): retain completed prompt usage after retry errors - #149767

Merged
steipete merged 1 commit into
mainfrom
codex/cron-retry-error-usage
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cron-retry-error-usage

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Real Gateway baseline reproduced: on f7b6ec34117, an isolated Gateway and registered synthetic harness completed a prompt with 10 input tokens, 20 output tokens, and 3 cache-read tokens, then threw AgentHarnessPreflightError during the retry. The cron CLI reported the original Synthetic cron retry preparation failed. error, but run usage was absent instead of totaling 33 tokens.
  • Runner tests passed: 59 tests across five retry, accounting, and lifecycle suites. The final five-case regression table also passed: retry rejection, cancellation, accounting-write failure with a late abort, a competing session generation, and delivery failure after a completed retry. These checks cover original-error preservation, no interim delivery, unchanged replacement-session billing, and no duplicate usage diagnostics.
  • Checks passed: scoped lint, formatting, diff checks, and a fresh isolated review through P2 with no actionable findings. The original-code regression failed on missing usage before the repair.
  • Candidate build and live proof passed: full production build at final head 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.
  • Required CI passed: run 35061190786 completed successfully on the final head. Both live cases also passed again after the main refresh.

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.
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 16, 2026 05:51
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 1:57 AM ET / 05:57 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 4f1114ee2b2385df80796e96ea6ebc9946e10a29

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant Gateway observations, meaningful failure-path coverage, and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports the actual isolated Gateway and public cron CLI exercising retry rejection and returned abort, retaining 33 tokens and cost with one failure webhook and no interim acknowledgement. This directly exercises the changed cron accounting owner; proof-to-head equivalence is author-reported because the earlier candidate object is unavailable locally.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports the actual isolated Gateway and public cron CLI exercising retry rejection and returned abort, retaining 33 tokens and cost with one failure webhook and no interim acknowledgement. This directly exercises the changed cron accounting owner; proof-to-head equivalence is author-reported because the earlier candidate object is unavailable locally.
Evidence reviewed 8 items Current main still needs the repair: The fetched main error handler returns the failure without completed usage. Comparing the PR base with fetched main shows no intervening changes under src/cron/isolated-agent.
Completed facts precede fallible continuation persistence: The executor publishes each completed result before continuation persistence; the run owner retains those facts and memoizes accounting settlement for both finalization and catch handling.
Existing session ownership guards remain authoritative: Accounting uses the existing session writer, whose update callback reads the current row and rejects competing lifecycle revisions. Continuation sealing also rejects foreign revisions and preserves already-sealed state.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +36, Tests +178. Total +214 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 111 75 +36
Tests 1 178 0 +178
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 289 75 +214

Review metrics

Metric Value Why it matters
Accounting repair size Production net +36 lines; tests +178 lines Production growth supplies the completed-result handoff and shared settlement needed to preserve billing across failures.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs incomplete usage and cost reporting for failed scheduled retries without evidence of an urgent runtime outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the actual isolated Gateway and public cron CLI exercising retry rejection and returned abort, retaining 33 tokens and cost with one failure webhook and no interim acknowledgement. This directly exercises the changed cron accounting owner; proof-to-head equivalence is author-reported because the earlier candidate object is unavailable locally.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports the actual isolated Gateway and public cron CLI exercising retry rejection and returned abort, retaining 33 tokens and cost with one failure webhook and no interim acknowledgement. This directly exercises the changed cron accounting owner; proof-to-head equivalence is author-reported because the earlier candidate object is unavailable locally.

Label justifications:

  • P2: This repairs incomplete usage and cost reporting for failed scheduled retries without evidence of an urgent runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports the actual isolated Gateway and public cron CLI exercising retry rejection and returned abort, retaining 33 tokens and cost with one failure webhook and no interim acknowledgement. This directly exercises the changed cron accounting owner; proof-to-head equivalence is author-reported because the earlier candidate object is unavailable locally.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the actual isolated Gateway and public cron CLI exercising retry rejection and returned abort, retaining 33 tokens and cost with one failure webhook and no interim acknowledgement. This directly exercises the changed cron accounting owner; proof-to-head equivalence is author-reported because the earlier candidate object is unavailable locally.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main error handler returns the failure without completed usage. Comparing the PR base with fetched main shows no intervening changes under src/cron/isolated-agent. (src/cron/isolated-agent/run.ts:322, 932846b521c0)
  • Completed facts precede fallible continuation persistence: The executor publishes each completed result before continuation persistence; the run owner retains those facts and memoizes accounting settlement for both finalization and catch handling. (src/cron/isolated-agent/run-executor.ts:960, 4f1114ee2b23)
  • Existing session ownership guards remain authoritative: Accounting uses the existing session writer, whose update callback reads the current row and rejects competing lifecycle revisions. Continuation sealing also rejects foreign revisions and preserves already-sealed state. (src/cron/isolated-agent/run-session-state.ts:194, 4f1114ee2b23)
  • Focused regression coverage: The five-case table covers retry rejection, cancellation, accounting persistence failure with a late abort, session replacement, and delivery failure. Assertions protect original errors, retained totals, replacement-session billing, acknowledgement suppression, and diagnostic event counts. Tests were inspected, not executed in this read-only review. (src/cron/isolated-agent/run.retry-failure-usage.test.ts:24, 4f1114ee2b23)
  • Reported production-path proof: The captured PR body reports an isolated Gateway and public cron CLI reproducing absent usage before the fix, then retaining 10 input, 20 output, and 3 cached tokens after retry rejection and returned abort. Each candidate case reportedly preserved its failure and emitted one terminal webhook with usage and no acknowledgement. The stated proof revision is a4aa094f6710345734e573ef860d507ef75056ef; that object is unavailable locally, so patch equivalence to the reviewed head rests on the captured author's explicit statement. Captured context sourceRevision: 4afe62620c495d1bb7e1b93914f8baa5ed3e6e22d9301bafc90d8f1cbc3e93fe. (a4aa094f6710)
  • Merged predecessor and feature-history routing: Provided GitHub metadata verifies fix(cron): suppress control tokens and retain retry usage #149697 merged at 08584b3. Its patch added completed-prompt aggregation; this PR extends that work to thrown continuation failures. The exact source line was checked against the commit's raw recorded parent. (src/cron/isolated-agent/run-usage.ts:25, 08584b3d34c5)

Likely related people:

  • Peter Steinberger: Raw commit 08584b3 adds src/cron/isolated-agent/run-usage.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 08584b3d34c5; files: src/cron/isolated-agent/run-usage.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 3257cbb into main Sep 16, 2026
271 checks passed
@steipete
steipete deleted the codex/cron-retry-error-usage branch September 16, 2026 06:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant