Skip to content

fix(cron): suppress control tokens and retain retry usage - #149697

Merged
steipete merged 8 commits into
mainfrom
codex/cron-session-results-land
Sep 16, 2026
Merged

steipete merged 8 commits into
mainfrom
codex/cron-session-results-land

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Current-session cron results could display control tokens, and an interim acknowledgement followed by a second model prompt could lose the first prompt's usage and cost.

User Impact

Scheduled reports use the same silent-reply handling as channel announcements, preserving media when its caption is suppressed. Run usage and estimated cost include both completed prompts; session context reflects the final request. No configuration or migration is required.

Why This Change Was Made

Normalize payloads before the conversation writer commits them. Retain completed prompts with their own usage, model, and timing for billing and diagnostics. Keep final context separate from aggregate billing, including context-only and unavailable-context results. Reuse the real usage predicate in tests and keep stale-delivery policy in its existing owner.

Current-main CI also required three bounded repairs. Goal edits now reuse the entry already validated in their transaction, preserving identity and certification checks; the unchanged read-count assertion reproduced the failure caused by #149537 and #149388. Two chat callbacks use equivalent void expressions to restore the existing file-length limit, with no visual behavior change. The planner fixture repair reuses the exact commit from #149726 so it accepts full test-file paths as well as extension roots.

Evidence

  • All 494 tests sharing the cron run harness passed; the final delivery/accounting run passed 207 tests. Context-only and persistent billing regressions fail before their fixes.
  • Full build and all five isolated Gateway flows passed at c2b2b7a00168f5ba00ad40c91f9be1828ff71194: leading control token, media with suppressed caption and exact downloaded bytes, silent-only result, ordinary text, and two-prompt accounting. The original Gateway probe reproduced the token leak before repair; fixture cleanup completed.
  • Accounting observed 40 input, 60 output, 10 cached and 110 total tokens, final context 37, and estimated cost $0.000165. The completed session generation retained both assistant messages.
  • Hosted live checks passed all ten cron allowlist cases across OpenClaw and Codex at e2151fee2abab22f4f357907b0f1b2bd2e0ed88a. Later changes only simplify the two UI callbacks and correct the CI fixture; the cron and harness inputs are unchanged.
  • The full local changed gate passed before the patch-identical main refresh. The Goal repair passed 38 related tests; the UI callback repair passed 21 existing tests. Scoped lint, formatting and diff checks passed.
  • Fresh independent Codex reviews are clean through P2 for the cron changes and all three CI repairs. The earlier completed ClawSweeper review found no actionable findings. Relevant cron docs are updated.
  • Required CI passed on the current head; GitHub reports no pending or failed checks.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 04:47
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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: blocked before merge. Reviewed September 16, 2026, 1:20 AM ET / 05:20 UTC (Revision 2).

ClawSweeper review

What this changes

This PR removes control tokens from scheduled conversation results while preserving media, counts both completed retry prompts with their respective prices, and avoids a redundant session read during Goal edits.

Merge readiness

⛔ Blocked before merge - 1 item remains

The fixes remain necessary on fetched main, and no actionable introduced defect was identified. The recorded Gateway proof remains relevant after verifying that all five changed cron production modules match the previously tested revision.

Priority: P2
Reviewed head: e2151fee2abab22f4f357907b0f1b2bd2e0ed88a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported repair with relevant Gateway observations and meaningful regression coverage; no blocking code finding was identified.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded isolated-Gateway CLI/RPC observations exercise the changed delivery and accounting owners, showing clean conversation text, preserved downloadable media, intentional silence, and combined retry usage with final context. All five cron production modules are byte-identical to that tested revision; the review did not rerun those flows.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded isolated-Gateway CLI/RPC observations exercise the changed delivery and accounting owners, showing clean conversation text, preserved downloadable media, intentional silence, and combined retry usage with final context. All five cron production modules are byte-identical to that tested revision; the review did not rerun those flows.
Evidence reviewed 11 items Introduced delivery repair: Current-session completion now uses the existing direct-delivery normalizer before the transcript writer. The normalizer removes control text while retaining payload metadata and media; existing generation, cancellation, and idempotency checks remain in the completion owner.
Accounting and context separation: Completed prompt results retain individual models and timing. Usage aggregation reuses the existing accumulator, pricing is evaluated per completed prompt, and finalization derives session context from final-request metadata. Tests cover mixed prices, unavailable prices, malformed totals, and persistent sessions with context-only results.
Goal mutation preserves transaction safeguards: The reused entry is read after assertCurrent inside the synchronous write transaction. Other identity keys, post-write identity reads, canonical writer validation, and receipt publication remain intact; the patch adds no schema or authority contract.
Findings None None.
Security None None.

How this fits together

OpenClaw's scheduler runs background agent prompts, records usage, and delivers completed reports into conversations or external channels. These changes normalize reports before transcript insertion and separate whole-run billing from the final request's context usage.

flowchart TD
  A[Scheduled job] --> B[Agent prompt]
  B --> C{Interim acknowledgement?}
  C -->|Yes| D[Continuation prompt]
  C -->|No| E[Usage and final result]
  D --> E
  E --> F[Aggregate billing and final context]
  E --> G[Normalize control tokens and preserve media]
  G --> H[Conversation and channel delivery]
Loading

Before merge

  • Resolve merge risk (P1) - The causes of two failed current-head checks remain unverified because their detailed log host was inaccessible to this reviewer.
Agent review details

Security

None.

PR surface

Source +92, Tests +216, Docs +2. Total +310 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 233 141 +92
Tests 3 283 67 +216
Docs 2 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 519 209 +310

Review metrics

Metric Value Why it matters
Production versus test growth Production +92 net lines; tests and test support +216 net lines Production growth retains per-prompt accounting facts; coverage exercises transcript content, media preservation, pricing, and final context.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one shared delivery normalizer and preserve per-prompt billing facts while persisting only the final request's context snapshot.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one shared delivery normalizer and preserve per-prompt billing facts while persisting only the final request's context snapshot.

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

Yes, source establishes both paths: current-session completion receives unnormalized payloads on fetched main, and interim retries replace the first prompt result before accounting. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Reusing the existing delivery normalizer and usage accumulator repairs the owning paths without adding competing policy, configuration, or storage formats.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs bounded scheduled-report and usage-accounting defects without introducing configuration or migration requirements.
  • 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): Recorded isolated-Gateway CLI/RPC observations exercise the changed delivery and accounting owners, showing clean conversation text, preserved downloadable media, intentional silence, and combined retry usage with final context. All five cron production modules are byte-identical to that tested revision; the review did not rerun those flows.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded isolated-Gateway CLI/RPC observations exercise the changed delivery and accounting owners, showing clean conversation text, preserved downloadable media, intentional silence, and combined retry usage with final context. All five cron production modules are byte-identical to that tested revision; the review did not rerun those flows.

Evidence

What I checked:

  • Introduced delivery repair: Current-session completion now uses the existing direct-delivery normalizer before the transcript writer. The normalizer removes control text while retaining payload metadata and media; existing generation, cancellation, and idempotency checks remain in the completion owner. (src/cron/isolated-agent/delivery-dispatch.ts:675, e2151fee2aba)
  • Accounting and context separation: Completed prompt results retain individual models and timing. Usage aggregation reuses the existing accumulator, pricing is evaluated per completed prompt, and finalization derives session context from final-request metadata. Tests cover mixed prices, unavailable prices, malformed totals, and persistent sessions with context-only results. (src/cron/isolated-agent/run-usage.ts:24, e2151fee2aba)
  • Goal mutation preserves transaction safeguards: The reused entry is read after assertCurrent inside the synchronous write transaction. Other identity keys, post-write identity reads, canonical writer validation, and receipt publication remain intact; the patch adds no schema or authority contract. (src/config/sessions/goals-operations.ts:337, e2151fee2aba)
  • Still necessary on fetched main: Comparison against fetched main shows that current-session payload normalization and completed-prompt retention are still absent there. The related merged session-read PRs do not implement the cron fixes. GitHub continues to report this PR open and unmerged. (src/cron/isolated-agent/run-executor.ts:1131, c9121962faf3)
  • Recorded real Gateway results: The supplied body snapshot, sourceRevision 9944fc65052158af63e04eb2be25ed0f4a1cb443bdd661322a057932b00a7b1c, records five isolated Gateway flows through CLI/public RPCs: leading-token cleanup, suppressed-caption media with matching downloaded bytes, silent-only output, ordinary text, and two-prompt accounting. It reports 40 input, 60 output, 10 cached tokens, final context 37, and estimated cost $0.000165 at f7b6ec34117acf15647e72a7f0e119a61cd4057b. These are contributor-recorded observations, not executions performed by this review. (f7b6ec34117a)
  • Proof continuity verified: GitHub's complete tree for the earlier tested revision and the local head have identical blobs for delivery-dispatch-policy.ts, delivery-dispatch.ts, run-executor.ts, run-finalize.ts, and run-usage.ts. The prior review retained no findings or published rank-up moves. The Goal repair was separately reviewed in this cycle. (src/cron/isolated-agent/run-usage.ts:1, e2151fee2aba)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • LiuwqGit: 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-16T04:54:40.683Z sha f7b6ec34117acf15647e72a7f0e119a61cd4057b :: needs maintainer review before merge. :: none

@steipete steipete changed the title fix(cron): clean scheduled replies and count retry usage fix(cron): suppress control tokens and retain retry usage Sep 16, 2026
Reuse the entry already read in the current write transaction when capturing
previous session identity. Preserve the other lookup keys, current authority
checks, post-write identity reads, and canonical certification.

This resolves the interaction between #149537 and #149388 without changing the
existing query budget. The unchanged test reproduces on their combined main
state; all 38 Goal, identity, and canonical-validation tests pass after repair.
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 16, 2026
@steipete
steipete force-pushed the codex/cron-session-results-land branch from f7b6ec3 to e2151fe Compare September 16, 2026 05:10
Keep the existing progress-dismiss and agent-change callbacks as explicit void expressions, preserving their undefined returns and side effects. This brings the renderer back within its existing max-lines limit after #149384 without changing UI behavior.
@openclaw-barnacle openclaw-barnacle Bot added the app: web-ui App: web-ui label Sep 16, 2026
@steipete
steipete merged commit 08584b3 into main Sep 16, 2026
207 checks passed
@steipete
steipete deleted the codex/cron-session-results-land branch September 16, 2026 05:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 16, 2026
Refresh against the canonical pre-write reuse from #149697 and retain
Vincent Koc's case-distinct Matrix sibling identity regression from #149722.
Management-only Goal mutations still preserve identity without taking
identity snapshots; shared writer certification and receipt atomicity stay.

The current-main64KiB fixture drops3 session-row SELECTs/132942bytes to
2 SELECTs/66771bytes. All23 focused owner/Gateway tests, scoped types,
typed lint, formatting and independent P2 review pass. These are local
database-read measurements, not production CPU or latency claims.

Co-authored-by: Vincent Koc <[email protected]>
steipete added a commit that referenced this pull request Sep 16, 2026
* chore(lint): make max-lines a warning

Peter decided on 2026-09-16 that max-lines should warn in CI rather than
block main. The chat-pane-render.ts failure exposed unnecessary lint
burden after #149697.

Change all six max-lines scopes to warn while preserving every threshold
and all other rules. Document warning behavior and the retained suppression
ratchet. The runners and CI already preserve warning output and exit codes.

Proof: check-changed, formatting, and git diff --check pass. The current
chat-pane-render.ts passes single-file core lint; the exact 702-line
revision from failed main run 35060497703 prints one max-lines warning and
exits 0 through run-oxlint with CI-style output. The sample UI tsconfig
command hit the existing nested-checkout declaration boundary, so proof
uses CI's source-only core tsconfig.

* test(lint): expect max-lines warnings

Align the existing config-policy test with Peter’s 2026-09-16 decision. Preserve all six budgets and exclusions. The prior PR run correctly exposed the stale error expectations.

Proof: all 13 oxlint config tests, check-changed, and git diff --check pass. Fresh independent review found no actionable P0/P1 findings.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…49697)

* fix(cron): normalize current-session completion payloads

* fix(cron): account for completed interim retry prompts

* fix(cron): preserve final context after retry accounting

* refactor(cron): centralize stale delivery policy

* fix(cron): clear stale billing after context-only retries

* fix(sessions): reuse the admitted entry during Goal edits

Reuse the entry already read in the current write transaction when capturing
previous session identity. Preserve the other lookup keys, current authority
checks, post-write identity reads, and canonical certification.

This resolves the interaction between openclaw#149537 and openclaw#149388 without changing the
existing query budget. The unchanged test reproduces on their combined main
state; all 38 Goal, identity, and canonical-validation tests pass after repair.

* refactor(ui): simplify chat pane callbacks

Keep the existing progress-dismiss and agent-change callbacks as explicit void expressions, preserving their undefined returns and side effects. This brings the renderer back within its existing max-lines limit after openclaw#149384 without changing UI behavior.

* fix(ci): accept file paths in extension packing fixtures
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
* chore(lint): make max-lines a warning

Peter decided on 2026-09-16 that max-lines should warn in CI rather than
block main. The chat-pane-render.ts failure exposed unnecessary lint
burden after openclaw#149697.

Change all six max-lines scopes to warn while preserving every threshold
and all other rules. Document warning behavior and the retained suppression
ratchet. The runners and CI already preserve warning output and exit codes.

Proof: check-changed, formatting, and git diff --check pass. The current
chat-pane-render.ts passes single-file core lint; the exact 702-line
revision from failed main run 35060497703 prints one max-lines warning and
exits 0 through run-oxlint with CI-style output. The sample UI tsconfig
command hit the existing nested-checkout declaration boundary, so proof
uses CI's source-only core tsconfig.

* test(lint): expect max-lines warnings

Align the existing config-policy test with Peter’s 2026-09-16 decision. Preserve all six budgets and exclusions. The prior PR run correctly exposed the stale error expectations.

Proof: all 13 oxlint config tests, check-changed, and git diff --check pass. Fresh independent review found no actionable P0/P1 findings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui 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