Skip to content

fix(storage): preserve durable result-set transitions - #4526

Merged
Sinity merged 4 commits into
masterfrom
feature/packet/polylogue-htjxx
Sep 2, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/packet/polylogue-htjxx

Conversation

@Sinity

@Sinity Sinity commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Preserve durable user references when a candidate changes message IDs to the current namespace.

Problem

Finding result-set members and mixed EvidenceRef fields could be stranded or rejected during a message-ID transition. The prior packet also mixed unrelated ZIP replay and Claude sidecar work into this PR.

Solution

Catalog durable reference fields by tier, classify every parsed public reference, and leave opaque locators unchanged. A changed immutable result set is validated, cloned as a successor with recomputed membership hashes, and its mutable owners and assertion references are repointed atomically. The PR diff now excludes the unrelated ZIP and parser changes.

Verification

devtools test tests/unit/maintenance/test_assertion_transition.py tests/unit/storage/test_durable_references.py passed: 22 passed.

devtools verify schema-versioning, devtools verify oracle-integrity, devtools verify layering, and devtools verify --quick passed.

Residual risk

An affected-testmon verification is still running under shared-host I/O pressure. Its earlier durable-change-train failures were source-schema parity failures outside this diff.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 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-09-02T05:21:28.877518Z 200f46a New commits
ℹ️ 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 Sep 2, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 69b267db-ca40-4929-8f4a-ae4c867b10db


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 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: 1244bfcaf9

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

@Sinity
Sinity force-pushed the feature/packet/polylogue-htjxx branch from 1244bfc to 97b4351 Compare September 2, 2026 04:47
@Sinity

Sinity commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

@codex 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: 97b43512c6

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

@Sinity Sinity changed the title refactor(test): make corpus manifests canonical fix(storage): preserve durable result-set transitions Sep 2, 2026

@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: 200f46af39

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

@Sinity
Sinity merged commit 1d8c570 into master Sep 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/packet/polylogue-htjxx branch September 2, 2026 16:32
Sinity added a commit that referenced this pull request Sep 3, 2026
## Summary

Nine unaddressed Codex review threads from merged PRs #4539, #4550 and
#4552. Each was re-verified against current `origin/master` before being
fixed; two were refuted and are recorded below rather than silently
dropped.

## Problem

Attribution for a read result was assembled inside
`polylogue/surfaces/authority.py` from a bare archive root. That is the
wrong layer and the wrong input: the surface re-resolved the active
generation at serialization time, so a result could be attributed to a
generation published after its rows were read.

## Solution

**#4539 `polylogue/surfaces/authority.py:12` — move archive resolution
out of the surface layer.** `surfaces/authority.py` now holds only the
envelope and takes already-resolved facts. Resolution moved to
`polylogue/operations/authority.py`. `docs/plans/layering.yaml` gains a
`polylogue/surfaces` rule so the boundary is enforced rather than merely
intended — it had no rule at all, so the import was unratcheted. Two
pre-existing type-only row imports in `payloads.py` are baselined and
ratchet like the other four surfaces.

**#4539 `polylogue/archive/query/unit_results.py:728` — bind authority
to the generation opened by the reader.** New
`ArchiveIdentity.resolve_pinned_index` resolves durable tiers against
the index a reader already holds open. `authority_for_reader` uses it.

**#4539 `polylogue/api/search_envelope_builder.py:138` — resolve
authority from the active archive root.** `authority_for_config` follows
`active_archive_root(config)`, so an explicit `Config(db_path=...)`
split-root override is attributed to the archive the read actually used.

**#4539 `polylogue/surfaces/authority.py:65` — measure elapsed time at
the operation boundary.** No production call site passed `started_at`,
so `elapsed_ms` was structurally always 0. All eight now capture it at
their operation boundary.

**#4539 `polylogue/surfaces/payloads.py:3947` — include authority in
daemon message responses.** `_do_get_messages` and
`_do_archive_get_messages` emit `authority`, including on the not-found
early return.

**#4552 `polylogue/api/archive.py:1691` — preserve expiry filtering in
the candidate queue.** `_archive_list_assertion_candidates` derived the
actionable queue from the candidate-*review* read model, which pins
`include_expired=True` deliberately so judged history is never erased.
The queue now calls the canonical `list_assertion_candidates`, which
excludes expired claims.

**#4552 `polylogue/api/archive.py:3453` — preserve user-tier
unavailability errors.** A missing or unreadable `user.db` was swallowed
into `return []`, presenting a read failure as a judged-empty queue.
Both candidate reads now go through one `_readable_user_tier` context
manager that raises `ArchiveTierUnavailableError`, matching the sibling
assertion read.

**#4550 `polylogue/cli/click_command_registration.py:192` — limit the
root alias.** Root `insights` registered the whole `ops insights` group
a second time, contradicting `docs/insights.md:7`, and entered the tree
as an unexplained hitchhiker in the #4550 squash (that PR was a
corpus-manifest refactor). Removed; `docs/cli-reference.md` regenerated.

### Refuted

**#4550 `click_command_registration.py:192` — "update the pinned
root-help snapshots".** There is no pinned root-help snapshot.
`tests/unit/cli/test_help_snapshots.py` does not exist, and `devtools
render all --check` reports every generated surface in sync at the
reviewed head. No change made.

**#4526 `polylogue/operations/zip_acquisition_replay.py:122` — large
JSON integer overflow.** The reviewed code never merged: `git log` shows
the file untouched by #4526, whose merge commit records that the
ZIP-replay work was descoped before merge. Nothing to fix.

## Verification

`devtools test tests/unit/surfaces/test_authority.py
tests/unit/api/test_assertion_candidate_queue_admission.py
tests/unit/cli/test_help_contract.py -n 2` — **166 passed**.

`devtools gate layering` — `violations 0, baselined 296, status passed`
with the new `polylogue/surfaces` rule enforced.

`devtools test tests/unit/api tests/unit/surfaces tests/unit/mcp -n 4` —
897 passed, 3 failed. All three failures reproduce identically on clean
`origin/master` (`test_archive_tiers_api_session_costs_read_index_tier`,
`test_existing_same_version_ops_database_receives_additive_call_log`,
`test_record_context_delivery_requires_initialized_user_tier`) and are
inherited, not introduced here.

`devtools verify --quick` — all 12 gates ok (run by the pre-push hook).

Each new test names its anti-vacuity condition in its docstring:
dropping `started_at` pins `elapsed_ms` to 0; resolving from the root
instead of the pinned index flips attribution to the newly published
generation; reading `config.archive_root` instead of the active root
returns the decoy archive; re-importing `archive_identity` into the
surface module fails the boundary assertion; routing the queue back
through the review read model resurfaces the expired claim; swallowing
the tier error back into `return []` makes the refusal test pass
silently.

## Residual risk

The `polylogue/surfaces` layering rule is new, so its two baselined
`payloads.py` entries are type-only imports that a future change could
grow into runtime ones; the ratchet makes that visible in review rather
than preventing it. `authority_for_reader` requires a reader exposing
`archive_root` and `index_db_path` — the MCP and daemon archive paths
satisfy this; config-based surfaces still resolve the active generation,
which is correct for them because they have not opened a reader.

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sinity added a commit that referenced this pull request Sep 3, 2026
…ty transitions (#4582)

## Summary

Eleven Codex review findings against the maintenance layer (PRs #4522
and #4526), re-confirmed at this branch's base. All eleven held; none
were refuted.

## Findings and what changed

**#4522 — planner / scope / CLI**

1. `maintenance/planner.py` set `status=FAILED` on a scope refusal but
never `error=`, and `cli/commands/maintenance/_plan.py` printed only
`result.error`, never the failure samples, and always exited 0. A
refused plan read as "Affected: 0 rows", exit 0. → the refusal receipt
now carries `error`; plain output prints every failure sample; a FAILED
plan exits 1 in both plain and JSON modes.
2. The preview counted archive-wide `count_empty_sessions_sync` and
clamped it with `min(total_rows, len(session_ids))`, while execution
filters by `session_ids`. One healthy requested session plus unrelated
debris previewed 1 affected row where execution deletes 0. →
`count_empty_sessions_sync` takes `session_ids` (the same narrowing
`repair_empty_sessions` applies) and the planner counts scoped
candidates. `session_insights` has no scoped counter yet and keeps the
request-size clamp.
3. Click's `multiple=True` yields `()` for an omitted `--session-id`,
and `_coerce_session_ids` kept `()`, so `scope.py` treated it as a
scoped request and refused the default `polylogue ops maintenance plan`
for `superseded_raw_snapshots`. → an empty sequence normalizes to `None`
at the model boundary, so every surface (CLI, MCP, daemon) agrees.

**#4522 — replay refusal machinery (4, 5, 6 are one mechanism)**

4. `_build_in_progress_snapshot` derived COMPLETED from `all_completed`
alone, ignoring `state.failures`, so the checkpoint written between the
last target and the final receipt persisted COMPLETED for a permanent
refusal. → the snapshot is FAILED when the state carries a terminal
scope refusal, matching the final receipt exactly.
5. `offline_maintenance_blockers` ran before
`unsupported_scope_dimensions` was ever consulted (only inside
`_run_one_target`), so an invalid scoped request under daemon write
ownership was reported as a retryable blocker. → refusals are recorded
and their targets dropped from the pending set before the offline gate;
if nothing supported remains, the existing terminal-refusal receipt path
handles it.
6. `_has_terminal_scope_refusal` scanned all hydrated samples with no
target filter, so resuming with a narrowed, succeeding target set still
returned FAILED from a stale excluded-target sample. → the check is
scoped to the targets the current invocation requests.

**#4526 — durable identity transitions**

7. `_has_complete_durable_schema_marker` checked only
`query_unit_frame_state` (migration 010) while
`_validate_reference_catalog` then required `query_excision_ledger`
(migration 011), rejecting a valid v10 archive. →
`DurableReferenceRelation` declares the `since_version` that introduced
it, and a versioned file is validated only against relations at or below
its `PRAGMA user_version`. An unversioned file (ad-hoc or fully-applied
DDL with no cursor) still falls back to the marker.
8. `_repoint_result_set_owners` rewrote `retained_query_runs` /
`query_evaluation_receipts` unconditionally, but
`put_retained_query_run` treats `result_set_id` as exact-retry identity,
so a retry after a transition raised a spurious conflict. → execution
records keep naming the manifest they ran against (which is retained);
only the forward-looking `watched_query_baselines` moves.
9. `_clone_holdout_policy` gave a holdout cohort a second manifest id
while `has_holdout_contamination` is scoped strictly by `result_set_id`,
so contamination under one id was invisible under the other. → a result
set under a holdout policy is refused a successor outright, so the
cohort keeps one identity.
10. `_insert_result_set_successor` was a plain INSERT with no existence
check, so a retried application with the same deterministic successor id
raised `IntegrityError`. → `INSERT OR IGNORE` for the manifest and its
members; the id is a hash of the content, so a colliding id already
carries exactly this content.
11. With a separate `audit_conn`, two connections released savepoints
sequentially with no coordination; if the savepoint was outermost, the
release committed the user tier by itself and a crash before the audit
release stranded a durable transition with no audit record. → both
connections are placed in an explicit transaction first, so every
release is nested and neither tier is durable until the caller commits.

## Verification

```
devtools test tests/unit/maintenance/test_planner_filter_narrowing.py -n 2      # 11 passed
devtools test tests/unit/maintenance/test_resume.py -n 2                        # 52 passed
devtools test tests/unit/maintenance/test_assertion_transition.py -n 2          # 26 passed
devtools test tests/unit/cli/test_maintenance_registration.py -n 2              # 16 passed
devtools test tests/unit/storage/test_repair.py tests/unit/storage/test_empty_session_repair_provenance.py -n 2   # 108 passed
devtools test tests/unit/maintenance/test_scope_filter.py tests/unit/maintenance/test_scope_filter_envelope_contract.py tests/unit/maintenance/test_envelope_contracts.py tests/unit/maintenance/test_planner_contract.py -n 2   # 96 passed
devtools test tests/unit/daemon/test_maintenance_endpoints.py tests/unit/maintenance/test_preview.py tests/unit/maintenance/test_idempotency.py -n 2   # 40 passed
devtools verify --quick                                                         # exit 0, no "out of sync"
```

Anti-vacuity was measured, not asserted: reverting
`polylogue/maintenance/replay.py` to its pre-change state turns the
pre-gate and narrowed-resume tests red, mutating `clean = all_completed
and not _has_terminal_scope_refusal(...)` back to `clean =
all_completed` turns the checkpoint test red, and reverting
`polylogue/maintenance/assertion_transition.py` turns all five new
transition tests red.

Three tests that existed before this branch encoded the fixed behavior
and were updated with it: the two `retained_query_runs` /
`query_evaluation_receipts` repoint assertions in
`test_result_set_member_transition_clones_the_manifest_and_repoints_owners`,
and the `session_ids` clamp assertions in
`TestPlannerNarrowsBySessionIds`.

## Residual risk

- Finding 9 is fixed by refusing, not by sharing: a result set under a
holdout policy can no longer be given a successor manifest at all.
Sharing contamination across two ids would need a durable lineage link
(a user-tier migration), which is out of scope here.
- Finding 11 removes the savepoint-release window but not cross-file
atomicity: two SQLite files cannot commit atomically, so a crash between
the caller's two commits remains possible. The function now guarantees
only that no savepoint release commits one tier alone.
- Finding 2's scoped counting covers `empty_sessions`;
`session_insights` still falls back to the request-size clamp.
- `_run_one_target`'s own scope-refusal branch is now unreachable from
`execute_replay` and is retained as defense in depth.

Not in scope: findings 12-20 (surfaces / api / cli), owned by another
lane.

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
@Sinity

Sinity commented Sep 28, 2026

Copy link
Copy Markdown
Owner Author

Codex review threads on this PR whose cited code is gone (checked against master at 23f91a5):

Resolving these threads.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 0914f89):

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 8e6234c):

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 8e6234c):

  • P2 polylogue/operations/zip_acquisition_replay.py:95: Fixed on master (checked at 64a9bd0): With a recorded digest, resolution first tries the hinted candidate, then keeps every candidate that matches the expected identity; several matches resolve as duplicate observations (polylogue/operations/zip_acquisition_replay.py:109-120). No structural-ambiguity refusal comes before the hash test any more.

Resolving every thread listed; confirmed defects are fixed under the named bead.

@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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