Repository navigation
fix(cron): avoid loading off-page history payloads - #174175
Conversation
Scan selection metadata in indexed keyset batches and hydrate only the requested history page through the existing read worker. Preserve public completion ordering, exact totals, search, notification links and live session-disclosure checks. Summary reads omit diagnostics and delivery traces before crossing the database driver. Synthetic 7,312-run proof preserves every tested response while reducing all-job summary database values from 290 MB to 2.67 MB. Metadata batching adds statements and page hydration adds one request; this is a payload reduction, with no warmed-turn SQL-saving claim. Concurrent deletion may shorten a page and captured-name search may lag renaming until refresh.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR selects cron history using lightweight metadata and loads response payloads only for the requested page. Example: Request a two-entry summary page from 520 diagnostic-heavy runs.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a concrete history-read payload problem that remains on current main, and the reviewed diff introduces no definite correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherCron history RPCs read retained task_runs through the existing SQLite worker, apply caller visibility and pagination, and return history pages or transcript bindings. flowchart TD
A[History RPC request] --> B[Current job and visibility facts]
B --> C[Worker metadata scan]
C --> D[History page selection]
D --> E[Worker page hydration]
E --> F[Final authority and visibility checks]
F --> G[History response]
Technical reviewBest possible solution: Land the existing-worker metadata selection and page hydration approach after the failing checks are resolved or conclusively attributed upstream. Do we have a high-confidence way to reproduce the issue? Current-main source loads full detail_json for matching cron rows before pagination; the author also supplies synthetic before/after database-cell measurements, but this review ran no target code. Is this the best way to solve the issue? The approach preserves the existing completion-order and visibility owners, avoids a schema change, and explicitly accounts for the added query cost. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9afcbdfea3cc. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +289, Tests +362, Docs +10. Total +661 across 13 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 16, 2026, 7:54 AM ET / 11:54 UTC. |
|
Merged via squash.
|
* fix(cron): avoid loading off-page history payloads Scan selection metadata in indexed keyset batches and hydrate only the requested history page through the existing read worker. Preserve public completion ordering, exact totals, search, notification links and live session-disclosure checks. Summary reads omit diagnostics and delivery traces before crossing the database driver. Synthetic 7,312-run proof preserves every tested response while reducing all-job summary database values from 290 MB to 2.67 MB. Metadata batching adds statements and page hydration adds one request; this is a payload reduction, with no warmed-turn SQL-saving claim. Concurrent deletion may shorten a page and captured-name search may lag renaming until refresh. * fix(cron): preserve worker history type narrowing
What Problem This Solves
Cron history loaded every matching run's full retained JSON before paging, so a small summary page could read tens of megabytes of diagnostics, delivery traces, and recovery state.
User Impact
History pages load response details only for the selected runs. Completion ordering, offsets, exact totals, search, notification links, and session visibility retain their existing semantics. Summary reads omit diagnostics and delivery traces at the SQL boundary.
Why This Change Was Made
The existing indexes order by
(created_at, task_id), but public history orders by completion time and uses locale-aware identity ties. Changing the public order or introducing a schema migration would be a larger contract change. The reader therefore scans only selection metadata in bounded, indexed keyset batches, selects the page with the existing codec, and hydrates its IDs with a bounded SQL query. Diagnostic search evaluates one batch at a time and retains match identities rather than diagnostic payloads. Exact totals still require a metadata scan; this is a payload reduction, not constant-time pagination.The existing read worker owns all SQL. The former full-history asynchronous read is removed; the full-record kernel remains only for write, recovery, and retention responsibilities that need those facts. Shared engine JSON projection helpers and tuple comparisons keep new SQL portable.
Disclosure authority and session visibility are checked after hydration. Ordinary concurrent removal can shorten a page until refresh, and concurrent job renaming can leave search matches based on the captured name until refresh. Neither requires a generation or retry handshake.
Removed checks and accepted edges:
scope_kind,notify_policy,delivery_status, orterminal_outcomeenums: malformed unused bookkeeping fields no longer reject an otherwise readable history entry.statusenum: the existing timestamp normalization and public history codec consume the stored facts; write/recovery admission retains its validation.The live caller/session disclosure check remains because it protects a security boundary.
Evidence
M1,C1,M2,C2,M3,C3), each passing 14 turns, cron, compaction, restart and both shutdowns. Base594e35ed589d, measured candidate0c9ff57d5bd; pinned Node 24.22.0 / SQLite 3.54.0, unchanged harness, compile cache disabled. Final-head reuse is explained below. No warmed-turn or latency improvement is claimed.38897832754passes the changed tests, types, lint, source contracts, Madge, T1 and dialect gates. The repository Knip export scan has zero production or script findings. Its two full-tree UI test-helper findings (proofCaptureandrenderActivityGroup) reproduce exactly on the tested main parentc489e8ce0a85; no findings are introduced, and both are already tracked for repair.Payload and query evidence
The table reports logical database-cell bytes returned by the driver, not physical disk I/O. Response bytes exclude the RPC envelope and are identical before/after. Base:
594e35ed589d1441bc3d4d1304c8aae9bd09a55f.All-job summary pages return 99.08% fewer database bytes; largest-job summary pages return 98.99% fewer. The added SQL is explicit: 15/five indexed metadata batches, two snapshot statements, and one hydration query. Hydration adds one worker request for a nonempty page; the Gateway harness confirms that cost. This is a payload reduction with a statement/request tradeoff, not a warmed-turn SQL-saving claim.
EXPLAIN uses the existing runtime/source
(created_at, task_id)range indexes and the task-ID primary key for hydration. No OFFSET or temporary ordering B-tree is used. Exact totals and completion sorting still require all matching metadata; deep offsets do not add work.All five search scenarios retain their diagnostic/delivery matching semantics, reduce database bytes by about 63.1%, and increase median measured CPU by 6.2–19.8% on this fixture. Ordinary pages and single-run reads use less measured CPU. Search remains the deliberate CPU tradeoff for bounded retained payloads.
Native query elapsed observations (three alternating samples, median [min–max] ms) were: all-first summary 536 [523–657] → 1,388 [996–1,964]; all-deep summary 509 [446–555] → 1,081 [881–1,543]; largest-job first summary 39 [38–50] → 142 [112–153]; largest-job deep summary 59 [54–74] → 191 [136–213]; single full run 94 [48–140] → 165 [101–186]. These are noisy observations from a loaded host (load approximately 82 on 32 CPUs), not latency or speedup evidence. A quiet remote allocation queued and was canceled without running a payload.
LOC: 13 files, +809/−146 overall; production TypeScript +396/−105 (net +291). The added code owns bounded metadata selection and page-only hydration; it replaces the full-history async reader. All six Gateway harness arms are complete; counts follow below.
CI correction:
31224243e9bfixes two TypeScript narrowing errors found on the first CI run. It validates the captured job-name map once and annotates a synthetic tuple as readonly; formatting and type-aware lint pass. The harness remains pinned to0c9ff57d5bd, whose accepted-input SQL and dispatch path is unchanged by the correction. The first run also found an inheritedsrc/media/media-facts.tsassertion allowance mismatch (14 actual versus 16 allowed), independently reproduced on its main base; the final-head CI is now green after main corrected that allowance. No CI bypass is needed.Final-head CI tested merge
4468b83bfd81edffdafdecda09f771fb3741f614(mainc489e8ce0a851563b61bbd806adc5e4c5063036bplus PR31224243e9bd5f073cd6096f6cd997e74a026c4c). Global T1 remains 222 → 222; all changed dialect groups remain 0 → 0.Final Gateway measurements
Values are median [min–max], SQL / requests / MAIN. Warm rows pool 30 turns per side; other rows summarize three complete runs per side. Fixture setup is excluded.
Each pair has causal warm medians of 72 SQL / 25 requests / 0 MAIN on both sides. Per-arm whole-workload totals:
Normalized history operation cost on the small harness fixture: an empty page changes from 1 → 3 SQL / 1 → 1 request; a nonempty page changes from 1 → 4 SQL / 1 → 2 requests. MAIN stays zero. Poll counts vary with completion timing; matched pair two uses three polls
[0, 0, 1]and changes from 3 SQL / 3 requests to 10 SQL / 4 requests. No history operation runs inside the warmed chat windows.Whole-workload medians rise by 28 SQL (+0.68%) and five requests (+0.46%), with unchanged MAIN. The bounded history reads intentionally add queries and one nonempty-page request. Restart-combined SQL rises by 35 at the median: an unchanged session-transcript projection publication operation contributes 34 statements in M1 and all three candidate runs, but not M2/M3. The trigger correlation is unresolved; this increase is disclosed, not classified as noise or attributed to a saving. Raw warm MAIN comes from existing background work; causal warm MAIN is zero throughout.
All six warmed shared-read-family histograms match: exact-entry facts, actor hydration, full entry-cache snapshots, row database facts and dedicated watermarks are zero; exact-entry candidate reads are 0.2 per turn, qualified session-node reads two per turn, and combined transcript-context reads one per turn. These owner-frame categories can overlap and are not summed. Native causal SELECT/WITH histograms match exactly within pairs two and three; pair one adds one auth-profile read across ten candidate turns. Family-specific request counts are not inferred from SQL frames.
Merged as
afe03ab7249237d27a09f53605cca3907e442ab9. The landed patch exactly matches the reviewed final head. Native merge initially refused on a pending rollup projection despite green checks; a fresh native retry succeeded without REST fallback or CI bypass.