Repository navigation
perf(bay): serve the Bay projection from a TTL memo and edge cache - #1388
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed September 3, 2026, 9:09 PM ET / September 4, 2026, 01:09 UTC. ClawSweeper reviewWhat this changesThis PR changes Bay lifecycle snapshot caching to a 30-second Durable Object TTL memo plus stale-while-refresh edge caching, simplifies cold projection parsing, and updates docs and tests. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 5 items remain Keep open: the stale-while-refresh implementation can replace a valid stale Bay snapshot with an unavailable result after a transient queue failure, and the current-head proof does not meet the repository’s required Crabbox runtime contract. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw Bay is the public observer-only dashboard surface. Its Worker route obtains sanitized lifecycle aggregates from the Exact Review Queue Durable Object and returns them to dashboard polls. flowchart LR
A[Dashboard poll] --> B[Bay Worker route]
B --> C[Fresh edge cache]
C --> D[Stale edge cache]
B --> E[Queue Durable Object]
E --> F[Lifecycle projection snapshot]
F --> B
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain stale verified snapshots when refresh returns unavailable or malformed data, add focused failure-path coverage, then publish a redacted current-head Crabbox trace proving fresh-hit, stale-refresh, and maximum-age behavior. Do we have a high-confidence way to reproduce the issue? Yes: source inspection shows that a stale hit starts a background refresh whose unavailable result is unconditionally stored in both cache buckets, displacing the valid stale response. Is this the best way to solve the issue? No: TTL memoization and stale-while-refresh are suitable here, but refresh failure must preserve the last verified stale snapshot until its existing maximum-age limit. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 72041f31e1d3. LabelsLabel changes:
Label justifications:
EvidenceWhat 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 (1 earlier review cycle)
|
9e8d953 to
538a4c1
Compare
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: perf(bay): serve the Bay projection from a TTL memo and edge cache This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
Bay's projection memo was effectively disabled under sustained writes, contributing to the overload tracked in #1372. This follows #1385.
Changes
The object memo is TTL-only, with a 30-second default and explicit production value of
30000ms. Queue/lifecycle writes preserve it; concurrent readers of the same normalized scope share one computation. Disabling the memo fences off pending work. Stats retain their separate write-invalidation behavior.The outer route caches sanitized responses for 30 seconds, then serves stale data while coalescing a background refresh per origin/scope per isolate. Both buckets honor the snapshot's original 60-second maximum age without renewing
generated_at.Cold builds now stream full
projection_jsonthrough the existing parser, with no per-row parsed-object cache. The accepted P2 performance finding is resolved by deleting the compact SQL JSON validation, key grouping, field extraction, serialization, and reconstruction path. Integrity checks, legacy-field normalization, streaming, and bounded card sampling remain.scripts/proof-bay-ttl.mjsand its documentation reference are deleted; no test imported it.Bay is affected in snapshot delivery and cold materialization cost. Its public fields, repository filtering, freshness limit, and observer-only boundary are unchanged. This fix round preserves the TTL-only memo, single-flight, production TTL, and outer edge SWR exactly. No Bay UI change is needed.
pr-behavior-proof
Claim and exercised surface: production lifecycle projection code in local workerd SQLite produces identical snapshots with less cold materialization time. The production queue route still reuses one memo across 30 polls with one state write per simulated second.
Fixture and environment: 20,000 mixed synthetic projections across two repositories, including historical terminal states, claims/results, acknowledgements, legacy optional fields, and multiple revisions. Provider
local-process, macOS arm64, Node v26.8.1, workerd via Miniflare; no image or lease. Cold measurements are request wall time over 11 interleaved builds per variant. Before is299b1a5fc8bb0200f2e5e9360052c5eda1091a25; after is9e8d95301bf6ded54459514cdf8f15b7c894f8b6.Cold workerd time falls 63.7%. Every before/after snapshot is deeply equal, with 20,000 lifecycle records. Cached medians remain below 0.1 ms; their tiny difference is not evidence of a change in cache performance. Route CPU measurements use a separate admission-only 20,000-row fixture with Node SQLite, not workerd CPU accounting. The two fixtures and timing types are not interchangeable.
Commands and artifacts: the retained local reviewer harness was rerun as
node .artifacts/bay-1388-fix/workerd-comparison.mjs; its fixture comes from the deleted script at the before commit..artifacts/bay-1388-fix/workerd-report.jsoncontains source hashes, timings, and output-equivalence results. The route benchmark runs with:EXACT_REVIEW_CPU_BENCH=1 node --test --test-name-pattern='Bay TTL CPU' test/exact-review-queue-cpu.test.tsRoute traces are
.artifacts/bay-1388-fix/memo-before.logandmemo-after.log. These paths are local proof artifacts. Fixture SHA-256:a96a3e022e79ddfc6f4eca6294c8c616aff0d73f1941d550587b83ed115bb568. Lifecycle source SHA-256: beforeec9dd9256c6366605224061730184206b5f8844567610df60be4002dc3b64df1; after65c3f880c4fe92a66d2af91b4ee1932ab0bfab202f54f8268a579c35edc0a1e5.Regression proof: streaming more than 10,000 rows; full audit/Bay mixed-fact equivalence; malformed JSON, duplicate keys, NULs, invalid row identity and legacy fields; memo expiry, writes, normalized scopes, single-flight and failure/reset safety; outer edge hits, stale refresh coalescing, cache failures and original source-age limits. The required seven-file test command passes 488 tests, with three opt-in benchmarks skipped.
Limits: synthetic local execution does not establish production CPU, capacity, cache eviction, or cross-colo behavior. Cold builds still scan all retained projections; this remains O(retained projections). Seven-day telemetry and 30-day event retention belong to different tables. Persisted aggregates need a separate durable-state/backfill change. No production services were contacted by these proofs.
Validation
pnpm run format,pnpm run build:all,pnpm run lint,pnpm run check:docs,pnpm run check:limits,pnpm run check:dashboard-queue-boundary,pnpm run check:dashboard-strict,git diff --check, and the required seven-file test command pass. Independent pre-commit review is clean through P2. The fullpnpm run checkalso passes in exact-head CI on9e8d95301bf6ded54459514cdf8f15b7c894f8b6. CI completed successfully on poll 10 at 60-second intervals, without a retry or follow-up fix. The duplicate local full-suite run was stopped after CI went green; no local full-suite pass is claimed.Release-note context: Bay polling reuses bounded-stale snapshots during continuous writes, and cold builds use the plain projection parser to avoid redundant SQL JSON processing. The changelog and operational docs are updated.