Skip to content

fix: Count a refused membership cohort instead of fencing its generation - #5129

Merged
Sinity merged 1 commit into
masterfrom
fix/cohort-membership-refusal
Sep 14, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/cohort-membership-refusal

Conversation

@Sinity

@Sinity Sinity commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

The last open arm of polylogue-163ku: one selector member that no longer parses still fenced an entire source generation, through a different code path than the one #5056 fixed.

Problem

polylogue/storage/ingest_governance.py::_session_for_key raised a bare
RuntimeError(f"membership {raw_id}:{logical_source_key} no longer parses uniquely") whenever a selector member did not yield exactly one session for the key. prepare_ingest_cohort calls it once per selector member, and _selector_raw_ids admits archive.raw_revision_head_raw_id(logical_source_key) unconditionally — no revision_kind / source_index / census filter, unlike its sibling raw_membership_raw_ids, which admits only byte-proven members.

Concrete input, executed as the new regression test: a published cohort over two Codex raws, then a re-prepare where the now-accepted head raw raises (exactly the production shape — parse_retained_raw_sessions is typed -> list[ParsedSession] and raises rather than returning None).

Wrong observable outcome at the reviewed head: the exception escapes prepare_ingest_cohort, out of IngestExecution.materialize, to execute_ingest_operation's except Exception: await execution.fence("refused"); raise (polylogue/operations/daemon_ingest.py). Every other logical key in that generation — all of them still preparable — is lost with it. This is the repo's own doctrine violated in the stated terms: an escaped exception fencing a generation is neither explicit-and-retryable nor a typed permanent refusal.

Secondary, same site: the zero-match case never established "no longer parses uniquely". A head that is an append fragment was never expected to parse standalone, so the message named a cause the code had not proven.

Solution

  1. Typed, per-key refusal. New CohortMembershipRefusalError(logical_source_key, raw_id, reason) in ingest_governance. _session_for_key raises it for a parse exception, for zero matches, and for multiple matches, each with the reason actually established. Transient SQLite contention is re-raised rather than converted, mirroring prepare_raw_census — contention is not a parse verdict.
  2. Recover per key, not per generation. IngestExecution.materialize catches it around prepare_cohort, emits ingest.membership.refused, records it, and continues to the next key. The remaining keys publish normally.
  3. The skip is counted. This is the part that matters: a per-item skip nothing reports would trade a loud failure for a silent one. IngestTerminalSummaryHistorical gains refused_membership_count: int and a bounded refused_memberships: list[IngestRefusedMembershipHistorical] (key, raw id, reason), populated in historical_receipt. Two new IngestHistoricalReceipt validators make dishonest receipts unconstructable: the count may not fall below its own enumeration, and a receipt may not be source_complete while any membership was refused. The refused keys additionally remain visible as incomplete in the SourceGenerationReceipt blockers projection, which is computed from durable state and unchanged here.

Deliberately not changed: _selector_raw_ids still admits the revision head unconditionally. Filtering it would silently drop the current accepted head from classification — a silent degradation traded for the loud one. Refusing the key, counted, is the conservative reading.

Verification

devtools test tests/unit/storage/test_ingest_governance.py tests/unit/operations/test_machine_receipts.py tests/unit/daemon/test_daemon_http_contracts.py tests/unit/daemon/test_daemon_status.py
devtools test: PASSED exit=0 diagnosis=pytest_passed
devtools verify --quick   # EXIT=0

Anti-vacuity verified by reverting, not asserted. With _session_for_key restored to the bare RuntimeError and the two receipt validators deleted:

E           ValueError: synthetic unparseable retained payload
E       Failed: DID NOT RAISE ValueError
E       Failed: DID NOT RAISE ValueError
FAILED tests/unit/storage/test_ingest_governance.py::test_unparseable_selector_member_is_a_typed_per_key_refusal
FAILED tests/unit/operations/test_machine_receipts.py::test_refusal_count_may_not_understate_its_own_enumeration
FAILED tests/unit/operations/test_machine_receipts.py::test_refused_memberships_cannot_coexist_with_a_source_complete_claim
devtools test: FAILED exit=1 diagnosis=pytest_failed

The first line is the defect itself: the raw ValueError propagating out of prepare_ingest_cohort, which is what reached the generation fence.

Schema closure

devtools schema closure on every touched file:

out  polylogue/storage/ingest_governance.py
out  polylogue/operations/daemon_ingest.py
IN   polylogue/operations/machine_receipts.py
out  tests/unit/storage/test_ingest_governance.py
out  tests/unit/operations/test_machine_receipts.py

machine_receipts.py is IN the closure. This moves the derived schema identity: it must land before the from-scratch rebuild starts, never during one, and it invalidates the seeded fixture cache.

Residuals

  • The per-key continue in materialize is covered only indirectly — by the typed exception it catches and the receipt contract it feeds. There is no end-to-end test driving execute_ingest_operation through a refusal to a terminal receipt; the existing suite has no harness for that path.
  • prepare_ingest_cohort's convertible branch still raises two bare RuntimeErrors with the same fence-the-generation shape. Different route (full-revision retirement), left untouched and unreported by this change.
  • refused_memberships is capped at 256 entries while refused_membership_count is uncapped, so a pathological generation reports an honest total with a truncated enumeration.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

`_session_for_key` raised an untyped `RuntimeError("... no longer parses
uniquely")` for any selector member it could not resolve. That escaped
`prepare_ingest_cohort` into `execute_ingest_operation`'s
`except Exception: fence("refused")`, so one unparseable selector member --
notably the unconditionally-admitted `raw_revision_head_raw_id`, which
carries no revision_kind filter -- cost every other logical key in the
source generation. The message also named a cause the zero-match case never
established.

Every failure there is now a typed `CohortMembershipRefusalError` carrying
the logical key, raw id, and the reason actually established. `materialize`
records it and continues with the remaining keys; transient SQLite
contention still propagates so the cohort is re-prepared rather than
quarantined.

The skip is counted, not silent: `IngestTerminalSummaryHistorical` gains
`refused_membership_count` plus a bounded `refused_memberships` list, and
`IngestHistoricalReceipt` refuses to be `source_complete` while any
membership was refused or to carry a count below its own enumeration.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 47 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 0cec299b-8d3d-437a-8672-4a6de047672c

📥 Commits

Reviewing files that changed from the base of the PR and between a59bdb4 and bbbd29d.

📒 Files selected for processing (5)
  • polylogue/operations/daemon_ingest.py
  • polylogue/operations/machine_receipts.py
  • polylogue/storage/ingest_governance.py
  • tests/unit/operations/test_machine_receipts.py
  • tests/unit/storage/test_ingest_governance.py

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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 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
🔒 Security Review ✅ Completed 2026-09-14T18:17:33.989461Z bbbd29d 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.

@Sinity
Sinity merged commit ff0f34f into master Sep 14, 2026
3 checks passed
@Sinity
Sinity deleted the fix/cohort-membership-refusal branch September 14, 2026 18:23
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.

1 participant