Skip to content

fix(routing): exact delivery proof and atomic queue acknowledgement - #20

Merged
RMANOV merged 2 commits into
mainfrom
agent/routing-ack-atomic-20261004
Oct 3, 2026
Merged

RMANOV merged 2 commits into
mainfrom
agent/routing-ack-atomic-20261004

Conversation

@RMANOV

@RMANOV RMANOV commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Keep durable delivery acknowledgement separate from cursor-terminal eligibility; require exact recipient/current binding evidence and matching versioned successful-launch receipts rather than claim reservations or same-role diagnostic evidence.
  • Preserve prelaunch binding identity through the actual claimed worker and recheck it in the spawn-audit transaction; stale/retired/unconfirmed evidence remains ineligible.
  • Revalidate every recipient and complete the queue in one owned BEGIN IMMEDIATE transaction, closing the public-rebind gap between ACK and write. Preserve existing logical-role terminal/watermark rules and incoming normalization/prompt attribution.
  • Add causal temporary-DB regressions for public rebinding, exact receipt attribution, diagnostic isolation, mixed targets, bounded diagnostics, writer serialization and rollback/connection ownership.

Verification

  • Independent review of the exact repair and isolated execution packet.
  • Causal RED: only the injected public-rebind-at-write-boundary case failed; 127 selected cases passed, including paired no-gap control.
  • Initial atomic GREEN: all 132 selected cases passed. Corrected test-only GREEN: all 135 selected cases (405 setup/call/teardown reports) passed with final provenance/path validation successful.
  • Initial full CI exposed an undeclared optional psutil import in three producer test variants. The follow-up changes only that test: an explicit test-owned identity module versus blocked-absent import crosses the same spawn/rebind scenarios, retaining all receipt assertions and checking recorded create_time 123.5 versus None. No dependency/workflow/production changes or skips. Fresh full CI on the corrected head is required; the initial failed run remains evidence.
  • Corrected inherited worker-author fixture separately passed against stock pump/frozen normalization source.
  • This branch tree matches the exact tested source manifest; only two hooks and the new delivery-ACK test change over current main.

Integration gate

The existing full CI (lint, manifest completeness, full pytest and core-only registry smoke) must succeed for this exact feature head before main integration. No runtime/live database/bridge deployment, schema/governance change, workflow modification or optional-package/native-Windows verification is claimed. Main integration requires separate ratification and postmerge CI.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 21:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 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-10-03T21:29:06.115244Z d5458b1 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.

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The change reworks concurrency-sensitive durable-delivery acknowledgement and transaction ownership, and the new test suite unconditionally imports the undeclared optional psutil, which would error the referenced CI gate—warranting human review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

This PR hardens the debate "pump" routing path so a durable targeted-delivery queue row is only marked complete when there is genuine proof the recipient was reached. It fixes an incident where an implementation-tagged notify-only PING was treated as terminal and the queue was cleared with zero workers launched and no recipient acknowledgement. It separates cursor-terminal eligibility from durable delivery acknowledgement, introduces a versioned "successful-launch receipt" bound to the exact recipient/binding/worker identity, and revalidates acknowledgement inside the same owned BEGIN IMMEDIATE write transaction that completes the queue (closing the rebind-between-ACK-and-write gap).

Changes:

  • debate_pump.py: adds _delivery_acknowledged[_on_connection], _confirmed_delivery_receipt, _cursor_reached, and bounded withheld-delivery logging; _complete_pending_deliveries now runs under an owned write transaction and re-checks acknowledgement before writing.
  • debate_wake.py: captures an authoritative pre-launch recipient/binding snapshot, rechecks it in the spawn-audit transaction, and records a routing_receipt_version:1 / launch_confirmed receipt plus binding_generation only when attribution is still current.
  • Adds tests/test_debate_pump_delivery_ack.py with extensive regression coverage (public rebind, exact receipt attribution, diagnostic isolation, mixed targets, bounded diagnostics, writer serialization, rollback/lock ownership).
File Description
hooks/​debate_pump.py Separates queue ACK from cursor-terminal; adds versioned-receipt/cursor acknowledgement checks and atomic guarded completion under BEGIN IMMEDIATE.
hooks/​debate_wake.py Captures and re-audits prelaunch binding identity; emits versioned successful-launch receipts with binding_generation.
tests/​test_debate_pump_delivery_ack.py New in-process temp-DB regression suite pinning the delivery-ACK contract; one unguarded optional-dependency import flagged.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_debate_pump_delivery_ack.py Outdated
@pytest.mark.parametrize("spawn_ok,rebind_race", [(True,False), (False,False), (True,True)])
def test_real_launcher_receipt_records_prelaunch_parent_and_actual_worker(pump_db, monkeypatch, tmp_path, spawn_ok, rebind_race):
import db_utils
import psutil

@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: d5458b1fdb

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

Comment thread tests/test_debate_pump_delivery_ack.py Outdated
@pytest.mark.parametrize("spawn_ok,rebind_race", [(True,False), (False,False), (True,True)])
def test_real_launcher_receipt_records_prelaunch_parent_and_actual_worker(pump_db, monkeypatch, tmp_path, spawn_ok, rebind_race):
import db_utils
import psutil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid requiring undeclared psutil in this cross-platform test

On a clean Linux environment using the repository's declared .[dev,gui] dependencies, this unconditional import fails with ModuleNotFoundError before all three parameterized cases run; psutil is not listed in pyproject.toml, and unlike the existing psutil-dependent tests this test is not guarded by the Windows-only marker. This makes the full pytest CI job depend on an undeclared ambient package, so either mock the optional module without importing it or declare it as a test dependency.

Useful? React with 👍 / 👎.

Comment thread hooks/debate_pump.py
Comment on lines +567 to +568
return bool(cursor and cursor["last_processed_ts"] and
(str(cursor["last_processed_ts"]), str(cursor["last_processed_msg_id"] or "")) >= (trigger_ts, trigger_id))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize timestamps before comparing cursor positions

When the trigger and cursor use different valid ISO-8601 precisions, this string comparison can order them incorrectly. For example, a trigger at 2026-10-03T00:00:00Z compares greater than a later cursor at 2026-10-03T00:00:00.500000Z because Z sorts after ., so an acknowledged delivery remains pending; the accepted timestamp format permits both representations, and Python's isoformat() can omit the fraction when microseconds are zero. Parse or normalize the timestamps before applying the (timestamp, msg_id) comparison.

Useful? React with 👍 / 👎.

@RMANOV
RMANOV merged commit 6006a0d into main Oct 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants