Skip to content

perf(bay): serve the Bay projection from a TTL memo and edge cache - #1388

Merged
steipete merged 2 commits into
mainfrom
perf/bay-ttl-only-memo
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
perf/bay-ttl-only-memo

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

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 30000 ms. 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_json through 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.mjs and 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 is 299b1a5fc8bb0200f2e5e9360052c5eda1091a25; after is 9e8d95301bf6ded54459514cdf8f15b7c894f8b6.

Measurement Before fix After fix
Mixed-history cold workerd median wall time 411.481 ms 149.423 ms
Route benchmark, memo disabled: median CPU 228.289 ms 73.865 ms
Route benchmark, 30-second memo: median CPU 0.079 ms 0.088 ms
Route benchmark, 30-second memo: total CPU for 30 polls 255.721 ms 76.128 ms
Route benchmark scans, memo disabled / enabled 30 / 1 30 / 1

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.json contains 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.ts

Route traces are .artifacts/bay-1388-fix/memo-before.log and memo-after.log. These paths are local proof artifacts. Fixture SHA-256: a96a3e022e79ddfc6f4eca6294c8c616aff0d73f1941d550587b83ed115bb568. Lifecycle source SHA-256: before ec9dd9256c6366605224061730184206b5f8844567610df60be4002dc3b64df1; after 65c3f880c4fe92a66d2af91b4ee1932ab0bfab202f54f8268a579c35edc0a1e5.

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 full pnpm run check also passes in exact-head CI on 9e8d95301bf6ded54459514cdf8f15b7c894f8b6. 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.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 3, 2026, 9:09 PM ET / September 4, 2026, 01:09 UTC.

ClawSweeper review

What this changes

This 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 provenance

Possible 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
Reviewed head: 9e8d95301bf6ded54459514cdf8f15b7c894f8b6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has focused tests and detailed synthetic measurements, but a P1 stale-refresh defect and incomplete required runtime proof keep it from merge readiness.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The supplied PR-body evidence reports current-head synthetic Miniflare/workerd measurements, but it does not show the repository-required Docker-backed Crabbox local-container Worker, Durable Object, and Cache API trace; it also does not exercise the introduced unavailable-refresh preservation case. Publish redacted evidence after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied PR-body evidence reports current-head synthetic Miniflare/workerd measurements, but it does not show the repository-required Docker-backed Crabbox local-container Worker, Durable Object, and Cache API trace; it also does not exercise the introduced unavailable-refresh preservation case. Publish redacted evidence after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Introduced stale-refresh overwrite: The introduced refresh path writes every snapshot to both fresh and stale cache buckets, including an unavailable snapshot returned after a failed queue request.
Failure becomes cached unknown state: The lifecycle snapshot helper converts a failed Durable Object request into an unavailable public snapshot; the new background refresh then overwrites the still-valid stale success rather than preserving it through its source-age limit.
Established stale-cache safeguard: The existing status route only replaces its cache when a refresh is not empty, preserving a prior stale status during a failed refresh; the new Bay route lacks the equivalent guard.
Findings 1 actionable finding [P1] Preserve stale success when background refresh fails
Security None None.

How this fits together

OpenClaw 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
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied PR-body evidence reports current-head synthetic Miniflare/workerd measurements, but it does not show the repository-required Docker-backed Crabbox local-container Worker, Durable Object, and Cache API trace; it also does not exercise the introduced unavailable-refresh preservation case. Publish redacted evidence after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve stale success when background refresh fails (P1) - durableLifecycleBaySnapshot() turns a failed queue request into an unavailable snapshot, but this function then stores it in both buckets. A stale hit therefore loses its valid response immediately after a transient refresh failure, unlike the status cache’s guarded replacement; retain the prior stale success until its source-age limit and add that regression case.
  • Resolve merge risk (P1) - A transient Durable Object failure after the fresh cache expires overwrites the still-valid stale success with an unavailable Bay response before its 60-second source-age limit.
  • Resolve merge risk (P1) - The supplied synthetic local proof does not provide the required current-head Docker-backed Crabbox trace for the Worker, Durable Object, and Cache API path.
  • Complete next step (P2) - Preserve the valid stale Bay snapshot when a background refresh is unavailable or malformed, add the regression test, and publish redacted current-head Docker-backed Crabbox local-container proof before merge.

Findings

  • [P1] Preserve stale success when background refresh fails — dashboard/worker.ts:5577-5592
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 10 files; 3 runtime modules and 3 focused test suites The branch changes both Durable Object and Worker caching behavior as well as the regression coverage for their interaction.

Merge-risk options

Maintainer options:

  1. Preserve stale success on refresh failure (recommended)
    Guard cache replacement so an unavailable or malformed refresh cannot displace a still-valid stale Bay snapshot, and cover that failure sequence before merge.

Technical review

Best 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:

  • [P1] Preserve stale success when background refresh fails — dashboard/worker.ts:5577-5592
    durableLifecycleBaySnapshot() turns a failed queue request into an unavailable snapshot, but this function then stores it in both buckets. A stale hit therefore loses its valid response immediately after a transient refresh failure, unlike the status cache’s guarded replacement; retain the prior stale success until its source-age limit and add that regression case.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 72041f31e1d3.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp. Replaced prior rating: 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: The introduced failure path can reduce availability of the public operational dashboard during transient queue outages.
  • merge-risk: 🚨 availability: The new edge-cache refresh can replace an otherwise usable stale snapshot with an unavailable response.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp. Replaced prior rating: 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied PR-body evidence reports current-head synthetic Miniflare/workerd measurements, but it does not show the repository-required Docker-backed Crabbox local-container Worker, Durable Object, and Cache API trace; it also does not exercise the introduced unavailable-refresh preservation case. Publish redacted evidence after the fix. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Introduced stale-refresh overwrite: The introduced refresh path writes every snapshot to both fresh and stale cache buckets, including an unavailable snapshot returned after a failed queue request. (dashboard/worker.ts:5577, 9e8d95301bf6)
  • Failure becomes cached unknown state: The lifecycle snapshot helper converts a failed Durable Object request into an unavailable public snapshot; the new background refresh then overwrites the still-valid stale success rather than preserving it through its source-age limit. (dashboard/worker.ts:5607, 9e8d95301bf6)
  • Established stale-cache safeguard: The existing status route only replaces its cache when a refresh is not empty, preserving a prior stale status during a failed refresh; the new Bay route lacks the equivalent guard. (dashboard/worker.ts:3329, 9e8d95301bf6)
  • Current-head proof limitation: The PR body reports local-process Miniflare/workerd measurements and local artifact paths, but no Docker-backed Crabbox local-container provider, image, lease, or current-head fresh-hit/stale-refresh/maximum-age trace required by repository policy. (9e8d95301bf6)
  • Recent feature history: The preceding merged Bay memo work and the current branch’s Bay cache work were authored by steipete, making that account the strongest routing candidate for this cache path. (dashboard/exact-review-queue.ts:3935, 72041f31e1d3)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Prevent unavailable refreshes from overwriting a still-valid stale Bay snapshot and add a focused regression test.
  • Publish a redacted current-head Docker-backed Crabbox local-container trace for fresh hit, stale refresh, refresh failure, and source maximum age.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-04T00:41:57.131Z sha 299b1a5 :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the perf/bay-ttl-only-memo branch from 9e8d953 to 538a4c1 Compare September 4, 2026 01:20
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant