Repository navigation
perf(cron): speed up concurrent automation list requests - #158077
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 25, 2026, 9:08 AM ET / 13:08 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch caches sorted automation lists, resolves pending-chat automation names in a read worker, and updates handler and integration test fixtures. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 5 items remain Current main still repeats the cron-list sort and hash, and the reported registered-handler measurements support keeping this improvement. An introduced worker await still lets exact pending-message lookup return an input consumed during that wait; the branch also conflicts with main. Priority: P2 Review scores
Verification
How this fits togetherThe cron service reads SQLite-backed automation jobs and serves Gateway list and status requests. Gateway chat handlers use those jobs to label pending messages before returning history or exact-message replies. flowchart LR
A[SQLite automation jobs] --> B[Cron list snapshot]
B --> C[List and status replies]
A --> D[Name read worker]
E[Pending chat inputs] --> D
E --> F[Chat projection]
D --> F
F --> G[Chat replies]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +148, Tests +199. Total +347 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep the measured cron and name-lookup improvements while making exact-message replies reflect the pending-input owner's current custody state. Do we have a high-confidence way to reproduce the issue? Yes for the performance concern: the PR body supplies before-and-after registered-handler measurements. The pending-input race has a clear source path, but this review did not execute a delayed-consumption regression. Is this the best way to solve the issue? Not yet. Reusing the cron owner's snapshot and read worker fits the existing boundaries, but exact-message lookup must recheck pending-input custody after its new await. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d5d4952c5bca. LabelsLabel changes: No label changes. Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
ec66ba9 to
669e965
Compare
What Problem This Solves
Concurrent automation list requests repeatedly sort and hash the complete matching job inventory under the cron operation queue, delaying both
cron.listandcron.status. Pending chat inputs also resolve automation names separately for every message.User Impact
Automation lists and status return faster when callers share an unchanged inventory. Pending automation messages use the Gateway's selected cron partition, including renamed and deleted jobs. No configuration, storage schema, migration, or response-format changes.
Why This Change Was Made
Reuse one prepared filtered/sorted list and its existing content revision per started scheduler. Committed store revisions and service mutations invalidate it; visibility filters still run on every request, returned pages remain detached, and FIFO ordering stays intact. Passive/unstarted readers retain their existing reload and repair behavior. Status remains a count/wake summary and benefits from removing repeated hashing ahead of it in the queue.
Prepare pending-message automation names once per page in the existing read-only worker, using the already-selected partition. Exact-message reads revalidate session access after the await. Production growth is 148 lines. The fixture-only CI follow-up commits were removed during the rebase; the four model/config fixture files now exactly match main.
Rebase validation (2026-09-25)
Current head:
669e9650afc533afaf64ab31aadb3a1aafc2f8d4, rebased ontod5d4952c5bcabcf1470846c02d88bf04c66051d2(#158115).git range-diffconfirms the cron/chat/state performance commit is patch-identical. Dropped all four fixture-only follow-up commits: duplicate discovery/freshness repairs, config-RPC lifecycle diagnostics, and catalog-publication module preparation. No fixture resolution hunks were retained. This mechanical rebase does not change the production implementation or invalidate its existing review and benchmark evidence.Blacksmith Testbox
tbx_01m3cam37k8cshmeex3mhxzktg(blacksmith-testbox,openclaw-check; lease run):pnpm install --frozen-lockfilefollowed bynode scripts/check-changed.mjs: passed in 33m09s, including all 25 test type graphs, production types, formatting, lint (zero warnings/errors), dead-export scans, and selected storage/runtime/auth guards.node scripts/run-vitest.mjswith the 12 files below and--maxWorkers=1: all 101 tests passed across three shards; 3m25s command wall including runtime build preparation. All three models-list/connect integration files passed using main's versions.Exact-head CI run 36142723638 passed, including its
openclaw/ci-gate; 147 jobs completed with no failures (inapplicable jobs were skipped). GitHub reports the PR as mergeable.The lease is stopped. Auto-merge remains unchanged and disabled. No new benchmark was needed or run for the patch-identical rebase. Historical benchmark and CI investigation evidence follows; the fixture changes discussed there are no longer in this PR's diff.
Evidence
Original pre-rebase head
ec66ba9aa0f4: CI run 36136119577 passed, includingopenclaw/ci-gate. All Testbox leases are stopped. Squash auto-merge was requested but the installed CLI refused it withstring rewrite protection blocked unsafe input; the PR remains open with auto-merge disabled.CI run 36132845881 passed both repaired model-discovery shards, then hit a separate catalog-publication fixture timeout after Gateway setup consumed almost the entire test deadline. Investigation and the module-preparation correction are recorded below.
CI run 36129100405 exposed an incomplete synthetic model-provider fixture after merging a newer catalog-owner change from main. The fixture repair and before/after proof are recorded below. The original run hit an unlocalized config-test hook timeout; its investigation is also retained.
On Blacksmith Testbox
tbx_01m3bz86ykw97fszh960q5gm98(blacksmith-testbox,openclaw-check), the real registered handlers used 300 disabled SQLite-backed jobs with 4 KB synthetic payloads, compact 50-row list pages, and bursts of 20 concurrent callers (10 list + 10 status). Five warmup bursts preceded 50 measured bursts, giving 500 samples per handler.cron.listcron.statusThe baseline uses in-memory store revisions already; the measured redundant work was sorting and full-result serialization/hashing, not per-call store polling. Regression controls fail on the original production code: 10 full hashes instead of one per concurrent burst, and a 20-message pending page performs 20 cron-name plus 20 partition-selection queries on the main thread instead of zero. A separate baseline check also reproduced labels from the wrong partition. Pending-page proof also checks zero main-thread cron/config SQL, rename/delete freshness, and exact-message lookup. Both regressions were rerun against original production code on the lease and failed for the intended cost budgets; the final candidate passes both.
Nine focused runtime files passed in 60.34 s across three Vitest shards. All selected changed-file checks completed: production typechecking, 25 test-type graphs, formatting, lint, dead-export/storage/runtime/auth guards, and zero runtime import cycles. Targeted type/lint reruns corrected fixture omissions and test formatting. Independent Codex review found no actionable P0–P2 issues.
Current focused test command (all 12 files passed)
Measured single-file costs using
node scripts/run-vitest.mjs <file> --maxWorkers=1on the same Testbox:cron.list-scoped.test.tschat-pending-inputs.test.tsservice.list-page-sort-guards.test.tsThe first standalone run includes a 23.06 s shared worker compilation; subsequent runs reuse those outputs. The new handler case takes 0.69 s and the pending-input case 2.78 s. Per-file CI timing for these three primary files was not available through the published run artifacts or bounded shard mapping; the measured standalone Testbox costs are shown above. These exercise real SQLite/worker and registered-handler boundaries without launching a Gateway server or adding timer waits.
CI hook timeout investigation
Initial CI job failed in
server.config-patch.test.ts, caseopenclaw.changes.list preserves an approved include-only operation without a duplicate write: a 180 s lifecycle-hook timeout followed by the 300 s no-output watchdog (exit 143). The test step lasted 568.81 s; fail-fast canceled three other shards. No timeout, assertion, retry, or baseline was relaxed.On fresh Blacksmith Testbox
tbx_01m3c3jncm9hsx9bvyv5q3xwjz,OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs src/gateway/server.config-patch.test.tspassed all 81 cases in original order (119.64 s Vitest wall; the previously failing case took 3.19 s). An isolated run with--config test/vitest/vitest.gateway-server.config.tsand the exact test name also passed (70.39 s wall, including cold startup). Both were unmodified replays, not evidence of a timeout fix. They used the PR head in Testbox rather than the complete CI merge tree. Runtime build passed.The fixture disables cron and does not call the changed listing or pending-input handlers. Its config, reload, shutdown, model-runtime, and cleanup source matches the CI base. Related shutdown work in #158047 explicitly leaves this historical timeout's cause unproven; it is not incorporated or claimed as a repair here.
The follow-up adds only failure-time reporting of the last fixture lifecycle phase, allowing a recurrence to distinguish startup, client stop, Gateway close, watcher close, and isolated-state cleanup. On
tbx_01m3c4bee4k1mvghrmry37jyg5, all 81 cases passed again using the CI Vitest configuration (156.46 s wall), followed by the Gateway-server type graph (59.6 s), targeted lint (zero warnings/errors), formatting, and fresh independent review. All Testbox leases were stopped. The original hook timeout remains unlocalized.CI model discovery fixture repair
Second CI job failed in
models-list.discovery-lifecycle.integration.test.ts: after successful learning, a failed refresh returned no retained models. The CI merge base36def8be398bcorrectly requires successful discovery provenance before retaining account inventory. The synthetic provider emittedunavailableon HTTP failure but omittedreadyon HTTP success, so it never recorded that provenance.The fixture now reports the SDK's successful outcome, including successful empty results, and the selected auth profile on both success and failure. Production model behavior and every assertion remain unchanged.
On Blacksmith Testbox
tbx_01m3c5rs56m3t4bgrgd6y86vjj(blacksmith-testbox,openclaw-check; lease run),node scripts/run-vitest.mjs src/gateway/server-methods/models-list.discovery-lifecycle.integration.test.ts --maxWorkers=1ran twice against the exact catalog-owner file from the CI base. The original fixture failed at the exact CI assertion (88.65 s Vitest wall); the repaired fixture passed (43.65 s Vitest wall, 14.25 s test time; 46.14 s wrapper wall). This is a controlled owner-file substitution on the PR head, not a replay of the entire merge tree. The final CI lifecycle case passed in 23.57 s. The Gateway-other type graph, targeted lint (zero errors/warnings), formatting, and diff checks passed in a 93.69 s validation command. Fresh independent review found no actionable P0–P2 findings. The lease was stopped.CI freshness fixture repair
Third CI job failed three freshness cases: plain, getter-backed, and initially empty catalogs lost learned rows after a failed refresh. The strict builder returns a provider configuration; the enclosing synthetic catalog hook still needs to report its successful outcome. The fixture now emits that outcome in both return shapes without evaluating the one-read getter early. Related fixtures were inspected; none exercises this same missing-provenance failure path.
On Blacksmith Testbox
tbx_01m3c6rsy1ddckhd08zsbeq4hr(blacksmith-testbox,openclaw-check; lease run),node scripts/run-vitest.mjs src/gateway/server-methods/models-list.freshness.integration.test.ts --maxWorkers=1ran against the exact catalog-owner file from CI based43208fc55c7. The original fixture reproduced all three CI assertion failures (55.05 s Vitest wall); the repaired fixture passed all four cases (32.80 s Vitest wall, 15.77 s tests; 75.24 s wrapper wall including required runtime preparation). Assertions, timers, and production code are unchanged. Final CI passed all four freshness cases in 37.56 s combined reported test time. The Gateway-other type graph, targeted type-aware lint, formatting, and diff checks passed (73.86 s command). Independent review found no actionable P0–P2 findings. The lease was stopped.CI catalog-publication fixture startup
Fourth CI job timed out in
models-connect-publication.integration.test.ts. Phase diagnostics showed Gateway startup/connect consuming 58.63 s; the first assertion phase began at 59.03 s of the unchanged 60 s test budget. The catalog test and startup helpers match CI base488ce1e590dc; cron is disabled in this fixture.On Blacksmith Testbox
tbx_01m3c88jxfcg55j125cagyr44p(blacksmith-testbox,openclaw-check; lease run), the original 13-file shard withOPENCLAW_VITEST_MAX_WORKERS=8 node scripts/run-vitest.mjs <original 13 files>reproduced the timeout (249 passed, one failed; 137.59 s Vitest wall). Cold import tracing recorded 14.32 s ingateway.server-start-import. A subsequent trace-only replay passed all 250 cases with a 38.36 s target case; that passing replay does not prove a fix.The fixture now imports
server-startinbeforeAll. Only module preparation moves; real Gateway startup, isolated state, all assertions, and the 60 s behavior deadline stay in the test. A paired comparison used separate emptyOPENCLAW_VITEST_FS_MODULE_CACHE_PATHdirectories and the same 13 files/eight workers: both passed 250 cases, with the target case 52.87 s before and 50.36 s after (119.47/134.71 s whole-shard Vitest wall). This removes known module-loading work from the behavior budget; it is not a claim that all startup latency is fixed. Final CI passed the catalog-publication case in 36.29 s. Gateway-other types, type-aware lint, formatting, and diff checks passed (85.52 s validation command). Independent review found no actionable P0–P2 findings. The lease was stopped.Gap: this isolated fixture does not reproduce the production multi-second main-thread stalls or long writer holds. FIFO writer waiting is unchanged; this removes measurable repeated read work without claiming those separate stalls are fixed. No live Gateway was modified.