Repository navigation
perf(gateway): avoid database polling in idle Gateways - #169871
Conversation
Reuse owner-published placement and publication facts, and schedule session registry retention from known deadlines. Preserve active work, startup recovery, and effect authority while dropping redundant idle reads.
|
🦞👀 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 changes before merge. What this changesThis PR replaces unchanged idle database scans with committed-write wakeups, retained placement inventories, and retention deadlines. Example: A Gateway has no cron-run sessions or pending GitHub publications.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep this PR open: the measured optimization is useful, but the changed startup-cleanup regression still fails after the previous fixture fix. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway maintenance consumes SQLite owner snapshots and committed-write receipts to schedule retention, worker housekeeping, disk probes, and publication recovery. flowchart TD
A[Committed SQLite writes] --> B[Owner receipts]
B --> C[Maintenance scheduling]
D[Retention deadlines] --> C
C --> E[Worker inventory and recovery]
C --> F[Session retention]
C --> G[Publication recovery]
Technical reviewBest possible solution: Retain the receipt-driven scheduling while restoring passing startup-cleanup coverage without weakening its eventual-deletion assertion. Do we have a high-confidence way to reproduce the issue? Current-main source confirms repeated maintenance reads, and the supplied comparative Gateway results measure their cost; this read-only review executed no target code. Is this the best way to solve the issue? Reusing existing owner receipts and deadlines fits the problem and preserves the existing persistence owners, but the changed cleanup scenario must pass before merge. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 28df9fe159fc. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +188, Tests +255, Docs +2. Total +445 across 19 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
Reviewed October 12, 2026, 9:46 AM ET / 13:46 UTC (Revision 5). |
Reuse the generation-3 environment for the seeded startup placement's retry, preserving the orphan-cleanup admission assertion.
|
Landed with the corrected startup-orphan regression passing. Follow-up from review: extend the publication retry tests to assert observable reporting outcomes alongside mock-call counts. This is separate test-quality work; the retained failure/retry paths are unchanged. |
Reuse owner-held placement and publication inventories, and wake session retention from deadlines and committed receipts. Delete redundant synchronous placement reads while preserving recovery, active retention, and effect authority. Idle live pair: 82.0 to 58.6 statements/min and 39.2 to 24.4 requests/min; idle MAIN SQL 1.4 to zero. Includes focused startup-orphan regression and recorded static/inherited CI evidence. Release-note context: reduce idle Gateway database work without configuration changes.
Upstream provenance: PR openclaw#169871, relevant upstream commit d43b88e; PR openclaw#171320, relevant upstream commit 17e87b0; adapted, not cherry-picked. Adaptation: retain 10.5 startup discovery, recovery, expiry, lease, heartbeat, active-job protection, retry, and clock behavior while parking empty maintenance and waking from post-commit history/session invalidations. Added deadline calculation and fresh-facts retry handling; no schema or public API changes. Regression coverage: maintenance lifecycle, retained session expiry, async invalidation, run-history, oxlint, oxfmt, and guarded tsgo:core. Direct tsc was separately resource-capped at 6G and could not complete. Rollback: revert this commit only.
What Problem This Solves
An idle Gateway repeatedly queries unchanged placement, session-retention, and GitHub-publication state. These sweeps also inflate per-turn SQL counts when a turn overlaps a timer.
User Impact
Idle Gateways do less database work while preserving startup recovery, session retention, active placement maintenance, publication retries, and personal-publication confirmation. No configuration, schema, or migration changes are required.
Why This Change Was Made
Reuse the placement owner's receipt-invalidated maintenance inventory for disk checks, skip environment pruning when its resident inventory is empty, and finish orphan-ref cleanup against the startup inventory it already owns. Session registry maintenance now sleeps until the earliest expiry or a relevant committed session/topology change. GitHub publication recovery sleeps after an empty scan and resumes from its existing exact write receipts.
Removed checks and accepted edges:
Cron run-history recovery keeps its minute cadence. Protected expired sessions, unreadable stores, failed sweeps, active environments, pending publications, unreported outcomes, and failed transcript reporting continue retrying. All real effect and retention guards remain.
Evidence
One isolated shared-harness live pair on baseline
3e3a9a87e58band this batch's production commit457339912ac0:Idle SQL falls 28.5%; requests fall 37.8%. The removed idle MAIN statements were startup orphan-cleanup workspace resolution.
Shared read families per warm turn (baseline→this batch→combined follow-up #169894): exact-entry facts 11.5→11.7→8.7; actor hydration 7.4→7.1→7.2; entry-cache snapshots 1.8→1.6→0.5; row-facts SQL 25.0→23.5→24.5; shared row-facts SQL 2.5→2.2→2.8; watermarks 6.0→5.7→5.9. The first pair's four extra single-entry reads against two fewer broker reads did not recur in the combined run. The combined follow-up reduces warmed medians to 404 SQL / 95 requests, with zero warm MAIN. The small +0.3 shared-row-facts difference versus baseline is disclosed and outweighed by the net −59.5 SQL / −18 requests per warm turn.
All runs completed 13 turns, child completion, cron, compaction, five-minute idle, and clean shutdown. The first two wrappers failed only their final all-RPC assertion because
mentions.dismissreturned UNAVAILABLE; their runtime workload and census completed. The combined run completed with all RPCs successful. That run used44efea52e883plus the saved required OAuth import and aggregate/fallback normalization corrections; later changes were type/export/test fixes and integrated upstream placement ownership. It is not represented as an exact final-head benchmark.Validation:
placements.getsites are deleted, with no fallback.19cd255fa6b7through merge09044762a696onto main418aa6a54a07. Lint, source contracts, architecture/Madge, worker and dialect ratchets passed. Four type jobs fail at the unchanged updater's number/bigint snapshot identity mismatch (update-command-migrate.ts:211); the incompatible caller and type owner exist on that exact main.This changes scheduling, not update, Doctor, schema, plugin loading, SDK, or service lifecycle; no update cell or SDK diff applies. The public behavior/release-note context is reduced idle database work without configuration changes.
Follow-up: publication tests could assert observable retry/reporting outcomes in addition to their mock counts; this is advisory test-quality work, not a product regression.
Final test-only correction:
4deba4b49f77(+4/−1). It uses normal reclamation before asserting GC; the failed prior assertion is not presented as passing. Required static proof above is unchanged by this fixture-only correction.Final own-scope diff versus integrated main parent
08005517c47b: 19 files, +536/−88 lines (production8 files +229/−41; tests/support/manifest10 files +305/−47; docs1 file +2/−0).