Skip to content

perf(cron): reuse list and status snapshots between mutations - #165629

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-cron-list-status-polling-20260919
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-cron-list-status-polling-20260919

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated cron.list and cron.status requests rebuild unchanged public job projections and aggregate scheduler status across concurrent Gateway clients.

User Impact

Automation lists and scheduler status reuse immutable snapshots while retaining the same JSON responses and current visibility checks. On the synthetic 200-job workload, full-list handler means fall from 4.418 to 0.486 ms without previews, and from 5.543 to 0.919 ms with default previews. No polling-cadence, configuration, or schema changes.

All Testbox p99s meet the <5 ms goal. Handler means meet <0.5 ms for full/no-preview, filtered, and status reads; compact (0.587 ms) and default-preview lists (0.919 ms) still miss. Full-dispatch means also remain above 0.5 ms for 200-job lists. Delivery previews stay fresh because they depend on session/configuration state beyond the cron revision.

Why This Change Was Made

Active cron reads already use resident state rather than loading SQLite on each request. Extend the existing read generation to own frozen status and requested rows, invalidated by committed store revisions, resident store replacement, and scheduler-local mutations. Preserve mutation ordering and passive-reader refresh behavior.

The Gateway keeps one full and one compact projection per service, keyed by the complete filtered/sorted list revision, page, and current default agent. It omits unset compact fields before freezing, preserving direct-RPC and serialized response shapes, and registers immutable arrays with the existing serializer. Visibility filtering and authority checks still run for each request; projections do not cache authorization. Register cron.status with the existing shared-response contract, with cron-event invalidation and the existing one-second ceiling.

Remove superseded list-snapshot state, duplicate enum admission checks, and redundant sharing-key wrappers. Runtime production LOC is net negative: +143/-148 (−5 lines). Remove the unused filter aliases after inlining their exact unions into the service options.

The Control UI already consumes cron events. The separate macOS open-menu polling follow-up is #165527; client cadence is outside this change.

Evidence

Blacksmith Testbox: provider blacksmith-testbox, profile openclaw-check, lease tbx_01m46a1a3dq9h18jp45n5dfqje (coral-shrimp-ed28). The inline crabbox run --id … --timing-json -- bash -c "$SCRIPT" proof verified checkout b25b8c7a63d6 plus the final two-file field-omission repair and SHA-256 hashes of all 14 candidate files, then completed successfully in 361.5 s. The comparison restores the original production implementation from 740ddaa458e3 for the before measurements.

The benchmark exercises the real Gateway dispatcher, cron handlers, started CronService, synthetic SQLite store, and actual frame serializer. Eight authenticated connections use identical sharing scope. Each cell measures 150 bursts / 1,200 requests after 10 warmup bursts. The table expires response sharing before each burst, while retaining the unchanged cron generation. Values are mean / p99 milliseconds; full dispatch includes admission and response encoding.

Request Handler before Handler after Full dispatch before Full dispatch after
Compact list (200 jobs) 0.690 / 1.061 0.587 / 2.734 0.844 / 1.256 0.875 / 3.365
Full list, previews disabled 4.418 / 6.179 0.486 / 2.257 4.633 / 8.104 0.673 / 3.565
Full list, default previews 5.543 / 9.948 0.919 / 2.632 5.780 / 10.478 1.099 / 2.809
Agent-filtered list (100/200 jobs) 0.451 / 0.966 0.195 / 0.303 0.555 / 1.333 0.331 / 0.771
Status 0.089 / 0.267 0.066 / 0.142 0.183 / 0.626 0.188 / 0.304

With response sharing already warm, candidate handler means are compact: 0.263 ms, full/no-preview: 0.320 ms, full/default-preview: 0.336 ms, filtered: 0.189 ms, status: 0.055 ms. Every complete normalized response matched before/after for all five shapes.

Focused tests: node scripts/run-vitest.mjs over the cron sort/status, read-operations, past-due, Gateway shared-response, list-snapshot, validation, scoped-list, agent-output-contract, and full server.cron.test.ts files: 333 passed, 174.73 s wall. The new Gateway snapshot regression fails against the original production implementation. An earlier Testbox run (tbx_01m461x0a85hna1wvwm34dx8gn, base 78e406060b56) ran the same two owner regressions against the original production code: both failed on missing freeze/reuse as expected (43.2 s, proof command exit 0), then restored the candidate. The candidate passes both, including mutation and scheduler-tick assertions.

Per-file cost, measured with pnpm test <file> --maxWorkers=1 on the same Testbox (wall time / single-run CI runner seconds):

File Tests Seconds
src/cron/service.list-page-sort-guards.test.ts 7 8.84
src/cron/service.read-ops-nonblocking.test.ts 16 10.04
src/gateway/server-methods/cron-list.snapshot.test.ts 1 9.01
src/agents/tools/cron-tool.output-contract.test.ts 5 10.18

The regressions cover stable frozen reuse, one new read generation after a real mutation, and correct next-run times after a scheduler tick following cached reads. Import/worker preparation dominates these file costs; no real timer sleeps were added.

Staged gate on the initial candidate (before the field-omission repair): all 24 non-deadcode checks passed on the authorized Linux rig, including production and test typechecks. The unused-export scan failed on unchanged base exports outside this PR: BranchSummaryResult, renderRootHelpText, stripEnvelopeFromMessage, and media-default re-exports. A pristine-base run of node --import tsx scripts/check-deadcode-exports.mts at 740ddaa458e3, with no tracked changes, reproduced exactly the same production/full-tree findings (exit 1). This is a recorded inherited failure, not a green full gate. The rig route was used after Testbox admission exceeded 20 minutes. Command: bash /srv/rig/rig-staged-check.sh lane493-cron-read 740ddaa458e3a6d931a03a323b6f853767227c0f, running node scripts/check-changed.mjs --staged against the exact staged patch.

Staged gate summary
1.66s  ok         conflict markers
   1.32s  ok         line-cap growth ratchet
  20.24s  ok         max-lines suppression ratchet
  45.24s  ok         assertion SAFETY comment ratchet
  13.01s  ok         SQLite worker ratchet
   4.99s  ok         test timeout race ratchet
  38.43s  ok         first-party mock export ratchet
   585ms  ok         changelog attributions
   449ms  ok         doctor deprecation registry
   549ms  ok         guarded extension wildcard re-exports
   475ms  ok         plugin-sdk wildcard re-exports
   806ms  ok         duplicate scan target coverage
   783ms  ok         dependency pin guard
   719ms  ok         format changed files
  11.51s  ok         config docs baseline
   5.32s  ok         plugin boundaries
  23.10s  ok         wrapper shadowing
   1.24s  ok         package patch guard
   865ms  ok         test temp creation report (warning-only)
 320.98s  ok         core tsgo graph boundary
 246.22s  ok         typecheck core
3478.05s  ok         typecheck core tests
  10.74s  ok         coercion helper declaration guard
  13.26s  ok         deprecated API usage
 119.02s  failed:1   dead export scan (skip with OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1)

Hosted CI found unset optional keys in direct compact responses and a test-only JSON round-trip flagged by lint. The producer now omits unset fields once before caching; the existing strict Gateway assertion is unchanged and passes. The unnecessary test round-trip is removed. Final targeted oxlint: 0 warnings, 0 errors, 17.2 s on the two repaired files. The final Testbox command exited 0 and the lease was stopped.

Hosted CI on f6f706c35e6b: the cron Node-test and core-lint failures from the first head are repaired. The remaining failure in run 37333010950 is android-test-play: ChatComposerLayoutTest.effortOpeningPreservesAlreadyAdmittedThinkingEffect timed out after 1,000 ms at ChatComposerLayoutTest.kt:3536 (1 failure among 3,566 Android tests). The unchanged Kotlin fixture mocks sessions.patch and does not execute the TypeScript cron Gateway. This PR changes no Android source; current main has no change to that fixture. The timeout has not been independently reproduced, so this is recorded as an unresolved, causally separate Android failure—not a confirmed fixed flake or a green CI run. No rerun, timeout increase, or weakened assertion was used.

Review: final whole-candidate isolated Codex review, including the field-omission repair, is scoped-clean with no actionable P0–P2 findings.

Limits: the synthetic jobs use delivery.mode=none; external delivery metadata I/O and production queue contention are not measured. Default successful-RPC journal logging omits calls below 50 ms, so a read-only caller sample cannot establish the full polling distribution or attribute a 40 ms production p99. No production Gateway or database changes were made.

Extend the cron owner's read generation to frozen status and job rows, and
reuse bounded Gateway projections with the existing serialized-array owner.
Share eligible status responses through the existing operator read contract.
Keep current visibility checks, passive refresh, and delivery previews fresh.

Remove duplicate enum admission checks and sharing-key wrappers so runtime
production LOC falls by 12 lines. Add mutation and scheduler-tick regressions.
Testbox: 316 focused tests pass; all five benchmark wire responses match.
At 200 jobs and 8 callers, full-list handler mean falls from 4.617 to 0.486 ms
without previews; default previews fall from 4.916 to 0.904 ms. All measured
p99s pass 5 ms; default-preview and full-dispatch list means remain above 0.5 ms.
@steipete
steipete marked this pull request as ready for review October 5, 2026 15:00
@clawsweeper

clawsweeper Bot commented Oct 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.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: f6f706c35e6b1e0b53510c839f2a038ec9a24ac0
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/methods/core-descriptors.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/methods/read-share-keys.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@steipete
steipete enabled auto-merge (squash) October 5, 2026 15:01
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 5, 2026
@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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 11:33 AM ET / 15:33 UTC (Revision 2).

ClawSweeper review

What this changes

Reuse immutable automation lists, scheduler status, and Gateway response projections between mutations while preserving response shapes and fresh delivery previews.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main lacks the proposed snapshot reuse. The prior compact-response finding is resolved, and no remaining introduced correctness or security defect was found.

Priority: P2
Reviewed head: f6f706c35e6b1e0b53510c839f2a038ec9a24ac0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with strong production-boundary measurements and a resolved prior finding is normal good-quality work.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied final Testbox transcript exercises the changed cron and projection owners through the real dispatcher and serializer, reports matching responses across five shapes, and measures reduced full-list work. Supplemental regressions cover mutation and scheduler-tick invalidation. No stored-data format changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied final Testbox transcript exercises the changed cron and projection owners through the real dispatcher and serializer, reports matching responses across five shapes, and measures reduced full-list work. Supplemental regressions cover mutation and scheduler-tick invalidation. No stored-data format changes are introduced.
Evidence reviewed 9 items Pinned introduction and clean checkout: Inspected the merge-base-to-head introduced changes across all 14 paths. The checkout is the original PR head and remains clean; endpoint drift was not treated as contributor changes.
Current main still needs this optimization: Current main constructs aggregate status on each read and retains the earlier list-only snapshot. Its Gateway projection module also constructs compact rows directly rather than retaining the new bounded projections. The supplied context identifies this PR as unmerged; no shipped implementation of this change was established.
Snapshot lifecycle and visibility: Read generation reuse requires both the committed store revision and resident jobs-array identity. Non-read-only locked operations invalidate that generation. List predicates still execute for each request, projection identity covers the complete filtered/sorted revision and default agent, and delivery previews remain outside the projection cache.
Findings None None.
Security None None.

How this fits together

The cron service schedules automations and supplies job lists and scheduler status to Gateway clients. The Gateway filters those reads for each caller, prepares public responses, and serializes them for delivery.

flowchart TD
  A[Gateway read request] --> B[Current caller authorization]
  B --> C[Cron read generation]
  D[Store commits and scheduler mutations] --> C
  C --> E[Visibility and page selection]
  E --> F[Immutable public projection]
  F --> G[Serialized response]
  H[Current session and configuration facts] --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -5, Tests +144, Docs +6. Total +145 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 8 143 148 -5
Tests 5 174 30 +144
Docs 1 8 2 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 325 180 +145

Review metrics

Metric Value Why it matters
Measured full-list handler cost 4.418 → 0.486 ms without previews; 5.543 → 0.919 ms with previews The supplied 200-job production-boundary benchmark demonstrates the central benefit while documenting remaining latency targets.

Technical review

Best possible solution:

Keep one mutation-invalidated cron read generation and bounded public projections, with request-local visibility checks and independently fresh delivery previews.

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

Not applicable as a bug reproduction: this is a performance optimization, supported by a supplied before/after dispatcher benchmark and source inspection.

Is this the best way to solve the issue?

Yes. Extending the existing read-generation and serialization owners avoids competing caches while preserving current visibility and preview contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded scheduler-read performance improvement with measured benefit and no demonstrated urgent user-facing outage.
  • 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 (terminal): The supplied final Testbox transcript exercises the changed cron and projection owners through the real dispatcher and serializer, reports matching responses across five shapes, and measures reduced full-list work. Supplemental regressions cover mutation and scheduler-tick invalidation. No stored-data format changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied final Testbox transcript exercises the changed cron and projection owners through the real dispatcher and serializer, reports matching responses across five shapes, and measures reduced full-list work. Supplemental regressions cover mutation and scheduler-tick invalidation. No stored-data format changes are introduced.

Evidence

What I checked:

  • Pinned introduction and clean checkout: Inspected the merge-base-to-head introduced changes across all 14 paths. The checkout is the original PR head and remains clean; endpoint drift was not treated as contributor changes. (f6f706c35e6b)
  • Current main still needs this optimization: Current main constructs aggregate status on each read and retains the earlier list-only snapshot. Its Gateway projection module also constructs compact rows directly rather than retaining the new bounded projections. The supplied context identifies this PR as unmerged; no shipped implementation of this change was established. (src/cron/service/ops-read.ts:37, fb84dd57fd57)
  • Snapshot lifecycle and visibility: Read generation reuse requires both the committed store revision and resident jobs-array identity. Non-read-only locked operations invalidate that generation. List predicates still execute for each request, projection identity covers the complete filtered/sorted revision and default agent, and delivery previews remain outside the projection cache. (src/cron/service/ops-read.ts:28, f6f706c35e6b)
  • Prior finding resolved at the producer: The current compact projection deletes only undefined properties before freezing. This preserves false, zero, and null values and addresses the earlier raw-response omission concern without weakening the direct-RPC assertion. The supplied final proof reports that assertion passing and removal of the test-only JSON round-trip. (src/gateway/server-methods/cron-list-projection.ts:80, f6f706c35e6b)
  • Security and response-sharing boundary: Status sharing reuses the existing operator identity key, which separates profiles, users, scopes, capabilities, and parameters and excludes synthetic and agent-authority callers. The dispatcher and shared-response owner revalidate each caller immediately before delivery; config, access, and session revisions fence reuse. This patch caches response facts without introducing transferable authorization. (src/gateway/methods/read-share-keys.ts:5, f6f706c35e6b)
  • Production-boundary performance proof: The captured PR body reports final candidate-file hash verification on Blacksmith Testbox and before/after measurements through the real Gateway dispatcher, cron handlers, started CronService, synthetic SQLite store, and frame serializer. Eight authenticated connections exercised five response shapes, with every normalized response matching. Full-list handler means improved from 4.418 to 0.486 ms without previews and from 5.543 to 0.919 ms with previews. Compact full-dispatch mean did not improve; external delivery I/O and production contention were explicitly outside the measurement. (f6f706c35e6b)

Likely related people:

  • Peter Steinberger: Raw commit 1d85663 adds src/gateway/methods/read-share-keys.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1d856637dc0d; files: src/gateway/methods/read-share-keys.ts)

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-10-05T15:13:20.472Z sha b25b8c7 :: needs changes before merge. :: [P3] Compare the compact response at the serialized boundary

Remove unset fields once before freezing cached compact projections so
direct RPC callers receive the same shape as serialized consumers. Keep
null, false, and zero values. Delete the test-only JSON round-trip now
that the producer preserves the direct response contract.

The existing strict Gateway projection test passes unchanged. Testbox
validated 333 focused tests, targeted lint with zero warnings/errors,
and identical before/after wire responses for all five benchmark shapes.
@steipete
steipete merged commit f45a1a1 into main Oct 5, 2026
137 of 141 checks passed
@steipete
steipete deleted the steipete/perf-micro-cron-list-status-polling-20260919 branch October 5, 2026 15:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…aw#165629)

* perf(cron): reuse list and status snapshots between mutations

Extend the cron owner's read generation to frozen status and job rows, and
reuse bounded Gateway projections with the existing serialized-array owner.
Share eligible status responses through the existing operator read contract.
Keep current visibility checks, passive refresh, and delivery previews fresh.

Remove duplicate enum admission checks and sharing-key wrappers so runtime
production LOC falls by 12 lines. Add mutation and scheduler-tick regressions.
Testbox: 316 focused tests pass; all five benchmark wire responses match.
At 200 jobs and 8 callers, full-list handler mean falls from 4.617 to 0.486 ms
without previews; default previews fall from 4.916 to 0.904 ms. All measured
p99s pass 5 ms; default-preview and full-dispatch list means remain above 0.5 ms.

* fix(cron): preserve compact response field omission

Remove unset fields once before freezing cached compact projections so
direct RPC callers receive the same shape as serialized consumers. Keep
null, false, and zero values. Delete the test-only JSON round-trip now
that the producer preserves the direct response contract.

The existing strict Gateway projection test passes unchanged. Testbox
validated 333 focused tests, targeted lint with zero warnings/errors,
and identical before/after wire responses for all five benchmark shapes.
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 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. security-sensitive-changed size: M 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