Skip to content

refactor(cron): simplify completed prompt accounting - #149818

Merged
steipete merged 1 commit into
mainfrom
codex/cron-accounting-owner-cleanup
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cron-accounting-owner-cleanup

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer-requested follow-up to #149767 and #149697.

What Problem This Solves

Simplifies cron retry accounting, which retained duplicate execution snapshots and copied the same prompt state through several layers.

User Impact

No user-visible behavior change, configuration change, or migration. Completed usage still survives failed retries; original errors, per-prompt pricing, final-request context, and session ownership checks are preserved.

Why This Change Was Made

Each prompt returns its completed result directly. The executor owns one ordered collection of completed prompts and publishes a readonly view before continuation persistence, so success and error accounting consume the same facts. This removes the mutable result cache, getState(), redundant model-selection fallbacks, and repeated parameter forwarding. The coordinator retains one settlement operation for diagnostics and guarded persistence.

Session teardown still releases the full snapshot after delivery, using a correctly typed empty map instead of a cast that assigns undefined to a required field.

Production code is reduced by 86 lines across four files. Two existing teardown assertions change; no tests or production seams are added.

Evidence

154 existing tests passed across nine accounting, retry, lifecycle, message-tool policy, model-switch, and fallback suites. Core typechecking and targeted typed lint passed. Isolated Codex review returned no actionable P0–P2 findings across both evidence passes.

The assertion-safety baseline shrinks by one entry because teardown no longer needs a cast. Local changed-file guards and the assertion-safety ratchet passed. The helper expanded to all 19 core test graphs; that duplicate local type sweep was stopped in favor of the same exact-head required CI checks running in parallel. The hosted live Gateway lane passed against commit 0af23d0861cf7146e4542b595cff858b757c4337: all ten allowlist cases across OpenClaw and Codex (empty, read, group:fs, r*, bash), plus five scheduler scenarios. The lane reported 12 passed tests and 21 unrelated skips. Workflow tooling was pinned by the run at e7989781acc9fb608a9f799ac80fb4473bb38859.

The full production build passed. Two real isolated Gateway/public CLI cases against that build passed using a registered synthetic harness and loopback provider: retry preparation throws, and the harness returns an abort. Each persisted 33 tokens and $0.0000515, preserved the original error/diagnostic, emitted exactly one terminal webhook without leaking the interim acknowledgement, and completed fixture cleanup. This is live Gateway boundary proof with a synthetic provider; the hosted lane above supplies real model proof.

Required CI passed on the exact candidate commit, including all production/test typechecks and the required openclaw/ci-gate. ClawSweeper completed source review on this head with no actionable findings.

@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 06:40
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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, 2:58 AM ET / 06:58 UTC (Revision 2).

ClawSweeper review

What this changes

Simplifies scheduled-run accounting around one ordered collection of completed prompts and releases the session snapshot with a correctly typed empty map.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, maintainer-requested cleanup. The pinned patch preserves the accounting and ownership contracts, introduces no actionable correctness finding, and is not already present on inspected main.

Priority: P3
Reviewed head: 0af23d0861cf7146e4542b595cff858b757c4337

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused simplification with relevant runtime observations, retained regression coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports production Gateway/public CLI runs through the changed accounting path with injected retry failure and abort, retaining exact usage and cost while preserving errors and single-webhook delivery; hosted allowlist checks are supplemental.
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 production Gateway/public CLI runs through the changed accounting path with injected retry failure and abort, retaining exact usage and cost while preserving errors and single-webhook delivery; hosted allowlist checks are supplemental.
Evidence reviewed 8 items Completed facts precede fallible persistence: Each prompt publishes its result before continuation persistence; the executor appends that result to its single ordered collection. The coordinator consumes those facts on both success and error paths.
Settlement and persistence invariants: The coordinator retains one settlement promise. The unchanged persistence owner checks the current lifecycle revision before committing, and teardown clears only the in-memory snapshot after persistence and delivery.
Existing regression coverage: The existing five-case table covers retry failure, cancellation, usage-persistence failure, replacement sessions, and delivery failure, asserting retained totals and nonduplicated diagnostics. The two changed teardown assertions still verify release of the full snapshot. Tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw’s scheduler runs agent prompts and may request a continuation after an interim acknowledgement. This accounting layer carries completed usage into billing, diagnostics, and the final run result, including when a later prompt fails.

flowchart TD
  A[Scheduled agent job] --> B[Execute prompt]
  B --> C[Record completed prompt]
  C --> D{Continuation needed?}
  D -->|Yes| B
  D -->|No or failed| E[Settle usage once]
  E --> F[Persist billing and diagnostics]
  F --> G[Finalize result and release snapshot]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -86, Tests 0, Other -1. Total -87 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 53 139 -86
Tests 1 2 2 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 6 55 142 -87

Review metrics

None.

Technical review

Best possible solution:

Keep completed-prompt facts owned by the executor and reuse the existing guarded settlement path without changing billing, delivery, or persisted formats.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR refactors already-fixed accounting behavior; existing regression scenarios and reported Gateway observations cover the contracts it must preserve.

Is this the best way to solve the issue?

Yes: the patch removes duplicate snapshots and routes all accounting consumers through the existing executor-owned collection without adding a competing implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 47d9a40df0af.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports production Gateway/public CLI runs through the changed accounting path with injected retry failure and abort, retaining exact usage and cost while preserving errors and single-webhook delivery; hosted allowlist checks are supplemental.

Label justifications:

  • P3: This is bounded internal simplification with no intended user-visible behavior or configuration change.
  • 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 production Gateway/public CLI runs through the changed accounting path with injected retry failure and abort, retaining exact usage and cost while preserving errors and single-webhook delivery; hosted allowlist checks are supplemental.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports production Gateway/public CLI runs through the changed accounting path with injected retry failure and abort, retaining exact usage and cost while preserving errors and single-webhook delivery; hosted allowlist checks are supplemental.

Evidence

What I checked:

  • Completed facts precede fallible persistence: Each prompt publishes its result before continuation persistence; the executor appends that result to its single ordered collection. The coordinator consumes those facts on both success and error paths. (src/cron/isolated-agent/run-executor.ts:958, 0af23d0861cf)
  • Settlement and persistence invariants: The coordinator retains one settlement promise. The unchanged persistence owner checks the current lifecycle revision before committing, and teardown clears only the in-memory snapshot after persistence and delivery. (src/cron/isolated-agent/run.ts:183, 0af23d0861cf)
  • Existing regression coverage: The existing five-case table covers retry failure, cancellation, usage-persistence failure, replacement sessions, and delivery failure, asserting retained totals and nonduplicated diagnostics. The two changed teardown assertions still verify release of the full snapshot. Tests were inspected, not executed during this read-only review. (src/cron/isolated-agent/run.retry-failure-usage.test.ts:24, 0af23d0861cf)
  • Current-main necessity: The four production modules on fetched main match the PR merge base exactly. Main still uses optional completed-run snapshots and the execution-envelope accounting interface, so this simplification remains distinct. (src/cron/isolated-agent/run-usage.ts:24, 47d9a40df0af)
  • Merged accounting history: Git history and GitHub metadata connect the existing accounting implementation to fix(cron): retain completed prompt usage after retry errors #149767 and fix(cron): suppress control tokens and retain retry usage #149697, both merged. These are preceding fixes, not replacements for this cleanup. GitHub identifies steipete as the author of the earlier settlement change; some older local blobs were unavailable, limiting blame traversal. (src/cron/isolated-agent/run.ts:183, 3257cbbf4a2f)
  • After-change Gateway observations: The complete captured PR body reports two production-build Gateway/public CLI runs using a registered synthetic harness and loopback provider: retry preparation failure and returned abort. Both retained 33 tokens and $0.0000515, preserved the original failure, and emitted one terminal webhook without the interim acknowledgement. Captured context identity: c20f23e3e8a2a97bd5f917b44c3bb67254b0dac75813287a035393aa7c83ca87. (0af23d0861cf)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-16T06:46:39.798Z sha 0af23d0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 16, 2026
@steipete
steipete merged commit 55e1802 into main Sep 16, 2026
278 checks passed
@steipete
steipete deleted the codex/cron-accounting-owner-cleanup branch September 16, 2026 07:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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