Skip to content

fix(cron): retain run-owned pricing through finalization - #139374

Merged
steipete merged 1 commit into
mainfrom
codex/130706-extract-cron-20260905
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/130706-extract-cron-20260905

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Scheduled runs that report token usage without a monetary total can lose their cost estimate in a fleet, even when the selected agent has prices in its own models.json. Cron's finalizer omitted the selected agent directory when resolving those prices. A separate owner-boundary regression also showed finalization using an ambient alias policy after inference had left the selected runtime's metadata scope.

This extracts the useful cron finalization repair from #130706.

Why This Change Was Made

The existing prepared runtime now spans inference, accounting, delivery, and cleanup, with one final release that fences detached borrowing. Cost lookup receives the agent directory already selected during preparation. This keeps the repair in cron's existing owner and removes duplicated release paths.

Production LOC: +280/-288, net -8. Tests: +121/-1. Documentation: +2. Most of the run-file diff moves the existing body into its retained scope.

User Impact

Token-only automation results use the scheduled agent's local model prices, and final bookkeeping uses the metadata selected for that run. The change adds no configuration, protocol, or database surface.

Evidence

Both added regressions failed before their corresponding repairs: an explicit fleet with separate main/worker price files completed with an undefined estimate instead of the worker's $3; a different ambient alias policy also cleared the expected $3 estimate. The pricing resolver and local model files are real in these tests; inference is the existing cron runner harness.

  • 159 targeted cron tests passed on the rebased candidate, covering generation/pricing, usage, diagnostics, session admission/deletion, terminal lifecycle, CLI continuity and cancellation, interim retry, Workshop execution roots, and hook outcomes.
  • 29 existing prepared-runtime owner tests passed on the baseline, including superseded generation rejection and borrowed snapshot fencing.
  • Fresh managed Codex autoreview on the rebased candidate: scoped-clean through P2, no actionable findings.
  • Changed-scope checks (core/test types, lint, format, dead exports, architecture and state guards) passed; additional finalizer lint passed.
  • Actual isolated Gateway + registered CLI backend + OpenAI Responses API: the scheduled Luna run crossed a model-config reload and completed; the Sol control completed afterward. Both returned 217 input and 11 output tokens. A worker price of $3/million input tokens produced persisted cost $0.000651, despite a separate main-agent file priced $1. Two history rows were observed and the job was removed.
  • Actual isolated Gateway + stock openclaw runtime + OpenAI: Luna run completed across hot reload, followed by a successful Sol control; two history rows and job cleanup verified. This targeted rerun exited 0.
  • Both live probes used the same verified pre-rebase source tree on Blacksmith Testbox run 33989499566. The CLI pricing stage passed in a command whose later stock-runtime stage initially selected liveness instead of readiness; that independent stage was corrected to wait for /readyz and rerun successfully. Earlier fixture attempts were corrected to use supported credential loading, declared startup activation and exact no-tools enforcement.

The rebase onto 9c068e13bd187606cac6111d60700f09ef52bd89 preserves upstream Workshop execution-root plumbing and rejection handling. The pricing/lifetime repair and its production LOC delta are unchanged; the 159-test run and fresh review cover that integration. No fresh live run on the rewritten head is claimed.

Release-note context: fix automation cost estimates for selected agents with local model pricing and retain the run's metadata through finalization.

@clawsweeper

clawsweeper Bot commented Sep 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels Sep 5, 2026
Resolve token-only scheduled usage against the selected agent directory and retain the prepared metadata scope through accounting, delivery, and cleanup. Close the existing lease once and fence detached borrowing after release.

Extracts the focused cron finalization repair from #130706. Production LOC net -8; verified worker-local pricing and model reload/control through a real Gateway and OpenAI inference.
@steipete
steipete force-pushed the codex/130706-extract-cron-20260905 branch from d5b9bd3 to 1e18d5c Compare September 5, 2026 20:59
@steipete
steipete marked this pull request as ready for review September 5, 2026 21:01
@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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 5:06 PM ET / 21:06 UTC.

ClawSweeper review

What this changes

The PR keeps scheduled runs’ selected runtime metadata through accounting and cleanup, and uses the selected agent’s local prices when estimating token-only usage.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main still loses selected-agent pricing and leaves the retained metadata scope before finalization. No blocking introduced defect was found.

Priority: P2
Reviewed head: 1e18d5ca51cff0b6fc080c231c0be2d8b424a79a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful regressions, supplied live accounting results, and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied live Gateway observations exercise cron finalization across reload and show the selected worker’s price persisted correctly, followed by successful controls and cleanup. These observations cover the pre-rebase repair; the body separately reports rebased regression validation, and linked run inspection was unavailable here.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Supplied live Gateway observations exercise cron finalization across reload and show the selected worker’s price persisted correctly, followed by successful controls and cleanup. These observations cover the pre-rebase repair; the body separately reports rebased regression validation, and linked run inspection was unavailable here.
Evidence reviewed 8 items Verified introduced scope: The whitespace-insensitive comparison isolates the lifetime change: the existing execution, finalization, and cleanup body moves inside the retained scopes; borrowing is fenced before the final lease release. Repository origin identifies openclaw/openclaw.
Current main still needs the repair: Fetched main omits agentDir from cost resolution and releases the prepared runtime before calling the finalizer. This establishes remaining work without attributing unrelated base-branch changes to this PR.
Existing pricing contract: The shared resolver already accepts agentDir, reads that directory’s models.json, and otherwise resolves a default agent directory. Aggregate accounting preserves reported monetary totals. The PR supplies missing context to this existing mechanism rather than adding another pricing implementation.
Findings None None.
Security None None.

How this fits together

The cron scheduler prepares an agent runtime, executes a scheduled turn, then records usage and delivers its result. Finalization needs the same agent directory and model metadata used by that run.

flowchart TD
  A[Scheduled job] --> B[Prepare selected agent runtime]
  B --> C[Execute agent turn]
  C --> D[Finalize usage and result]
  E[Agent prices and retained metadata] --> D
  D --> F[Persist accounting and deliver]
  F --> G[Clean up and release runtime]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -8, Tests +120, Docs +2. Total +114 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 280 288 -8
Tests 1 121 1 +120
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 403 289 +114

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net -8 lines; tests net +120 lines Most visible churn moves existing code into its owning scope; added coverage protects two distinct pricing failures.

Technical review

Best possible solution:

Keep accounting, delivery, and cleanup inside the run’s existing metadata lifetime, with selected-agent pricing and one final release.

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

Yes, from source: token-only cron usage can resolve the wrong agent’s prices, and finalization runs outside the selected metadata scope on current main. Runtime reproduction was not executed during this read-only review.

Is this the best way to solve the issue?

Yes. Supplying the prepared agent directory and extending the existing scope fixes the owning boundary; a new pricing resolver or finalizer-only workaround would duplicate behavior or leave cleanup outside that lifetime.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The repair corrects scheduled-run cost estimates with a bounded accounting impact.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Supplied live Gateway observations exercise cron finalization across reload and show the selected worker’s price persisted correctly, followed by successful controls and cleanup. These observations cover the pre-rebase repair; the body separately reports rebased regression validation, and linked run inspection was unavailable here.
  • 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): Supplied live Gateway observations exercise cron finalization across reload and show the selected worker’s price persisted correctly, followed by successful controls and cleanup. These observations cover the pre-rebase repair; the body separately reports rebased regression validation, and linked run inspection was unavailable here.

Label justifications:

  • P2: The repair corrects scheduled-run cost estimates with a bounded accounting impact.
  • 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): Supplied live Gateway observations exercise cron finalization across reload and show the selected worker’s price persisted correctly, followed by successful controls and cleanup. These observations cover the pre-rebase repair; the body separately reports rebased regression validation, and linked run inspection was unavailable here.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied live Gateway observations exercise cron finalization across reload and show the selected worker’s price persisted correctly, followed by successful controls and cleanup. These observations cover the pre-rebase repair; the body separately reports rebased regression validation, and linked run inspection was unavailable here.

Evidence

What I checked:

  • Verified introduced scope: The whitespace-insensitive comparison isolates the lifetime change: the existing execution, finalization, and cleanup body moves inside the retained scopes; borrowing is fenced before the final lease release. Repository origin identifies openclaw/openclaw. (src/cron/isolated-agent/run.ts:116, 1e18d5ca51cf)
  • Current main still needs the repair: Fetched main omits agentDir from cost resolution and releases the prepared runtime before calling the finalizer. This establishes remaining work without attributing unrelated base-branch changes to this PR. (src/cron/isolated-agent/run-finalize.ts:228, f8b43dc795f2)
  • Existing pricing contract: The shared resolver already accepts agentDir, reads that directory’s models.json, and otherwise resolves a default agent directory. Aggregate accounting preserves reported monetary totals. The PR supplies missing context to this existing mechanism rather than adding another pricing implementation. (src/utils/usage-format.ts:280, 1e18d5ca51cf)
  • Runtime identity and borrowing boundaries: Borrowing a superseded generation requires matching config, agent identity, agent directory, inherited auth directory, workspace, and supported selections; aborted admission is rejected. The PR retains these checks and sets leaseActive false before release. No changed authorization principal or new credential path was identified. (src/agents/prepared-model-runtime-lease.ts:152, 1e18d5ca51cf)
  • Focused behavioral regressions: The two added tests assert a $3 estimate under conflicting ambient alias metadata and separate main/worker price files. Existing coverage checks one release and unavailable borrowing after completion. Pricing resolution is real; inference and runtime acquisition are mocked. The supplied body reports both new cases failed before their repairs and 159 targeted tests passed afterward; this review did not execute tests. (src/cron/isolated-agent/run.plugin-generation.test.ts:152, 1e18d5ca51cf)
  • Supplied real Gateway observations: The captured body, sourceRevision 164b0140b5b8ebde5043624b92a0c0bbde67d90bb1786a39530e06b7381835d7, records isolated Gateway runs with real OpenAI inference across reload: 217 input tokens at the worker’s $3/million price persisted $0.000651 despite the main agent’s $1 price. It also records a stock-runtime control, two history rows, and cleanup. Evidence references https://github.com/openclaw/openclaw/actions/runs/33989499566 and explicitly predates the rebase; no exact-head live run is claimed. Both API and browser attempts to inspect the linked run failed in the review environment.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Brett Daman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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.

@steipete
steipete merged commit e53c152 into main Sep 5, 2026
249 of 250 checks passed
@steipete
steipete deleted the codex/130706-extract-cron-20260905 branch September 5, 2026 21:35
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
…9374)

Resolve token-only scheduled usage against the selected agent directory and retain the prepared metadata scope through accounting, delivery, and cleanup. Close the existing lease once and fence detached borrowing after release.

Extracts the focused cron finalization repair from openclaw#130706. Production LOC net -8; verified worker-local pricing and model reload/control through a real Gateway and OpenAI inference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation 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: L 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