Skip to content

fix(gateway): expose live load and preserve public reads - #166387

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-live-session-state-gauge-20260919
Oct 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-live-session-state-gauge-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem and change

openclaw_session_state_total{state="processing"} is cumulative and can remain at 60 after every run finishes. Add five fixed-cardinality live series: running/queued sessions in openclaw_sessions_active, and admitted agent runs, active chat runs, and queued chat turns in openclaw_gateway_active_work. Preserve the existing counter name; its HELP text and Gateway metrics reference now explicitly describe cumulative observations, including repeated observations of a session.

Existing owners publish absolute counts after changes, using coalescing and lifecycle-bound subscriptions. Session counts match the full operator sessions.list active-only roster, including global/unknown sessions and default archive/cron-history exclusions. Work counts match createGatewayActiveWorkSnapshot(). Unavailable or retired sources remove samples, and projection stops without exporter demand. No polling timers, per-session labels, new configuration options, or schema changes. Categories overlap and are not the complete suspension-blocker inventory; zero alone does not establish suspend readiness.

The PR also fixes an anonymous public-reader race exposed by integration testing: pending sharing facts were treated as absent publications. Initial authorization and final HTTP authorization/response emission now consume the existing prepared-read owner synchronously. Revocation and representation-cache invalidation remain enforced.

Update the channel-status fixture to the current no-probe contract: inspection metadata supplies configuration/source fields, and recorded runtime supplies lastProbeAt. Remove its unused live summary hook and strengthen the WhatsApp configuration assertion to exactly false.

Rebased onto 96ccec4a1385. Upstream now supplies the complete commit-receipt and continuation-authority repairs and the CI fixture fixes encountered during validation. The redundant lane repair commits were dropped. Only the live metrics, public-reader readiness, and channel fixture changes remain; no upstream fixes were copied or cherry-picked.

Measurement

Synthetic persisted-state/API/exporter rig: 10,000 idle rows, 2 active rows, 20 transitions.

Observation Before After
Live load after drain No live series; cumulative processing remains 60 All five gauges return to zero; counter remains 60
Identities inspected by active selection 514 At most 2
Gauge refresh latency No live gauge 27.920 ms median; 161.540 ms maximum
Projection reads for 1,000 invalidations without an exporter Not applicable 0

These are bounded-work and freshness measurements, not a claimed wall-time speedup or production memory reduction.

Production/tooling delta with git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*': +452 (669 additions, 217 deletions). Growth implements the new live-metrics contract: owner notifications, replayable projection, exporter delivery, and indexed selection for session-list parity without idle-history scans. The public-reader fix adds 15 net lines to retain prepared authorization through response emission. Existing code moves to focused modules; there is no second activity registry or alternate fast path. The cumulative metric name and legacy public token URLs are retained public contracts.

Proof

All heavy validation ran remotely; Testbox provider blacksmith-testbox, profile openclaw-check. No local tests, builds, or typechecks.

  • The retained two production patches are identical by git range-diff to the previously reviewed and validated patches. On tbx_01m4avp5j96fxdkmsag4jvdx0r, the original ten-file CI shard passed 51/51 in 173.48s and eight focused files passed 163/163 in 342.87s. node scripts/check-changed.mjs --staged --timed passed all core/test/extension types, dead exports, lint, and schema/database/media guards. The lease ended with exit 255 after 1h1m38s, before the last runtime guards finished; all five unfinished guards passed against the same tree on tbx_01m4azkxkkgabnjh9jga593kbe in 1m56s. Runtime import cycles: 0. No gate was waived.
  • Public-reader negative control on tbx_01m4adfrhhkektfvdxcktjnb1c: original reader 7 pass / 1 fail, corrected reader 8/8. Another 27 HTTP/admission cases passed, covering concurrent readers, revocation, and cache staleness. The original predecessor-plus-X sequence reproduced the false 404; the corrected sequence passed 12/12 across five files.
  • The metrics patch passed 91 focused tests across nine files on tbx_01m4a0kcvc1358z30v4jv4k2zh. Full pnpm build passed on the authorized Linux rig in 26m24.5s while sharing the host with a gate; this is build proof, not an idle-host timing.
  • Later integration proof passed 395 cases / 45 files plus 58 focused cases / nine files on tbx_01m4b3rnjz44x5yxz2g097tp09. After the upstream UI fixture correction, tbx_01m4b74xvhgp65agjbkate657f passed 17/17 cases across five files, UI component types (62.80s), extension test types (107.52s), and core/extension lint. An initial extension-lint command used an incorrect tsconfig path; the corrected command passed with zero warnings/errors.

Test cost: cold pnpm test src/gateway/server-work-metrics.test.ts --maxWorkers=1 measured 60.55s wall / 5.978s test time on the rig; a later Testbox run measured 3.893s test time. The public-reader suite measured 32.62s wall, including its new 513ms regression; database-backed authorization across awaited history requires this boundary. The original exporter regression took 9ms.

Current-base proof on tbx_01m4bahafg5pgp5nz63gffqgww verified candidate tree d015da92479c1ead3fc1390753c502fb151f05a5 before execution. The original CI group passed 71/71 tests across 21 files in 263.66s; the repaired channel-status case passed in 33ms. node scripts/run-vitest.mjs passed 68/68 integration tests across eight files (217.94s + 16.39s + 4.41s), including metrics, active selection, public reads, continuation authority, and committed facts. node scripts/check-changed.mjs --base HEAD --timed -- src/gateway/server.channels.test.ts passed every planned check: Gateway server types 70.50s, dead exports 97.54s with zero entries, and lint 16.18s with zero warnings/errors. Combined remote command: 15m12s, exit 0. Fresh full-candidate review is clean at P0–P2. All task-owned leases are stopped.

CI is green on e02f3af37687: run 37636360689 completed successfully. Final PR check rollup: 106 passing, 48 skipped, zero failed or pending. The automated merge watcher subsequently merged the PR; no manual merge or auto-merge command was issued.

One unresolved observation remains: an initial sessions-read-active.test.ts invocation returned totalCount 3 instead of 4. Isolated candidate/original probes, original-order replay, and subsequent rebased runs pass. No cause was established; passing replays are not claimed as a fix.

@clawsweeper

clawsweeper Bot commented Oct 7, 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 gateway Gateway runtime agents Agent runtime and tooling extensions: diagnostics-prometheus size: XL labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Oct 7, 2026
@steipete
steipete enabled auto-merge (squash) October 7, 2026 02:10
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 10:32 AM ET / 14:32 UTC (Revision 9).

ClawSweeper review

What this changes

The PR adds live Gateway load gauges, narrows active-session selection, synchronizes anonymous publication reads before delivery, and updates a channel-status fixture.

Merge readiness

✅ Ready for maintainer review

The PR remains useful and has no identified blocking patch defect. Current main still lacks the live gauges and retains the public-reader race; the earlier migration-proof blocker does not apply to this narrowed diff.

Priority: P2
Reviewed head: e02f3af37687d001d0c2a253a5b0f91779d4f978

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, coherent implementation with strong production-boundary evidence and no supported blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured exact-tree Testbox evidence and persisted-state/API/exporter measurements exercise live-load drain and public-reader recovery. Inspected production HTTP coverage exercises both public URL forms, concurrent reads, conditional reuse, and rejection after revocation; direct reader coverage rejects reset and mismatched grants. Linked logs could not be independently downloaded, which does not invalidate the supplied evidence. No stored-data contract changes remain, so the earlier migration-proof request is cleared.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured exact-tree Testbox evidence and persisted-state/API/exporter measurements exercise live-load drain and public-reader recovery. Inspected production HTTP coverage exercises both public URL forms, concurrent reads, conditional reuse, and rejection after revocation; direct reader coverage rejects reset and mismatched grants. Linked logs could not be independently downloaded, which does not invalidate the supplied evidence. No stored-data contract changes remain, so the earlier migration-proof request is cleared.
Evidence reviewed 12 items Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduced hunks. The raw test-merge parents are the pinned base followed by the exact PR head; its result preserves the reviewed public-read and optional diagnostics changes.
Live metrics use existing owners: The projection uses the existing active-session selector and Gateway work snapshot, coalesces owner notifications, suspends preparation without exporter demand, and clears published samples during shutdown.
Authorization remains at final HTTP emission: Both public routes consume prepared sharing facts and synchronously check publication authority and representation freshness before emitting either content or a 304 response. Exact grant, agent, session generation, and physical database checks remain in the reader.
Findings None None.
Security None None.

How this fits together

Gateway run and session owners feed current activity into the Prometheus exporter for operator monitoring. Anonymous conversation requests use the session projection to check publication authority before returning transcript content.

flowchart TD
  A[Run and session owners] --> B[Live activity projection]
  B --> C[Prometheus exporter]
  D[Anonymous conversation request] --> E[Prepared sharing facts]
  E --> F[Current publication and cache checks]
  F --> G[Transcript response or refusal]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +450, Tests +520, Docs +46. Total +1016 across 40 files.

View PR surface stats
Area Files Added Removed Net
Source 27 667 217 +450
Tests 11 533 13 +520
Docs 2 46 0 +46
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 40 1246 230 +1016

Review metrics

Metric Value Why it matters
Monitoring contract 5 fixed live series; 0 configuration options Operators gain current-load measurements without per-session labels or settings migration.
Production versus test growth production +450; tests and support +520 net lines Production growth is justified in the body by owner notifications, bounded selection, lifecycle projection, and exporter delivery.

Technical review

Best possible solution:

Keep one owner-projected live-load view and consume current publication authority synchronously through final HTTP delivery while preserving existing counters and public URLs.

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

Yes: current-main source can mistake pending sharing facts for an absent publication after awaited history, and the added regression targets that exact invalidation. No local runtime reproduction was executed in this read-only review.

Is this the best way to solve the issue?

Yes: the patch reuses the existing activity, selection, prepared-read, and authorization owners without adding a competing registry or persistent format.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This improves operator load visibility and repairs an anonymous-read race with a bounded Gateway impact.
  • 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 (live_output): Captured exact-tree Testbox evidence and persisted-state/API/exporter measurements exercise live-load drain and public-reader recovery. Inspected production HTTP coverage exercises both public URL forms, concurrent reads, conditional reuse, and rejection after revocation; direct reader coverage rejects reset and mismatched grants. Linked logs could not be independently downloaded, which does not invalidate the supplied evidence. No stored-data contract changes remain, so the earlier migration-proof request is cleared.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured exact-tree Testbox evidence and persisted-state/API/exporter measurements exercise live-load drain and public-reader recovery. Inspected production HTTP coverage exercises both public URL forms, concurrent reads, conditional reuse, and rejection after revocation; direct reader coverage rejects reset and mismatched grants. Linked logs could not be independently downloaded, which does not invalidate the supplied evidence. No stored-data contract changes remain, so the earlier migration-proof request is cleared.

Evidence

What I checked:

  • Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduced hunks. The raw test-merge parents are the pinned base followed by the exact PR head; its result preserves the reviewed public-read and optional diagnostics changes. (a96113a01071)
  • Live metrics use existing owners: The projection uses the existing active-session selector and Gateway work snapshot, coalesces owner notifications, suspends preparation without exporter demand, and clears published samples during shutdown. (src/gateway/server-work-metrics.ts:47, e02f3af37687)
  • Authorization remains at final HTTP emission: Both public routes consume prepared sharing facts and synchronously check publication authority and representation freshness before emitting either content or a 304 response. Exact grant, agent, session generation, and physical database checks remain in the reader. (src/gateway/control-ui-public-session.ts:145, e02f3af37687)
  • Production HTTP boundary coverage: The inspected loopback scenario uses real publication, SQLite history, HTTP routing, and fetch clients: twenty readers receive content on each URL form, conditional requests return 304, and revoked publications return 404 without the transcript. Reader coverage also rejects mismatched grants and generations and revocation/reset during awaited history. (src/gateway/control-ui-public-session.concurrent.test.ts:17, e02f3af37687)
  • Exact-tree proof identity: The captured PR body, sourceRevision 6cede688bb57615d078ca61e06f9010d533e0d811e09a165c27f6f0452ef2666, reports persisted-state/API/exporter measurements, public-reader negative controls, HTTP/revocation coverage, and current-base integration results. Its tested candidate tree d015da92479c1ead3fc1390753c502fb151f05a5 exactly matches this checkout's tree. The reported five gauges drain to zero while the cumulative counter stays at 60. (e02f3af37687)
  • No persisted-format change: The introduced changes add process-local projection/subscription state and read synchronization, without DDL, stored-field changes, migrations, or configuration defaults. The diagnostics callback is optional and restricted to existing trusted exporter admission; its subscription is retained by the service capability lease. The earlier generic upgrade-proof request therefore has no remaining stored-data trigger. (src/plugins/service-diagnostics.ts:28, e02f3af37687)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: 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 (8 earlier review cycles)
  • reviewed 2026-10-07T02:09:37.225Z sha ee8e936 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T03:38:45.409Z sha 8840e0d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T06:27:08.309Z sha ecd730e368ce972784a9362c787ee6424ceb44b2 :: needs changes before merge. :: none
  • reviewed 2026-10-07T07:29:46.904Z sha 356c749 :: blocked before merge. :: none
  • reviewed 2026-10-07T07:57:57.743Z sha 4fcd558 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T09:15:07.616Z sha 981c8bc :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T11:00:14.727Z sha 8189998 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T13:43:35.545Z sha 84e959a :: blocked before merge. :: none

@steipete steipete changed the title fix(diagnostics): expose live session and run gauges fix(gateway): expose live work gauges and preserve pinned writes Oct 7, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 7, 2026
@steipete
steipete force-pushed the steipete/perf-micro-live-session-state-gauge-20260919 branch from ecd730e to 356c749 Compare October 7, 2026 07:22
@steipete steipete changed the title fix(gateway): expose live work gauges and preserve pinned writes fix(gateway): export live gauges and preserve state lifetimes Oct 7, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 7, 2026
@steipete
steipete force-pushed the steipete/perf-micro-live-session-state-gauge-20260919 branch from 356c749 to 4fcd558 Compare October 7, 2026 07:49
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Oct 7, 2026
@steipete steipete changed the title fix(gateway): export live gauges and preserve state lifetimes fix(gateway): export live load and reconcile public reads Oct 7, 2026
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Oct 7, 2026
@steipete
steipete force-pushed the steipete/perf-micro-live-session-state-gauge-20260919 branch 2 times, most recently from 8189998 to 84e959a Compare October 7, 2026 13:35
@steipete steipete changed the title fix(gateway): export live load and reconcile public reads fix(gateway): export live load and preserve session authority Oct 7, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Oct 7, 2026
@steipete
steipete force-pushed the steipete/perf-micro-live-session-state-gauge-20260919 branch from 84e959a to e02f3af Compare October 7, 2026 14:23
@steipete steipete changed the title fix(gateway): export live load and preserve session authority fix(gateway): expose live load and preserve public reads Oct 7, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 7, 2026
@steipete
steipete merged commit f277bdf into main Oct 7, 2026
164 of 165 checks passed
@steipete
steipete deleted the steipete/perf-micro-live-session-state-gauge-20260919 branch October 7, 2026 14:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…6387)

* fix(diagnostics): expose live session and run gauges

* fix(gateway): reconcile public reads before delivery

* test(gateway): align channel status fixture with inspection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: diagnostics-prometheus gateway Gateway runtime 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: 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