Skip to content

fix(lineage): Repair or name the children a full replace strands - #5376

Merged
Sinity merged 1 commit into
masterfrom
fix/stranded-lineage-child
Sep 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/stranded-lineage-child

Conversation

@Sinity

@Sinity Sinity commented Sep 21, 2026

Copy link
Copy Markdown
Owner

fix(lineage): Repair or name the children a full replace strands

A parent full-replace that drops or relocates a branch-point message left its
already-resolved prefix-sharing children composing to their own divergent tail,
with no corrector of any kind. PR #5372 made that state VISIBLE -- the daemon
startup census reports it -- but nothing fixed it.

WHY THE PRODUCER MISSED IT

impacted_session_ids in _resolve_session_graph is {session_id} U
resolved_child_ids U reextract_invalidated_ids U invalidated_session_ids.
Identity resolution only ever revisits UNRESOLVED edges, so an already-resolved
child is in none of those sets and the in-write repair skipped exactly the
child the write had just stranded. A replaced parent that dropped a
branch-point message has no outbound link, no unresolved inbound edge and a
current root projection, so the write took the fast path.

THE ANCHOR IS THE RIGHT KEY, NOT THE EDGE'S PARENT

branch_points_anchored_in_session looks children up by the branch point's own
namespace rather than by resolved_dst_session_id. A child that branched inside
its parent's INHERITED prefix pins an ancestor-owned message id, so keying on
"this parent's inbound children" -- the obvious reading -- never names it.

Whatever the repair can re-resolve is repaired in the same write. Whatever it
cannot is a real loss: the branch-point message has no counterpart anywhere in
the replacement transcript, so no edge rewrite recovers the child's inherited
prefix. Those children are recorded as retryable convergence debt. The edge
KEEPS its composing status on purpose -- that is what keeps the read reporting
dangling_branch_point and the census counting it. Quarantining would drop the
edge out of composition and the child would read as a COMPLETE bare tail, which
is the silent-truncation failure this campaign has been removing.

THE LOOKUP RUNS ON EVERY SESSION WRITE, SO IT IS INDEXED

Measured on the live index shape (23,496 sessions, 9,497 edges): 0.617 ms per
write as a session_links scan -- 14.5 s of full-corpus replay, growing as
sessions x edges -- against 0.0053 ms as an indexed range probe over the new
partial index idx_session_links_branch_point, or 0.12 s across the replay.

VERIFICATION: devtools verify --quick exit 0, all gates. devtools render all
--check exit 0, zero "out of sync". devtools test
tests/unit/storage/test_lineage_normalization.py -- 53 passed.

CLOSURE: write.py and index.py are both IN, so the derived index identity moves
and this must land before a fresh rebuild starts, never during one. The index
addition is index-only on the rebuildable index tier, so it needs no migration.

RESIDUAL, reproduced and NOT fixed: a grandparent re-parse that relocates an
anchor THROUGH an intermediate parent. Writing ggp/gp/parent/child where child
branches at gp:n:m1, then re-acquiring gp with a parent claim, leaves the child
composing ['x2'] instead of ['m0','m1','x2']. Every piece resolves correctly in
isolation -- the anchor lookup finds the child, the identity suffix is n:m1, and
the replacement resolves to ggp:n:m1 -- but the in-write repair does not apply
it. Two candidate causes were implemented and both REVERTED because neither made
the case pass: deriving the suffix from the anchor's own owner rather than the
resolved parent, and clearing the composed-signature memo before the repair.
Landing untested speculative code would be worse than naming the gap. The case
belongs to polylogue-gy2yu and the reproduction is recorded there.

Advances polylogue-gy2yu.

Co-Authored-By: Claude Opus 5 (1M context) [email protected]
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

A parent full-replace that drops or relocates a branch-point message left its
already-resolved prefix-sharing children composing to their own divergent tail,
with no corrector of any kind. PR #5372 made that state VISIBLE -- the daemon
startup census reports it -- but nothing fixed it.

WHY THE PRODUCER MISSED IT

impacted_session_ids in _resolve_session_graph is {session_id} U
resolved_child_ids U reextract_invalidated_ids U invalidated_session_ids.
Identity resolution only ever revisits UNRESOLVED edges, so an already-resolved
child is in none of those sets and the in-write repair skipped exactly the
child the write had just stranded. A replaced parent that dropped a
branch-point message has no outbound link, no unresolved inbound edge and a
current root projection, so the write took the fast path.

THE ANCHOR IS THE RIGHT KEY, NOT THE EDGE'S PARENT

branch_points_anchored_in_session looks children up by the branch point's own
namespace rather than by resolved_dst_session_id. A child that branched inside
its parent's INHERITED prefix pins an ancestor-owned message id, so keying on
"this parent's inbound children" -- the obvious reading -- never names it.

Whatever the repair can re-resolve is repaired in the same write. Whatever it
cannot is a real loss: the branch-point message has no counterpart anywhere in
the replacement transcript, so no edge rewrite recovers the child's inherited
prefix. Those children are recorded as retryable convergence debt. The edge
KEEPS its composing status on purpose -- that is what keeps the read reporting
dangling_branch_point and the census counting it. Quarantining would drop the
edge out of composition and the child would read as a COMPLETE bare tail, which
is the silent-truncation failure this campaign has been removing.

THE LOOKUP RUNS ON EVERY SESSION WRITE, SO IT IS INDEXED

Measured on the live index shape (23,496 sessions, 9,497 edges): 0.617 ms per
write as a session_links scan -- 14.5 s of full-corpus replay, growing as
sessions x edges -- against 0.0053 ms as an indexed range probe over the new
partial index idx_session_links_branch_point, or 0.12 s across the replay.

VERIFICATION: devtools verify --quick exit 0, all gates. devtools render all
--check exit 0, zero "out of sync". devtools test
tests/unit/storage/test_lineage_normalization.py -- 53 passed.

CLOSURE: write.py and index.py are both IN, so the derived index identity moves
and this must land before a fresh rebuild starts, never during one. The index
addition is index-only on the rebuildable index tier, so it needs no migration.

RESIDUAL, reproduced and NOT fixed: a grandparent re-parse that relocates an
anchor THROUGH an intermediate parent. Writing ggp/gp/parent/child where child
branches at gp:n:m1, then re-acquiring gp with a parent claim, leaves the child
composing ['x2'] instead of ['m0','m1','x2']. Every piece resolves correctly in
isolation -- the anchor lookup finds the child, the identity suffix is n:m1, and
the replacement resolves to ggp:n:m1 -- but the in-write repair does not apply
it. Two candidate causes were implemented and both REVERTED because neither made
the case pass: deriving the suffix from the anchor's own owner rather than the
resolved parent, and clearing the composed-signature memo before the repair.
Landing untested speculative code would be worse than naming the gap. The case
belongs to polylogue-gy2yu and the reproduction is recorded there.

Advances polylogue-gy2yu.

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

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 12 minutes.

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: 5a38d1f0-32fc-4722-85a3-d4ba07669acb

📥 Commits

Reviewing files that changed from the base of the PR and between 93b003a and 95c25ce.

📒 Files selected for processing (3)
  • polylogue/storage/sqlite/archive_tiers/index.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • tests/unit/storage/test_lineage_normalization.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 21, 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-22T00:08:44.457426Z 95c25ce PR opened
🔒 Security Review ✅ Completed 2026-09-22T00:08:44.424862Z 95c25ce 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 enabled auto-merge (squash) September 21, 2026 23:55

@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: 95c25cecc1

ℹ️ 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 5fc4119 into master Sep 22, 2026
3 checks passed
@Sinity
Sinity deleted the fix/stranded-lineage-child branch September 22, 2026 00:09
Sinity added a commit that referenced this pull request Sep 27, 2026
## Summary

- `mark --tag-remove` through the daemon was refused on every route.
`mutate-remove-tag` now admits the `api` and `cli` surfaces, matching
its add counterpart.
- Adds an end-to-end test proving that a child stranded by a parent
re-parse is recomposed by the `lineage_prefix_recompose` debt stage.

## Problem

`mutate-remove-tag` declared no `allowed_surfaces`.
`_declare_executor_authority` therefore back-filled it as API-only, and
`MutationTransaction.prepare_bound` raised `SurfaceDeniedError` for the
`cli` principal. The CLI removal payload of `mutation.session.tag`
lowers onto exactly that per-target actuator, so every CLI tag removal
failed. The add payload lowers onto `mutate-bulk-tag-sessions`, which
admits `api` and `cli`. That asymmetry survived because the daemon write
test drove only the add payload.

The lineage half of this PR adds no production code. A parent full
replace that drops a child's branch-point message has, since #5376,
recorded `lineage_prefix_recompose` debt, and the stage re-derives the
child from its retained raw. No test drove that debt through the drain
for this loss, only for the identity-alias loss.

## Solution

- `polylogue/operations/specs.py`: `mutate-remove-tag` declares
`allowed_surfaces=("api", "cli")`.
- `tests/unit/daemon/test_http_write_coordination.py`: a real-daemon
test adds a tag and then removes it through `mutation.session.tag`. It
asserts two `mutate-remove-tag` operation runs under the `cli` surface.
Anti-vacuity: deleting the declaration makes the removal fail with
`SurfaceDeniedError`.
- `tests/unit/daemon/test_convergence_debt.py`: seeds a two-link Codex
lineage and replaces the parent through the writer with its branch-point
message under a new native id. It asserts that the child is stranded
with one debt row, drains once, and asserts that the child's composed
transcript is complete again and the row is cleared.

## Verification

- `devtools test tests/unit/daemon/test_http_write_coordination.py
tests/unit/daemon/test_convergence_debt.py
tests/unit/operations/test_specs.py
tests/unit/api/test_facade_mutation_census.py
tests/unit/mcp/test_privileged_tools.py` → 82 passed, 35 failed.
- All 35 failures are in `test_privileged_tools.py` and
`test_facade_mutation_census.py`. The same two files on clean
`origin/master` give 41 passed, 35 failed, so none come from this PR.
They are the facade's `FacadeDaemonRequiredError` route and the pinned
facade inventory.
- `devtools verify --quick` → `verify: PASSED exit=0`

## Residuals

- `polylogue/operations/specs.py` is inside the derived schema-identity
closure, so this must land before a fresh rebuild starts.
- The 35 pre-existing failures above are not addressed here.

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

https://claude.ai/code/session_013Vn4qhKjhyaVBG4aPiqNW4

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@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 ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

@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 64a9bd0):

  • P1 polylogue/storage/sqlite/archive_tiers/write.py:5974: Fixed on master (checked at 64a9bd0): _repair_stale_prefix_branch_points_db now refuses a reanchor whose replacement message's content address disagrees with the stored witness (write.py:12318-12328). The edge stays in the dangling-branch-point census.

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 0914f89):

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.

  • 76.F012 / P1: fixed-already at the checked revision: Lineage retry debt resolves ops.db with archive_root_for_index_path, so a promoted physical index generation no longer redirects debt to a nonexistent generation-local ops.db. See polylogue/storage/sqlite/archive_tiers/write.py:13832.

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