Skip to content

fix(maintenance): correct scope previews, replay refusals, and identity transitions - #4582

Merged
Sinity merged 5 commits into
masterfrom
fix/codex-maintenance-findings
Sep 3, 2026
Merged

Sinity merged 5 commits into
masterfrom
fix/codex-maintenance-findings

Conversation

@Sinity

@Sinity Sinity commented Sep 3, 2026

Copy link
Copy Markdown
Owner

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)

  1. _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.
  2. 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.
  3. _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

  1. _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.
  2. _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.
  3. _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.
  4. _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.
  5. 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.

Sinity and others added 5 commits September 3, 2026 06:21
Count empty-session debt over the requested sessions instead of clamping
archive-wide debt to the request size, normalize an omitted repeatable
--session-id to "no narrowing", and give a refused preview an error plus a
nonzero CLI exit.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz
…eplay

Refuse an unsupported scope before the offline-write gate so an invalid
scoped request is not reported as a retryable blocker, persist a mid-run
checkpoint carrying a refusal as FAILED, and judge a resumed operation only
by refusals recorded for the targets it still requests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz
Detect catalog completeness from the tier's schema version so a valid
pre-migration-011 user tier is not rejected, leave execution records pointing
at the manifest they ran against, make successor creation idempotent, refuse
to give a holdout cohort a second manifest identity, and enclose both durable
connections in explicit transactions so no savepoint release commits one tier
alone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz
@coderabbitai

coderabbitai Bot commented Sep 3, 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: f8a6c8aa-62fe-4657-b2b2-2df6a9d25afb


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 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-09-03T04:47:40.246384Z b97cb57 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 3925981 into master Sep 3, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/codex-maintenance-findings branch September 3, 2026 04:39

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

ℹ️ 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 polylogue/maintenance/replay.py Resolved
Comment thread polylogue/maintenance/replay.py Resolved
Comment thread polylogue/maintenance/planner.py Resolved
Comment thread polylogue/maintenance/replay.py Resolved
Sinity added a commit that referenced this pull request Sep 3, 2026
@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.

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