Repository navigation
perf(gateway): skip unchanged idle maintenance reads - #169894
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.
Cache empty recovery and OAuth inventories under their existing owners, retain secret and device expiry deadlines under committed write tokens, and reuse failed-delivery health counts until the database changes. Plan cron history maintenance inside its serialized worker and skip the write transaction when there is no recovery or pruning work. Keep active recovery, retention deadlines, credential effects, and lease-sensitive health reads live.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
…dlesql2-maintenance # Conflicts: # src/gateway/worker-environments/placement-turn-authority.ts
|
Codex review: needs changes before merge. What this changesThis PR caches unchanged maintenance inventories and expiry deadlines and skips Cron write transactions when no rows need changing. Example: An idle Gateway runs Cron history maintenance with no history requiring recovery or pruning.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it contains useful, maintainer-directed performance work absent from fetched main, and no new discrete introduced defect was established. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway timers call placement, OAuth, secret, device, health, and Cron owners, which consume committed-write publications and return recovery, cleanup, or diagnostic results. flowchart TD
A[Gateway timers] --> B[Maintenance owners]
C[Committed writes] --> D[Cache invalidation]
D --> B
E[Expiry deadlines] --> B
B --> F[Shared state workers]
F --> G[Recovery cleanup and health results]
Technical reviewBest possible solution: Land the existing-owner optimization after its declared validation is complete. Do we have a high-confidence way to reproduce the issue? Current-main source establishes repeated maintenance reads and unconditional Cron maintenance transactions; this read-only review ran no target code. Is this the best way to solve the issue? Receipt-based invalidation and explicit deadlines address redundant work at the existing owners while retaining active recovery and lease-sensitive pressure reads. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d6bcf79466f1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +250, Tests +204. Total +454 across 30 files. Added test files: 2. View PR surface stats
Review metrics
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 (3 earlier review cycles)
Reviewed October 12, 2026, 9:51 AM ET / 13:51 UTC (Revision 4). |
Reuse the generation-3 environment for the seeded startup placement's retry, preserving the orphan-cleanup admission assertion.
…idlesql2-maintenance
|
Reuse owner write receipts and expiry deadlines for maintenance caches. Keep active recovery, OAuth refresh, retention and live security checks. Skip no-op cron write transactions. Release-note context: reduce idle Gateway database work without configuration or schema changes.
What Problem This Solves
Idle Gateway timers repeatedly scan empty recovery/OAuth inventories, retained secret/device expiry state, and unchanged failed-delivery counts. Cron history maintenance also opens a write transaction when nothing changes, invalidating shared-state readers every minute.
User Impact
Idle Gateways issue fewer database requests while preserving active placement recovery, OAuth refresh, retention deadlines, delivery-pressure expiry, and cross-process liveness. No configuration or schema changes are required.
Why This Change Was Made
Keep the existing Gateway owners authoritative. Reuse their write receipts for empty placement recovery and personal OAuth inventories; use admitted physical-database write tokens for secret/device deadlines, hidden OAuth inventories, and failed-delivery counts. Actual queued work stays live. Cron computes its recovery/pruning plan in the existing serialized writer command and opens a transaction only when rows change.
Removed checks and accepted edges:
Secret deletion keeps the conditional creation-time predicate so a refreshed transient handoff is not deleted. Cron still checks retained active receipts and process liveness, preserves newly-lost retention, and prunes transactionally. Delivery pressure remains a live read because lease expiry can change without a write. Active OAuth records keep the existing refresh/expiry/recovery and effect checks.
Evidence
The isolated shared harness completed the workload, five-minute no-user-turn window, and clean shutdown. One baseline/candidate pair is used under the approved reduced-testing workflow; the first batch is shown separately for attribution.
Raw idle SQL falls 14.6% and requests 32.1% versus baseline; the ≤30 SQL/min and ≤15 requests/min aims are not met. The raw second-candidate window includes unchanged Workshop work that earlier runs completed before idle. All three runs execute exactly 134 synchronous Workshop transcript-anchor authority checks; 63 shifted into a 0.761-second burst at the start of this idle window. The experience-review owner, scheduler, and agent-end trigger sources are byte-identical across all measured revisions. This is phase drift, not added SQL. Subtracting only those 63 proven shifted statements would give 57.4 SQL/min; requests are not adjusted because their parent attribution is incomplete. These checks guard the review's current source/lifecycle/permission authority before effects and remain a separate async-owner follow-up. They are not silently removed from the raw table. No warmed MAIN increase occurs.
Health-related reads each ran six rather than five times in the last idle window; the placement inventory also includes one cleanup/retirement. These raw increases are disclosed as window-boundary/due-work differences, not claimed as removed polling. The shifted background review also performs writes and therefore legitimately invalidates caches. Active OAuth refresh, expiry/retention due work, cross-process liveness, pressure expiry, and WAL checkpoints remain. The final owner counts are observed rates, not promises that every idle cache stays empty.
Touched warmed operations (SQL/requests per turn, baseline→combined): placement recovery 1.8/0.3→0.6/0.1; cron history 1.2/0.3→0.1/0.1; secret expiry 0.8/0.2→0.2/0.1; hidden OAuth 0.5/0.4→0.2/0.2; device expiry 0.3/0.3→0.1/0.1; placement reads 0.3/0.3→0.1/0.1. Failed-delivery and the two ingress-health reads each fall from 0.3/0.3 to zero during warmed turns. No touched warm operation increases.
Shared read families per warm turn (baseline→combined): exact-entry facts 11.5→8.7; actor hydration 7.4→7.2; entry-cache snapshots 1.8→0.5; row-facts SQL 25.0→24.5; shared row-facts SQL 2.5→2.8; watermarks 6.0→5.9. The +0.3 shared-row-facts difference is disclosed and outweighed by −59.5 net SQL / −18 requests per warmed turn. It is recorded for follow-up.
Provenance: baseline
3e3a9a87e58b; first batch457339912ac0; combined44efea52e883plus the saved OAuth import and aggregate-null/fallback corrections. The private harness retained the shared observer and workload, adding a five-minute idle phase. Later integration, type/export/test corrections are not represented as an exact measured final head. Both earlier runs completed their runtime workloads but failed the wrapper's final all-RPC assertion on unavailablementions.dismiss; the combined run completed all RPCs successfully.Validation:
557c5893b51b: production types, all test-type stripes, lint, source/architecture guards including Madge, T1/worker and dialect ratchets, and all test shards passed.08005517; the unchanged node-reapproval test fails with the same 4001device-pairing-changedon main 38237812441 / job 114773019169. The shared startup-GC fixture is corrected in the first batch; its selected regression passed in 5.834s (350.68s wall time including the fresh worker build).f13b3cd209cd; no new lane-owned unused export remains. All three serial canonical Knip scans completed: production and full-tree reported only those inherited transcript/UI exports; the script scan passed with no findings. No lane-owned export finding remains.No schema, SDK, update, Doctor, plugin-loading, or service-lifecycle contract changes; no SDK diff or published-driver update cell applies. Release-note context: reduce unchanged idle-maintenance database work without configuration changes.
Integration head
557c5893b51b: merged the landed first batch (d43b88eb1bbd) into this branch with no production-code conflicts. The two test conflicts preserve the landed startup-recovery regression and the existing recovery-cache regression. Own diff against that main parent: 30 files, +786/−332 lines.The conflict-only integration passed changed-test formatting and type-aware lint; final-head CI confirms the integrated types, static checks and tests.