Skip to content

fix(storage): keep claim tombstone checks correlated (v060) - #738

Merged
hardbyte merged 6 commits into
mainfrom
claude/correlated-claim-tombstones
Nov 13, 2026
Merged

hardbyte merged 6 commits into
mainfrom
claude/correlated-claim-tombstones

Conversation

@hardbyte

@hardbyte hardbyte commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

This carries #713 by @Wallace99 onto current main, keeping both of their commits and authorship. 0.6 already has the same fix as #715, released in 0.6.17 through the correlated_claim_tombstones schema patch.

A claim marks each candidate row with an EXISTS over ready_tombstones. For a small batch PostgreSQL can plan that check as a hashed subplan that reads the slot's whole tombstone partition on every claim, although the lookup index exists. OFFSET 0 in the subquery keeps it correlated: one index probe per candidate row. The installer (v023) writes the fenced check into new substrates.

The migration rewrites the claim functions already installed, from their own definitions, so signatures, owners, privileges and settings are unchanged and a function that already has the fence is left alone. On main that means claim_ready_runtime and every per-slot claim_ready_slot_<n> from v051 in the default and every trusted custom queue-storage schema found by awa.queue_storage_schemas(); 0.6 has no per-slot functions and its own discovery. Each function is found by its exact signature, and slot functions only for the schema's installed queue slots, so another function that shares one of those names is not touched. Each schema's rewrite takes the schema's install advisory lock, as v056 and the 0.6 patch do. It takes no table locks and binaries before it claim unchanged.

Renumbering: main gained its own v056 to v059 since #713 was opened, so its migration becomes v060_correlated_claim_tombstones.sql (header, schema_version row, MIGRATIONS entry, CURRENT_VERSION = 60, and the test's migration_sql_range(59, 60)). The merge from main does the renumbering; the commits after it add the install lock, the signature filter, the header contract, the v060 upgrade guide section and a fuller CHANGELOG entry.

Evidence, PostgreSQL 18.6: with the rewrite disabled, claim_tombstone_plan_test fails because a 32-row claim scans 10,000 tombstone rows (claim_legacy: force_custom_plan must not scan tombstone partitions, left 10000, right 0). With it, the test passes for legacy and receipt modes under custom and generic plans, replay leaves the bodies unchanged, and three planted same-named functions (two overloads and a slot beyond the installed count) stay untouched.

Also passing locally: cargo fmt, workspace clippy with -D warnings, workspace build, the 16 migration unit tests, test_every_migration_is_individually_re_runnable, schema_discovery_owner_test, and 33 tombstone and claim prune tests in queue_storage_runtime_test.

Summary by CodeRabbit

  • Bug Fixes
    • Improved claim performance for queues with tombstones by avoiding unnecessary reads across tombstone partitions.
    • The migration updates existing queue schemas without reinstalling tables or triggers. Binaries from before this update continue to claim work as before.

Wallace Sharpe-Davidson and others added 4 commits November 11, 2026 15:46
main now has its own v056 to v059, so the correlated claim tombstone
migration becomes v060.
Take each schema's install advisory lock before rewriting its claim
functions, as v056 and the 0.6 schema patch do, and visit functions in a
stable order. The header now states the N-1 contract, live-load cost and
what external runners apply. Add the upgrade guide section and expand
the changelog entry.
@hardbyte hardbyte added the full-ci Run the full CI matrix (Python build+test, E2E) on this PR label Nov 13, 2026 — with Claude
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T00:57:27.747424Z 65128db PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The claim queries now keep tombstone checks correlated. Migration v060 updates installed runtime and slot-specific claim functions in discovered queue-storage schemas. The migration registry, integration test, changelog, and upgrade guide are updated.

Changes: Claim tombstone checks

Layer / File(s) Summary
Correlated checks in claim query definitions
awa-model/migrations/v023_install_queue_storage_substrate.sql
The dynamic and generated per-slot claim queries add OFFSET 0 to tombstone checks.
Upgrade installed claim functions
awa-model/migrations/v060_correlated_claim_tombstones.sql, awa-model/src/migrations.rs
Migration v060 discovers applicable schemas and updates installed claim functions that lack OFFSET 0. The migration registry advances to version 60.
Verify and document migration behavior
awa-model/tests/claim_tombstone_plan_test.rs, docs/upgrade-0.6-to-0.7.md, CHANGELOG.md
The integration test checks function updates, migration replay, and claim plans. The upgrade guide and changelog describe v060 and its compatibility details.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • hardbyte/awa#713: It applies the same correlated tombstone-check fix, with an earlier migration version and a regression test for plan behavior.
Merge Risk: Minimal · up to 47967

This change keeps the claim tombstone check correlated, so a small claim batch uses an index probe per candidate row instead of scanning a tombstone partition. The migration rewrites only installed claim functions that lack the fence and is safe to replay. Binaries that predate it keep claiming unchanged. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(storage): keep claim tombstone checks correlated (v060)" matches the main change. The PR adds OFFSET 0 to the tombstone EXISTS checks so PostgreSQL uses an index probe per candidate row…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix(storage): keep claim tombstone checks correlated (v060)" matches the main change. The PR adds OFFSET 0 to the tombstone EXISTS checks so PostgreSQL uses an index probe per candidate row, and migration v060 rewrites the existing claim functions to apply that fix. The title names the fix, the affected area (storage), and the migration version. It is specific and concise, and it is a single sentence without noise.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the queue at dawn,
With OFFSET set, the scan moves on.
Each claim probes where tombstones lie,
The live rows hop neatly by.
V060 keeps the functions in line,
And leaves old binaries doing fine.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 33fbf23 and 479678c.

Files selected for processing: 6

  • CHANGELOG.md
  • awa-model/migrations/v023_install_queue_storage_substrate.sql
  • awa-model/migrations/v060_correlated_claim_tombstones.sql
  • awa-model/src/migrations.rs
  • awa-model/tests/claim_tombstone_plan_test.rs
  • docs/upgrade-0.6-to-0.7.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65128db9b5

ℹ️ 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".

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-11-13 03:18 UTC

Find claim_ready_runtime and each claim_ready_slot_<n> for the installed
queue slots by their exact signatures, so another function that shares
one of those names is left alone. The plan test plants such functions
and checks that the migration does not change them.

Copy link
Copy Markdown
Owner Author

@coderabbitai review


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hardbyte
hardbyte merged commit eefcb57 into main Nov 13, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Run the full CI matrix (Python build+test, E2E) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant