Skip to content

fix(maintenance): enforce scoped target dimensions - #4522

Merged
Sinity merged 5 commits into
masterfrom
feature/packet/polylogue-oqyew
Sep 2, 2026
Merged

Sinity merged 5 commits into
masterfrom
feature/packet/polylogue-oqyew

Conversation

@Sinity

@Sinity Sinity commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

Maintenance scope dimensions are now target-owned. Session IDs narrow the empty-session cleanup target and bypass global preview counts; replay and planner execution produce a typed per-target refusal for dimensions a target cannot apply. The shared envelope reports the union of unsupported dimensions in stable contract order.

Problem

The maintenance envelope accepted and echoed origin, source, time, failure, and parser filters even when execution ignored them. Cleanup execution also dropped session IDs, allowing a scoped CLI request to process whole-archive debris.

Solution

Declared honored dimensions per maintenance target, threaded session IDs through cleanup and replay execution, and recorded UnsupportedScopeDimension failures before invoking an unqualified target.

Verification

  • nix develop --accept-flake-config --command devtools test tests/unit/maintenance/test_envelope_contracts.py tests/unit/maintenance/test_resume.py tests/unit/storage/test_repair.py — 171 passed.
  • nix develop --accept-flake-config --command devtools verify --quick — all checks passed.

Residual risk

Only session_ids is currently executable as a narrowing dimension. Other dimensions fail closed per target and remain visible in the envelope; superseded raw snapshot cleanup does not accept session-ID narrowing.


Receipt: harvest-2c14c50175219643162d56ae8af39d8f

@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: d4fd8988-daf0-493d-a72c-5da019d830df


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 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-02T11:31:25.385215Z 4e7fe03 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.

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

ℹ️ 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/storage/repair.py Resolved
Comment thread polylogue/storage/repair.py Resolved
@Sinity
Sinity force-pushed the feature/packet/polylogue-oqyew branch from e056fdc to ece5ee7 Compare September 2, 2026 03:17
@Sinity

Sinity commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

1 similar comment
@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: e4723d8e6e

ℹ️ 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/scope.py Resolved
Comment thread polylogue/maintenance/replay.py Resolved
@Sinity
Sinity force-pushed the feature/packet/polylogue-oqyew branch from e4723d8 to d635776 Compare September 2, 2026 03:46
@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: d6357760a1

ℹ️ 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/planner.py Resolved
Comment thread polylogue/maintenance/planner.py Resolved
Comment thread polylogue/maintenance/scope.py Resolved
Comment thread polylogue/maintenance/replay.py Resolved
@Sinity

Sinity commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: d6357760a1

ℹ️ 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 added a commit that referenced this pull request Sep 2, 2026
## Summary
`.lane/body.md` and `.lane/title` leave the index; `.gitignore` already
lists `.lane/`.

## Problem
Every merged lane PR rewrote the two tracked files, so every other open
lane branch conflicted with master on them (#4509 rebased four times
tonight, #4513/#4515/#4516/#4520/#4522 all cycled through the rebase
reaction for this alone). The harvest reads the publication text from
the worktree, not from the commit.

## Solution
Untrack the two files. Lane branches that still carry them conflict once
more (delete versus modify) and then never again.

## Verification
```
devtools verify --quick   # exit 0
```

## Residual risk
A lane that force-adds `.lane/` reintroduces the churn for itself only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01YGi8wLWGR2HYBh8p8fXFXz

Receipt: session-01YGi8wLWGR2HYBh8p8fXFXz

Co-authored-by: Claude Fable 5.1 <[email protected]>
@Sinity
Sinity force-pushed the feature/packet/polylogue-oqyew branch 2 times, most recently from 4c22fa3 to 4e7fe03 Compare September 2, 2026 11:23

@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: 4e7fe03f13

ℹ️ 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
@Sinity
Sinity merged commit c117184 into master Sep 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/packet/polylogue-oqyew branch September 2, 2026 16:32
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 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 5ebcfe5):

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

@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