Skip to content

fix(worker): bound finalization and speed up metadata completions (0.6) - #648

Closed
hardbyte wants to merge 3 commits into
release/0.6.6from
brian/fix-finalize-backpressure-0.6
Closed

hardbyte wants to merge 3 commits into
release/0.6.6from
brian/fix-finalize-backpressure-0.6

Conversation

@hardbyte

@hardbyte hardbyte commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Finished handlers could outpace committed completions, leaving an unbounded backlog. On 0.6, metadata and retry completions also expanded every retained compact batch on each flush.

Bound attempts waiting for finalization to max(runtime worker capacity, 2 × completion batch size × completion shard count). A finished handler retains its worker slot and heartbeat while waiting for capacity. Compact metadata completions address the batch ID and one-based item index, validate the exact job/run lease/receipt, and avoid locking the shared immutable batch. The PostgreSQL 18 prelock and fresh deciding snapshot remain.

Reconciled with the merged release fixes at 65c62f85, preserving #643's tracked graceful-shutdown finalizers. No migration or public API change. #650 supplies heartbeat protection after admission to finalization; it is still needed when a completion flush exceeds heartbeat staleness.

Validation of the reconciled tree:

  • Required workspace formatting, offline all-target/all-feature Clippy with warnings denied, and workspace build pass.
  • Five focused regressions pass on PostgreSQL 17 and 18: shutdown, stalled-finalization capacity, exact metadata completion while the shared batch is locked, and both live-ready point reads.
  • Earlier combined recovery tests on both engines demonstrated that keyed completion removes the old query's recovery timeout. Those totals included claiming, rescue and rotation; they were not isolated recovery throughput measurements.

Full CI runs for the pushed head. This PR remains open pending the broader release gates; the matched PostgreSQL 17 and assert-enabled persona soaks have unresolved failures.

The executor removed an attempt from the heartbeat set and released its
worker slot as soon as the handler returned, then queued its finalize
on the completion batcher. When finalization was slower than claiming,
the dispatcher kept claiming and the queue of finished, unheartbeated
attempts grew without bound. Those that waited past heartbeat_staleness
were rescued and run again.

Admit at most the completion pipeline's depth (2 x batch size x
shards, and at least one per worker) of attempts to finalization. Past
that, a finished attempt keeps its worker slot and heartbeat until
there is room, which stops the dispatcher claiming. This is the bound
main already has.
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 699be7e8-d2b0-429c-bd8f-352106528862

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T06:00:51.846296Z 303b7ad 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.

@hardbyte hardbyte added the full-ci Run the full CI matrix (Python build+test, E2E) on this PR label Nov 6, 2026 — with ChatGPT Codex Connector
Address compact claims by their batch ID and item index, validating the job, attempt and receipt before closing. Avoid expanding every retained compact batch for each metadata or retry completion flush, and avoid locking immutable shared batch rows. Preserve per-attempt advisory serialization, row-local prelocking and the fresh deciding snapshot.

A 50,000-claim recovery rehearsal with heartbeat protection timed out waiting 120 seconds for retries on PostgreSQL 17 and 18 before this change. With keyed completion, the same full rehearsal passes in 116.35s and 123.30s total. A new regression rejects a wrong item index, completes while the immutable batch row is locked elsewhere, and checks retained tags and metadata.

Validation: cargo fmt --all; SQLX_OFFLINE=true cargo clippy --all-targets --all-features -- -D warnings; SQLX_OFFLINE=true cargo build --workspace; eight focused metadata, stale-completion, cancellation, idempotence and finalization-bound tests plus the shutdown-waits test on PostgreSQL 17 and 18.
@hardbyte hardbyte changed the title fix(worker): bound finished attempts waiting for finalization (0.6) fix(worker): bound finalization and speed up metadata completions (0.6) Nov 6, 2026
JosiahBull added a commit to JosiahBull/awa that referenced this pull request Nov 8, 2026
Carry the complete fix from hardbyte#648 onto the current 0.6 release branch, preserving heartbeat ownership and lock-contention retries. Add coverage for shutdown while finalizer capacity is saturated.

Co-authored-by: Brian Thorne <brian@hardbyte.nz>
@hardbyte

hardbyte commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #695 (via #686), which carries this fix onto the current release/0.6.6.

@hardbyte hardbyte closed this Nov 8, 2026
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