Skip to content

fix(sessions): keep usage totals visible during refresh - #157270

Merged
steipete merged 10 commits into
mainfrom
steipete/perf-micro-usage-stale-rollup-and-completion-event-20260919
Sep 24, 2026
Merged

steipete merged 10 commits into
mainfrom
steipete/perf-micro-usage-stale-rollup-and-completion-event-20260919

Conversation

@steipete

@steipete steipete commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session usage panels discarded committed totals while background rollups refreshed, then stopped their 5/10/20-second retries before long refreshes finished. The panel could stay empty until a manual refresh.

User Impact

Usage keeps the last committed totals visible during refresh, then updates when the background work completes. A failed refresh leaves a visible paused notice and an explicit Refresh action.

Why This Change Was Made

Keep compatible committed totals visible with computedAt, staleSince, and refreshing. Return usage: null with computing: true only when there is no usable committed rollup. The refresh operation publishes after its worker and accepted writes settle, reusing chat.metadata.changed with agentId, usageUpdatedAt, and a terminal failure flag. Its revision invalidates cached usage responses.

The Control UI rereads on successful publications instead of polling session totals. The Gateway sets the existing modelCatalogChanged and authChanged flags to false for usage receipts, reusing the current metadata owners. Its Gateway connection owns duplicate suppression and per-agent outcomes, including the last successful publication; disconnect retires them. Hidden and preloading pages catch up once. Failed refreshes retain totals and show a paused notice across automatic reads and navigation. Filter changes and another agent's success cannot acknowledge that failure; Refresh acknowledges only the affected receipts in its selected scope and retries immediately. New immutable receipts retire prior acknowledgments. Provider quota retries remain bounded and independent, and usage-only events do not invalidate Control UI model catalogs.

Net production TypeScript growth is 197 lines, above the 120-line guideline because terminal recovery needs agent ownership, preload ordering, and independent provider retry accounting. No configuration, schema, or durability changes.

Measurement

Behavior Before After
Read while rollup writer is held usage: null Previous 10-token total and freshness metadata
Session requests during 35 fake seconds of pending refresh 4 1 (75% fewer)
Duplicate completion notifications No completion-driven recovery One reread
Browser totals on completion Empty/stale panel Retained 100 tokens → 320 tokens
Failed refresh followed by focus/navigation or another agent's success Pause could disappear or affect the wrong scope Pause remains with the affected agent

Evidence

Head 71f8378af881 passed all selected proof and exact-head CI. The maintained widget-menu test synchronization from #157494 preserves @vincentkoc’s contributor credit and every original assertion. Independent review of this head found no actionable findings.

All heavy validation used blacksmith-testbox, profile openclaw-check, through installed Crabbox and the repository source-transfer wrapper. No local suites, builds, or typechecks ran. Results below are remote command exits; stopping a completed lease can mark its hosting Actions job cancelled.

  • Initial lease tbx_01m39hj4k2e5c0gswh8b5pm3br (runner): 66 backend tests, 60.81 s wall with one worker; 266 UI tests, 12.02 s wall; 62 observer/view checks, 5.22 s. Full changed gate passed in 29m47s.
  • Recovery lease tbx_01m39qmtmkqb9feszdymtpwj5b (runner): 53 backend tests, 74.66 s wall; focused UI checks and bundled Chromium recovery flow passed. Follow-up static gates passed on tbx_01m39srnvjpsn093r4j2pbtswt in 34m35s.
  • Final recovery lease tbx_01m39xexnzy38tb6x17hkke7mp (runner): Original-order baseline shard passed (20 files, 625.792 s). Final focused checks passed: 129 UI tests (11.15 s); 49 Gateway tests (54.71 s); eight real-worker tests (35.40 s); 70 Telegram destination/native-command tests (98.77 s); three durable webhook admission/ACK tests (49.83 s). Corrected preload owner file: 28 passed in 3.20 s. These are Vitest durations with --maxWorkers=1; the existing real-worker tests retain their SQLite/worker settlement boundary. The bundled Chromium rebuild/recovery scenario passed in 2.221 s test time / 25.41 s file duration. The selected changed-code gates are complete across this lease and the final lease below. The first 15 unchanged test type graphs were reused after a fixture-only correction; the remaining ten graphs, core/UI types, extension types, lint, dead exports, and runtime guards all passed without suppressions.
  • Final lease tbx_01m3a4fzbzp412cy1qyc495n9b (runner): targeted Telegram lint and extension-test types passed; the remaining native check-changed plan completed, including core/extension lint, style checks, schema and database guards, sidecar, webhook and pairing guards. Final All-agents browser proof passed on tbx_01m3a1hvdk1ck1j3k5tv078km4 (runner): 1.761 s test / 16.41 s file duration. Repetition results are recorded below.
  • Merged-base lease tbx_01m3aavefq8kj9fc79t40mn0x9 (runner): six original-code controls failed at their intended assertions; 49 Gateway tests passed (34.00 s), eight real-worker tests passed (21.61 s), 192 UI tests passed (11.15 s), bundled browser recovery passed (17.35 s file duration), and 12 Telegram tests passed (51.11 s). The changed-code gate then identified the five-line test-file overage repaired above. The lease is stopped; the final static pass uses a fresh lease for the new head.
  • Pre-test attempts on tbx_01m3ac5xcew39y7j2g595js009 and tbx_01m3ad606whftcmcdr9hnj9w95 stopped at the validation script’s commit-identity assertion: the wrapper deliberately uses a transport commit as HEAD. Both leases are stopped. The corrected script verifies canonical execution root and exact source tree; the receiver separately verifies the source commit. No test pass is claimed for those attempts.
  • Completed usage candidate 797f90b13719, lease tbx_01m3adeyjhbfjjnr7c0yrsmz5w (runner): the original-worker missing-transcript control failed at its intended zero-publication assertion (21.50 s file). The repaired worker passed all nine tests (35.47 s file; new regression 2.516 s), and both palette files plus the usage page passed 87 tests (8.95 s). node scripts/check-changed.mjs for all 34 changed paths passed, including all 25 core-test type graphs, UI/extension types, lint, dead exports, and runtime guards. The composite command completed in 44m38s, exit 0; its chat replays are described below. This lease is stopped. The subsequent head changes only the separately maintained widget fixture.
  • Final fixture lease tbx_01m3ag5ffaha5tv3vfg168wvj2 (runner): node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner --maxWorkers 3 --shard 8/8 reused the original 654-path selection under CI=true: 79 files / 375 tests passed in 505.02 s. The focused solo-widget-chrome.e2e.test.ts invocation passed all four tests in 21.47 s. node scripts/check-changed.mjs -- ui/src/e2e/solo-widget-chrome.e2e.test.ts passed, including its UI E2E type graph (61.3 s), localization, dead exports, and lint. Composite command 16m10s, exit 0. A preceding attempt stopped before tests because the script had not created its artifact directory; the corrected script passed on the same lease.
  • Independent Codex review: no actionable P0–P2 findings. git diff --check passes.

Negative controls against the original implementation establish the null response and four-request defects. Further controls establish failed-refresh recovery, provider retry resets, agent scoping, automatic acknowledgment, and missed preload catch-up. Deferred writer/request barriers and fake UI time avoid real sleeps.

CI on the preceding head exposed an unrelated Telegram fixture deadline: grammY's generic webhook wrapper timed out at 10 seconds during real /help initialization (11.999 s observed). Production acknowledges durable admission before dispatching bot.handleUpdate; the destination tests now use that same dispatch boundary. All routing, real-command, persistence, and reply assertions remain. The fixture keeps JSON serialization before direct dispatch: grammY requires an undefined-only reply field in its TypeScript type, while Telegram wire JSON omits it. The authored update is checked with satisfies Update before the fixture decodes the JSON request. The unchanged original shard passed on Testbox in 625.792 s, so the replay alone is not claimed as a fix. The repaired fixture passed 20 fresh-process standalone runs (978 s total; 37–63 s per file) and three exact original-shard runs (544 / 565 / 515 s), with unchanged CI worker settings and file order. The final lease command, including remaining static guards and this repetition, completed in 49m54s with exit 0. The file retains real command initialization, loopback delivery and persisted session/topic checks; a cheaper mocked helper would bypass those contracts.

CI on an intermediate head also failed chat.reset-visible-yield.test.ts: the requester reported yielded: true, aborted: true, then a successful replay lacked the yield field and its child continuation remained pending. Source review identified inconsistent classification as a plausible cause, but the producer cause is unproven; genuine abort/timeout guards remain unchanged. The bounded original-plan replay (129 files, both Gateway-methods configs, two workers) passed in 487 s, followed by the standalone file in 53 s. No chat source was changed and those passes are not claimed as a fix; the producer cause remains unproven.

The final usage candidate’s only failing CI lane was fullscreen-widget browser chrome: after reopening the Research menu, the fixture waited for a remove request that never arrived. The maintained test fix now adopted here has controlled real-pointer proof: pointer-down hits Remove, the opening animation moves the items, and pointer-up at the same coordinates hits another item, so no selection is dispatched. A fresh wa-after-show receipt stabilizes coordinates while retaining real pointer/keyboard actions, the 30-second CI deadline, and every target/frame assertion. Upstream’s controlled proof and this branch’s fresh 79-file / 375-test replay passed. No production widget behavior changed.

One browser attempt stopped before page creation because Playwright FFmpeg was absent; installing that test prerequisite resolved it. An isolated negative control also exposed a cold-import fixture race; it now awaits the actual request-start signal, and all negative controls fail at their intended assertions.

The screenshots below are inspected synthetic fixtures. Browser assertions cover failed refresh, manual recovery, retained totals, deduplicated completion, and unchanged model-catalog request count. No production deployment or live multi-minute refresh was performed.

Before: original empty response shape (synthetic fixture)

After: committed totals remain visible during refresh (synthetic fixture)

After completion: one event-driven reread displays fresh totals (synthetic fixture)

Recovery: failed cold refresh pauses visibly and leaves Refresh available (synthetic fixture)

Retain compatible committed rollups and publish completed usage revisions through chat metadata events. Replace session polling with publication-driven rereads, preserving provider quota retries.
@clawsweeper

clawsweeper Bot commented Sep 24, 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 app: web-ui App: web-ui gateway Gateway runtime size: L labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 4:11 PM ET / 20:11 UTC (Revision 6).

ClawSweeper review

What this changes

The branch keeps committed session-usage totals visible during refresh and updates the Control UI when the Gateway publishes a completed or failed rollup.

Merge readiness

✅ Ready for maintainer review

The usage defect remains on current main, so this PR is still a distinct candidate. The related widget-test repair has merged separately and does not replace the usage work.

Priority: P2
Reviewed head: 71f8378af881539d9afc8f5b4b14605681a60414

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Direct browser screenshots and worker-boundary checks support a coherent repair, with no actionable introduced defect found.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Chromium rendered the changed Usage page with synthetic Gateway responses and visibly retained 100 tokens, updated to 320 after publication, and showed failure recovery; the reported real SQLite-worker check separately exercised publication after write settlement. No stored-data contract changes were found, and a deployed Gateway-to-browser run was not shown.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): Chromium rendered the changed Usage page with synthetic Gateway responses and visibly retained 100 tokens, updated to 320 after publication, and showed failure recovery; the reported real SQLite-worker check separately exercised publication after write settlement. No stored-data contract changes were found, and a deployed Gateway-to-browser run was not shown.
Evidence reviewed 8 items Current-main behavior: Current main still uses bounded timed retries for incomplete usage and has no rollup completion publication in this owner.
Committed-rollup projection: The branch returns a compatible committed rollup with freshness fields while still marking its transcript for refresh.
Publication boundary: The refresh owner publishes after a changed worker result and publishes a failure receipt for non-aborted errors; the Gateway forwards these notices.
Findings None None.
Security None None.

How this fits together

The Gateway builds usage totals from session transcripts and serves them to clients. The Control UI displays those totals and responds to Gateway refresh notifications.

flowchart LR
  A[Session transcripts] --> B[Usage rollup worker]
  B --> C[Committed usage cache]
  B --> D[Gateway refresh notice]
  C --> E[Usage API response]
  D --> F[Control UI Usage page]
  E --> F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +197, Tests +399, Docs +1. Total +597 across 35 files.

View PR surface stats
Area Files Added Removed Net
Source 20 259 62 +197
Tests 14 751 352 +399
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 35 1012 415 +597

Review metrics

None.

Technical review

Best possible solution:

Keep the committed totals readable until authoritative new totals arrive, with a visible retry action when refresh fails.

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

Yes. Current main's bounded retry policy and non-publishing refresh owner give a clear source-level path; the PR reports negative controls, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Publishing from the refresh owner after worker settlement and keeping UI recovery scoped to each agent is a maintainable repair for the reported behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d5e6383f4802.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs misleading or stalled Usage-page totals while leaving an explicit manual recovery path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Chromium rendered the changed Usage page with synthetic Gateway responses and visibly retained 100 tokens, updated to 320 after publication, and showed failure recovery; the reported real SQLite-worker check separately exercised publication after write settlement. No stored-data contract changes were found, and a deployed Gateway-to-browser run was not shown.
  • proof: sufficient: Contributor real behavior proof is sufficient. Chromium rendered the changed Usage page with synthetic Gateway responses and visibly retained 100 tokens, updated to 320 after publication, and showed failure recovery; the reported real SQLite-worker check separately exercised publication after write settlement. No stored-data contract changes were found, and a deployed Gateway-to-browser run was not shown.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Chromium rendered the changed Usage page with synthetic Gateway responses and visibly retained 100 tokens, updated to 320 after publication, and showed failure recovery; the reported real SQLite-worker check separately exercised publication after write settlement. No stored-data contract changes were found, and a deployed Gateway-to-browser run was not shown.

Evidence

What I checked:

Likely related people:

  • steipete: 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 (5 earlier review cycles)
  • reviewed 2026-09-24T12:19:54.080Z sha 3f4a7c0 :: blocked before merge. :: [P2] Restore a terminal state when a refresh commits nothing | [P2] Preserve provider retry limits across usage publications
  • reviewed 2026-09-24T14:22:25.474Z sha c5fe3db :: blocked before merge. :: [P2] Keep a failed refresh paused on page activation | [P2] Scope failure receipts to the refreshed agent
  • reviewed 2026-09-24T17:59:21.009Z sha 12d7b04 :: blocked before merge. :: [P2] Preserve failed-refresh notices across filter changes
  • reviewed 2026-09-24T19:02:24.557Z sha 06a0b9e :: blocked before merge. :: [P2] Publish a terminal receipt when a queued refresh writes nothing
  • reviewed 2026-09-24T19:22:56.530Z sha 797f90b :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) September 24, 2026 12:21
@steipete
steipete disabled auto-merge September 24, 2026 12:44
…er retries

Publish refresh completion at its operation owner, including a terminal failure receipt when no rollup commits. Keep last totals visible, support manual recovery, and preserve provider retry accounting across publication-driven reads.
@steipete
steipete enabled auto-merge (squash) September 24, 2026 14:16
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 24, 2026
@steipete
steipete disabled auto-merge September 24, 2026 14:34
Keep failed refresh outcomes attached to the affected agent and preserve their paused notice across automatic reads and route preloads. Retain committed publication revisions so later failures cannot erase a pending catch-up read.

Exercise Telegram session destinations through the same bot dispatch boundary as durable ingress, removing the unrelated webhook deadline and an impossible JSON fixture field. Preserve the existing routing, command, topic persistence, and reply assertions.
Declare both synthetic agents before selecting All agents in the usage recovery browser proof. Type-check Telegram updates before JSON serialization so grammY reply types and the actual wire payload stay aligned without the test-only webhook deadline.
Keep Request JSON decoding before direct Telegram bot dispatch so typed reply fixtures retain the actual wire representation without a webhook deadline. Remove a redundant default type argument from the preload request barrier.
@steipete
steipete enabled auto-merge (squash) September 24, 2026 17:51
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: XL and removed size: L labels Sep 24, 2026
@steipete
steipete disabled auto-merge September 24, 2026 17:52
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 24, 2026
Integrate current main metadata change flags so usage publications preserve model catalog and auth facts. Keep failure acknowledgment on the explicit Refresh action, tied to immutable per-agent receipts; filter changes cannot dismiss another agent failure. Guard selected-agent receipt lookup against inherited object keys.
@openclaw-barnacle openclaw-barnacle Bot reopened this Sep 24, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 24, 2026
Apply the maintained fixture repair from 2019fd9 (#157494). Wait for each actual menu opening before choosing pointer coordinates, retaining the real input flow and every original assertion.

Co-authored-by: vincentkoc <[email protected]>
@steipete
steipete enabled auto-merge (squash) September 24, 2026 20:27
@steipete
steipete merged commit 9fb9896 into main Sep 24, 2026
237 checks passed
@steipete
steipete deleted the steipete/perf-micro-usage-stale-rollup-and-completion-event-20260919 branch September 24, 2026 20:27
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
)

Keep committed session usage totals visible during background refresh and reread them when chat.metadata.changed announces settled work. Scope refresh outcomes to their agent, retain successful publications through later failures, and preserve paused recovery across navigation and filter changes until explicit Refresh or a successful publication. Reject unavailable requested transcripts through the existing failure receipt, and keep provider quota retry budgets independent.

Use Telegram's production dispatch boundary in its session-destination fixture instead of a generic HTTP wrapper with an unrelated ten-second deadline. Preserve routing, real-command, topic persistence, and reply assertions.

Validated with original-code negative controls, real usage-worker and Gateway tests, Control UI tests and bundled browser proof, static gates, and Telegram fixture repetition on Blacksmith Testbox. No production deployment or live multi-minute refresh.

Adopt the maintained widget-menu fixture synchronization from openclaw#157494, retaining every original pointer, keyboard, target, and frame-preservation assertion.

Co-authored-by: vincentkoc <[email protected]>
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 channel: telegram Channel integration: telegram docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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