Repository navigation
coordinator: persist the cache routing holder and demand indexes across restarts - #1240
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b4d65914b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
b4d6591 to
2fea54f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fea54f1c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4cd59d6189
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01ac365c4c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…and re-apply the changelog section and configuration rows after the rebase)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 048c4ddb51
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…store premise Findings of the independent review of round 28: - The dirty-cap comments (the field, Options.MaxPending, requeue) say what happens to a delete past the cap (a reset, never a drop; a requeued delete is kept) instead of claiming every mark is dropped. - The restore's "nothing parked is condemned" argument states its premise: nothing drains before the copy is established, so no decision has left the pending set or been evicted from retention in flight. - An abort into a reset counts the rows merged before it as restored (they stay parked); a failed reset records its duration like any failed flush; a test covers the overflow that lands during an empty load, which only the post-loop check catches.
…and re-apply the changelog section and configuration rows after the rebase)
…fore an overflow Codex round 29: - ResetCacheRoutingState records an in-progress marker as the key generation before it clears the tables (both stores), and records the fingerprint only afterwards, so a same-generation reset interrupted between its batched deletes (a crash, the shutdown flush deadline) is completed by the next boot instead of read as complete and its residual rows restored. Restore treats the marker as an interrupted reset, not a key rotation. - A batch drained before a backlog overflow does not requeue its upserts after it: one may be evidence a released decision condemned (its queued copy was removed at decision time, the drained copy was already in flight), and the reset that follows would write it back. Batches carry the overflow count they were drained under; requeue drops the upserts of an older batch (counted in dropped_dirty) and keeps its deletes and demand. Tests: a restore against a store left with the marker completes the reset without counting a rotation; an upsert batch that fails while the row is invalidated and the backlog overflows is not requeued and the row is not written back after the reset.
…and re-apply the changelog section and configuration rows after the rebase)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e06fdb2b88
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… was drained under Findings of the independent review of round 29: - Flush rebuilt the batch it requeued without the overflow count it was drained under, so after the first overflow of a process every failed flush dropped all of its upserts. The requeued batch carries the count; a test fails an upsert batch after a handled overflow and asserts it is requeued in full. - A Postgres test interrupts a reset right after its marker (a test-only hook on the store) and asserts the marker is the recorded generation and the rows are untouched, then that the retry completes the reset. - The interrupted-reset log no longer attributes the attempt to the previous run (a retried restore's own earlier attempt counts); the key_rotated row says a completed interrupted reset does not count; the rollout page states the single-writer assumption for an overflow reset.
…and re-apply the changelog section and configuration rows after the rebase)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1985e86d92
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…sh loop on overflow Codex round 31: a backlog overflow between a flush's reset check and its drain let the flush write its batch with the reset still pending, and a crash before the next flush left the fingerprint complete over rows the released decisions had condemned. The check and the drain now share one lock hold (drainUnlessReset): a drain never proceeds while a reset is pending, and a flush that finds the flag set at drain time resets first and then drains. An overflow also wakes the flush loop (Wake), so the reset's marker lands at the next flush rather than the next tick; the window between the overflow and the marker is the residual, documented as such. Also, from the independent review of the round-29 follow-up: the rollout note names the exposure of an overlapping overflow reset, and the Postgres marker test checks load errors.
…and re-apply the changelog section and configuration rows after the rebase)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 344c42a1f2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…fter the drain Codex round 32: a drained batch was still written after an overflow that landed between the drain and its first store call, so upserts a released decision condemned could reach the store ahead of the reset. The flush now re-checks the overflow count before every upsert chunk; when the backlog overflowed since the drain it stops writing, requeues the remainder (whose upserts the fence drops) and runs the reset in the same flush, so the marker lands before anything else is written. The window between that check and the store call is the same residual as between an overflow and the marker. Also, from the independent review of round 31: tests now guard the flush's reset after a refused drain (an overflow injected between the check and the drain through a test-only hook) and the loop's wake path (a registry-level overflow whose reset must land inside the flush tick), and the wake-up's practical bound is stated in the architecture page and the changelog.
…and re-apply the changelog section and configuration rows after the rebase)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 756909f2c3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… overflow Codex round 33 (and the independent review of round 32): the mid-flush fence ran only before upsert chunks, so a delete-only or demand-only batch spent its store calls with a reset pending only in memory. The fence now runs before every chunk of every kind: the flush stops at its next store call, requeues the remainder (upserts dropped, deletes and demand kept) and resets in the same flush, so the marker lands as early as the next chunk boundary. Also from that review: a reset that fails on the mid-flush path is counted once against its flush (not twice) and retried by the next flush, which then writes the requeued deletes; a reset's duration counts in the flush timing; the wake test queues the condemned row's decision before the fillers so the overflow releases it; the after-check test asserts a real fingerprint.
…and re-apply the changelog section and configuration rows after the rebase)
…a reset-only flush Findings of the independent review of round 33: - On the mid-flush path the flush was stamped before its reset ran, so the reset's duration was excluded from last_flush_ms and last_flush_at read as done while the reset was in flight. The stamp now follows the reset attempt, with its outcome. - A flush whose reset left nothing to drain behind it bumped no counter, so a reset-only flush was invisible in flushes and last_flush_at. It is counted now (resetIfPending reports whether it reset).
…and re-apply the changelog section and configuration rows after the rebase)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26b674d979
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Found 1 test failure on Blacksmith runners: Failure
|
…r the reset Findings of the independent review of the round-33 follow-up: the restamp after a mid-flush reset had no failing test (both stamps fell in the same second), and the mid-flush path still stamped once before its reset, so a status read during a slow reset showed the pre-reset stamp. The path now stamps only after the reset attempt; the failed-reset test makes the reset slow and asserts its duration lands in last_flush_ms; the flush-health row says a reset-only flush counts and a mid-flush reset's duration counts.
…and re-apply the changelog section and configuration rows after the rebase)
jonathan308
left a comment
There was a problem hiding this comment.
Reviewed commit befa667. No blocking findings from this review.
Checked revision-scoped acknowledgements and pending-delete retention, reset/restore fencing and TTL/cap handling, capability-bound reattachment, shared-session invalidation, HMAC-only persisted boundary identity, and provider-socket/periodic-writer shutdown ordering. The earlier automated review threads are resolved on this head.
Independent local Go 1.25 race checks: 47 top-level tests passed in cachepersist/cacheroutingstate; 178 top-level cache integration/store/shutdown tests passed. Zero failures. PostgreSQL-dependent coverage was not executed locally: two top-level skips and three additional subtest skips with DATABASE_URL deliberately unset. Full PostgreSQL/CI results remain separate; the current Coordinator, Provider and E2E jobs were still running when this review was submitted.
Approval is for this reviewed code, not a declaration that all CI/release gates have passed, and does not perform a merge or deployment.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: befa667037
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| tier = CASE WHEN EXCLUDED.updated_at >= cache_routing_holders.updated_at THEN EXCLUDED.tier ELSE cache_routing_holders.tier END, | ||
| model_id = CASE WHEN EXCLUDED.updated_at >= cache_routing_holders.updated_at THEN EXCLUDED.model_id ELSE cache_routing_holders.model_id END, | ||
| model_aggregate_hash = CASE WHEN EXCLUDED.updated_at >= cache_routing_holders.updated_at THEN EXCLUDED.model_aggregate_hash ELSE cache_routing_holders.model_aggregate_hash END, | ||
| prompt_contract_id = CASE WHEN EXCLUDED.updated_at >= cache_routing_holders.updated_at THEN EXCLUDED.prompt_contract_id ELSE cache_routing_holders.prompt_contract_id END, | ||
| block_hash_version = CASE WHEN EXCLUDED.updated_at >= cache_routing_holders.updated_at THEN EXCLUDED.block_hash_version ELSE cache_routing_holders.block_hash_version END, |
There was a problem hiding this comment.
Normalize tolerated-skew rows before conflict updates
When the previous coordinator wrote a holder up to FutureSkew ahead, LoadCacheHolders clamps only the returned copy while leaving the durable updated_at in the future. Until the local clock catches up, a fresh receipt reaches this conflict clause with an older timestamp, so these CASE expressions retain the old capability fields and measurement instead of the newly proved values. This is observable when a provider changes ready_boundary_mode without rotating its epoch: a restart restores the old identity, rejects it as a mismatch, and loses the valid new evidence. Normalize tolerated future timestamps in storage or let a current receipt supersede a row within the skew window.
Useful? React with 👍 / 👎.
Summary
Keep a write-behind copy of the exact prefix-cache holder and observed-demand indexes across coordinator restarts. Routing continues to read and update its in-memory indexes; Postgres IO stays outside registry locks and off the request path.
Code Organization
coordinator/registry/cachepersist/separates state/construction (persister.go), intake (marks.go), snapshots and acknowledgements (mutations.go), writing (flush.go), overflow (reset.go), restore, parked holders, delete fences, indexed heaps, maintenance, and status. Tests are grouped by those responsibilities.coordinator/registry/cache_persistence{,_registry}.goowns registry integration and lifecycle wiring.coordinator/store/cacheroutingstate/defines records and the store contract; memory and Postgres implementations live in the store package.Before
Blue: execution paths. Green: serving state. Red: lost state and recovery cost.
After
flowchart TD Events["Receipts, demand, invalidations"] --> Hot["Update in-memory indexes"] Hot --> Route["Requests keep routing from memory"] Hot --> Mark["Mark revisioned pending mutation"] Mark --> Snapshot["Flush: bounded snapshot, no removal"] Snapshot --> DB[("Postgres durable copy")] DB --> Ack{"Write acknowledged?"} Ack -->|"yes"| Clear["Clear only matching revisions"] Ack -->|"no"| Keep["Leave changes pending for retry"] Overflow["Delete backlog overflow"] --> Fence["Retain cutoff and reset durable copy"] Fence --> DB Boot["Restart: Restore"] --> Load["Check generation, TTL and caps"] DB --> Load Load --> Bind["Seed demand; park and bind matching holders"] Bind --> Hot classDef code fill:#dbeafe,stroke:#1d4ed8,color:#172554 classDef memory fill:#dcfce7,stroke:#15803d,color:#14532d classDef durable fill:#ede9fe,stroke:#6d28d9,color:#4c1d95 classDef safety fill:#fef3c7,stroke:#b45309,color:#78350f class Events,Route,Snapshot,Boot,Load,Bind code class Hot,Mark,Clear,Keep memory class DB durable class Ack,Overflow,Fence safetyPurple: durable state. Yellow: acknowledgement and invalidation safeguards. All store calls run outside registry locks.
Validation
make coordinator-test.go test -race ./coordinator/registry/cachepersist -count=3.go test -race ./coordinator/registry ./coordinator/api -run 'Test(Cache|CloseProvider|WaitProvider|ProviderShutdown)' -count=1.make coordinator-buildandgo vet ./coordinator/registry/... ./coordinator/store/... ./coordinator/api/....make docs-impact-check BASE=origin/master,make docs-check, andgit diff --check.Regression coverage includes stale acknowledgements, partial writes, failed deletes under retention pressure, overflow and delayed evidence, missed/shorter-hit boundaries before restore, and invalidating the newest shared session with queued and already-flushed rows. Store contracts and restart behavior run against memory and Postgres.
Interfaces and Rollout
cache_routing_holders,cache_routing_demand, andcache_routing_meta; the acknowledgement refactor adds no further schema changes.EIGENINFERENCE_CACHE_ROUTING_PERSISTdefaults on. Set it tofalseto retain the original empty-index-after-restart behavior.GET /v1/cache/statusexposeslifecycle.persistencerestore, pending-holder, binding, flush, overflow, and stale-upsert counters.rows_deletedcounts successfully submitted delete keys, including missing rows, not actual deleted rows.Canonical behavior and operations are documented in
docs/architecture/cache-aware-routing.md,docs/operations/cache-routing-rollout.md,docs/reference/api-contracts.md, and the existing storage/configuration/deploy references.