Repository navigation
perf(cron): reuse list and status snapshots between mutations - #165629
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 11:33 AM ET / 15:33 UTC (Revision 2). ClawSweeper reviewWhat this changesReuse 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 Review scores
Verification
How this fits togetherThe 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
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -5, Tests +144, Docs +6. Total +145 across 14 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
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.
…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.
What Problem This Solves
Repeated
cron.listandcron.statusrequests 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.statuswith 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, profileopenclaw-check, leasetbx_01m46a1a3dq9h18jp45n5dfqje(coral-shrimp-ed28). The inlinecrabbox run --id … --timing-json -- bash -c "$SCRIPT"proof verified checkoutb25b8c7a63d6plus 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 from740ddaa458e3for 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.
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.mjsover the cron sort/status, read-operations, past-due, Gateway shared-response, list-snapshot, validation, scoped-list, agent-output-contract, and fullserver.cron.test.tsfiles: 333 passed, 174.73 s wall. The new Gateway snapshot regression fails against the original production implementation. An earlier Testbox run (tbx_01m461x0a85hna1wvwm34dx8gn, base78e406060b56) 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=1on the same Testbox (wall time / single-run CI runner seconds):src/cron/service.list-page-sort-guards.test.tssrc/cron/service.read-ops-nonblocking.test.tssrc/gateway/server-methods/cron-list.snapshot.test.tssrc/agents/tools/cron-tool.output-contract.test.tsThe 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 ofnode --import tsx scripts/check-deadcode-exports.mtsat740ddaa458e3, 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, runningnode scripts/check-changed.mjs --stagedagainst the exact staged patch.Staged gate summary
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.effortOpeningPreservesAlreadyAdmittedThinkingEffecttimed out after 1,000 ms atChatComposerLayoutTest.kt:3536(1 failure among 3,566 Android tests). The unchanged Kotlin fixture mockssessions.patchand 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.