Skip to content

feat(topology): resolve hook-vs-inference parent conflicts on the write path - #4022

Merged
Sinity merged 6 commits into
masterfrom
feature/topology/hook-authority-conflict
Aug 19, 2026
Merged

Sinity merged 6 commits into
masterfrom
feature/topology/hook-authority-conflict

Conversation

@Sinity

@Sinity Sinity commented Aug 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Topology edges now resolve a disagreement between acquired Codex hook evidence and transcript inference instead of letting both claims coexist unmarked. Hook evidence wins, the overruled inference is retained under a new typed exclusion status rather than deleted, an inference-only re-parse can no longer overwrite or erase the authoritative result, and an archive-verification check censuses the outcome. Absent hook evidence, every edge is byte-identical to today.

Problem

polylogue-foee acquired Codex thread_spawn_edges into the durable source.db hook spool as codex_thread_spawn_edge events (3,055 title + 1,030 spawn-edge rows live). Nothing consumed them for topology. The only artifact was context/codex_spawn_edge_correlation.reconcile_codex_spawn_edges — a read-only counter reachable solely through the API facade.

That counter cannot express the problem it appears to address. It computes set differences over (parent, child) pairs, so a genuine contradiction — hook evidence and inference naming different parents for the same child — surfaces as one entry in inferred_only and one in authoritative_only, losing the fact that the two claims compete. authoritative-hook-evidence, the method token polylogue-4ts.10's design doc anticipated, had zero occurrences anywhere in the tree.

Three structural facts made this worse than a missing feature:

  1. Contradictions coexisted silently. session_links' primary key is (src_session_id, dst_origin, dst_native_id, link_type), so two contradictory parents are two rows, not an overwrite. Both resolved, and _refresh_session_projection then picked one by observed_at_ms ordering — an arbitrary, arrival-order-dependent parent with no recorded decision.
  2. A re-parse silently downgraded evidence. _write_session_link used a bare INSERT OR REPLACE, which rewrites every column of a matching key, resetting method and status.
  3. A full replace destroyed it outright. The session purge ran DELETE FROM session_links WHERE src_session_id = ? unconditionally, so an ordinary re-parse deleted an authoritative edge and — with no source handle to re-derive it — silently reinstated the inferred parent. This is the most destructive form of the hole and the one a write guard alone would not have caught; it surfaced only when a red twin failed.

Design

Where authority is applied: the write path, because of tier durability. I evaluated a post-ingest reconciliation pass — where reconcile_codex_spawn_edges already lives, holding both connections — and rejected it. session_links is in the rebuildable index tier while hook evidence is in the durable source tier, so every reindex reconstructs these rows from scratch. Only a derivation running inside write_parsed_session_to_archive — the choke point shared by live incremental ingest and full raw replay — survives a rebuild by construction. A convergence-stage applier would silently lose the marking on the next reindex, which is disqualifying for a reindex-readiness campaign.

source_conn is threaded in as an optional parameter, mirroring revision_authority_refuses_write(conn, source_conn, ...) (ingest_precedence.py:145) including its None case for index-only harnesses. ArchiveStore supplies it via a new _optional_source_conn() that degrades to None rather than failing a session write.

What "conflict" precisely is. Scoped to (src_session_id, link_type), not to the primary key — because the PK carries dst_native_id, keying conflict to it would define the contradiction out of existence. Given child C and link type T: the hook claim is the parent_thread_id whose codex_thread_spawn_edge payload names C as child; the parser claim is session.parent_session_provider_id. Agreement upgrades the single edge to authoritative-hook-evidence. Disagreement is a conflict. Hook silence is not a conflict — absent evidence is silence, which is why the no-evidence path is provably unchanged.

Note the child-side lookup cannot use list_hook_events(session_native_id=...): codex_state_evidence.py keys these events by session_native_id = parent_thread_id, so the query matches the payload's own child_thread_id.

What the durable conflict state looks like. TopologyEdgeStatus gains a member, AUTHORITY_CONTRADICTED ("authority-contradicted"). The losing edge is retained with that status and method = 'contradicted-by-hook-evidence', its evidence_json carrying both parents; the winner is written with method = 'authoritative-hook-evidence'.

A distinct member rather than reusing QUARANTINED is the point, not an accident. Both statuses exclude an edge from composition, but they are different defects and must stay tellable apart forever: a quarantine is a structural cycle-break (the graph SHAPE is wrong), while an authority contradiction is a provenance verdict (the shape is fine; this particular claim was overruled). An operator triaging a live archive needs that distinction, and method is an unconstrained TEXT column that cannot carry it safely — exactly the hand-written-vocabulary drift this repo warns against. Both members are documented beside each other in TopologyEdgeStatus.

The obstacle a new member normally creates, removed rather than accepted. Eleven exclusion sites across seven modules each hardcoded 'quarantined'. Adding an exclusion class to that arrangement means finding and updating every one, and any miss silently readmits an excluded edge into lineage. The predicate is now generated: COMPOSITION_EXCLUDED_TOPOLOGY_STATUSES is the single definition, rendered by topology_status_composes_sql() / topology_status_excluded_sql() for SQL and status_excludes_composition() for the Python-side filter that has no query to attach to.

Amended claim. An earlier revision of this body said eight sites and that a future exclusion class is "picked up by every consumer for free". Both were wrong, and I found the first one myself before review by re-running my own sweep with the scope I should have used originally — my search covered polylogue/storage/** and missed devtools/ and polylogue/operations/. Cold review then found two more I had still missed. The corrected set is eleven, and the "for free" claim only holds for consumers that read the shared definition — which is now all of them, but was not when the sentence was written. The three sites added in this revision:

  • storage/insights/topology/derivation.py:80 — a Python-side status == "quarantined" filter. Because a contradicted edge is unresolved by construction, 100% of them were readmitted here.
  • insights/transforms.py:77,1791 — SubagentChildLinkStatus' four-value allowlist mapped every contradicted edge to None ("no link status") rather than to a reason.
  • operations/daemon_workload_probe.py:1925-1942 — the CASE buckets by raw status, so contradicted edges already had their own bucket; it was simply never read out, so census counts stopped summing to the table.

REPAIRED is deliberately absent from the excluded set: a repaired edge was fixed, so it composes.

4ts.10 anticipated authoritative-hook-evidence as a method token only; that is implemented, plus the contradiction token and status member it did not anticipate, because a method alone can neither exclude an edge from composition nor be constrained.

Schema. The CHECK on session_links.status is generated from the enum (nullable_check("status", TopologyEdgeStatus)), so the new member is a DDL change: INDEX_SCHEMA_VERSION 67 → 69 with an IndexDeltaDeclaration of SEMANTIC_REPARSE. Widening the CHECK is inert for existing rows, but the new state is only produced by re-deriving edges against the durable hook spool during raw replay — an existing generation cannot fast-forward into it, and its lineage projections would keep composing through parents the hook evidence overrules. CONSTRAINT_ONLY would have been the cheap and dishonest call.

Version-number coordination — resolved. #4015 merged (squash ca466345) taking 68; this PR is rebased onto that master and takes 69. lab policy schema-versioning now reports "Schema evolution policy intact." and the three lifecycle tests that previously failed on the gap are green.

What does NOT change: lineage composition semantics, prefix-dedup, branch_point_message_id/inheritance (including the deliberate non-FK), cycle quarantine, and every edge in an archive with no hook evidence.

Surfacing. A new hook-authority-topology-conflict registry check censuses contradictions. Contradictions themselves are reported as observability, not errors — recording them is the mechanism working. The single error condition is a contradicted edge with no authoritative sibling for the same child, which would mean inference was demoted by nothing.

Verification

Lane /realm/worktrees/hook-authority-conflict, guard-verified; devtools test reported polylogue package → /realm/worktrees/hook-authority-conflict/polylogue/__init__.py.

devtools test tests/unit/storage/test_topology_hook_authority_conflict.py \
              tests/unit/maintenance/test_archive_verification.py
  -> 134 passed in 32.74s

devtools test <7 topology/lineage/delegation/correlation suites> \
              tests/unit/storage/test_archive_tiers_write.py \
              tests/unit/pipeline/test_ingest_batch.py
  -> 265 passed in 30.63s   (pre-existing behaviour unchanged across the
                             generated exclusion predicate)

devtools lab policy schema-versioning
  -> "Schema evolution policy intact." (0 undeclared index schema deltas)

devtools verify --quick
  -> exit 0, zero "out of sync"

Red twins

Each guard was mutated and shown to fail the test that claims it.

Mutation Result
Drop the contradiction branch (hook stops winning) 3 failed
Restore INSERT OR REPLACE (authority downgradable in place) 1 failed — test_reparse_cannot_downgrade_authoritative_evidence
Remove the purge exemption (full replace wipes authority) 1 failed — same test
Mark edges unconditionally (no-evidence path diverges) 3 failed — both byte-identical cases

| Two authoritative parents for one child | 1 failed — test_two_authoritative_parents_for_one_child_trips_the_check |

Retracted row, and what replaced it. An earlier revision of this table claimed that dropping AUTHORITY_CONTRADICTED from COMPOSITION_EXCLUDED_TOPOLOGY_STATUSES produced "1 failed, 6 errors". Cold review could not reproduce it; I re-ran the identical mutation and got 7 passed, after dumping the generated predicate to confirm the mutation genuinely reached it (NOT IN ('quarantined')). The original figure was almost certainly captured mid-edit, before the enum member existed — 1 + 6 equals the file's test count, which is the signature of a collection failure, not a detection. The row is withdrawn.

The reviewer's mechanical explanation is correct and is now documented in the code: _resolve_outbound_session_links' pre-existing status IS NULL gate is the operative mechanism. A contradicted edge never acquires resolved_dst_session_id, so composition cannot traverse it regardless of the exclusion set; membership in that set is defense-in-depth for an edge that resolved before acquiring a status (the cycle-quarantine path does exactly that). No test can distinguish its presence from absence today, so no twin should claim otherwise.

The genuine pin is test_contradicted_edge_is_excluded_from_composition, which asserts the invariant at the layer that enforces it: the contradicted edge stays unresolved and the child's composed parent is the hook's parent.

The registry check carries its own red twins, test_contradiction_without_authoritative_winner_trips_the_check and the multi-authoritative one above, plus a positive control asserting a properly resolved contradiction reports OK.

The third mutation is the one worth noting: it was not a planned twin. test_reparse_cannot_downgrade_authoritative_evidence failed on first run with KeyError, because the authoritative row was gone rather than downgraded — which is how the unconditional purge was found. The fix mirrors the exemption three lines above it in the same function, where capture_gap events are already spared as "archive-generated ingest evidence, not projections owned by whichever parser payload currently wins source precedence." Hook evidence is the same category.

Gate substitution

Per coordinator policy, the plain full devtools verify was not run. Checked rather than assumed: this lane's testmon environment digest is polylogue-a8fac865... and the graph lane-init seeded from the main checkout carries five environments, none matching — a plain verify would have been a bootstrap (absent) full run. Notably this is the same digest a previous lane computed, so the mismatch is systematic across lanes rather than per-lane. The focused runs above cover every changed module, and --quick gates format, lint, strict mypy, layering, schema-versioning, and all generated surfaces.

Bead disposition

This PR closes no bead and mutates no bead record; the carrier below is the typed self_contained scope.

Bead Disposition Residual
polylogue-hook-authority-conflict-proof partial — mechanism built The AC's resolution + anti-overwrite semantics now exist and are tested through the production write path. The bead is an acceptance bead: it wants the effect proven against a frozen source or candidate generation with an immutable receipt. No live or candidate run is claimed here.
polylogue-foee (closed) AC2 consumer built Its topology consumer now exists and prefers authoritative edges. Its "report how many previously-inferred edges are now backed by authoritative evidence" reporting is served by the new registry check's contradicted_count/authoritative_count evidence. The title-ladder wiring (AC1) and live UUID-title census (AC3) are untouched.

Ref polylogue-hook-authority-conflict-proof, polylogue-foee, polylogue-4ts.10

Not in scope

  • No live/candidate census run — the acceptance bead's own requirement, and it needs the reindex window.
  • Codex-only. The mechanism keys on codex_thread_spawn_edge; no other origin currently acquires authoritative topology evidence. The guard generalizes, but claiming provider-neutrality would overstate what is wired.
  • reconcile_codex_spawn_edges is untouched by deliberate scope guard; its disposition is later bookkeeping. It remains a useful read-only correlation counter, and its inability to detect same-child contradictions is documented above rather than fixed, since the write path now records that state directly.
  • No title-ladder work (polylogue-foee AC1).

@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 Aug 19, 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 63895e43-f156-4401-a509-3d43a7557690


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.

Sinity added 5 commits August 19, 2026 08:48
…te path

Ref polylogue-hook-authority-conflict-proof, polylogue-foee
…class

Ref polylogue-hook-authority-conflict-proof
…g-state gaps

Convert the three remaining composability sites to the shared exclusion
predicate, supersede a stale authoritative edge when hook evidence revises
itself, project the real status through the delegation mapping vocabulary,
and pin composition exclusion at the resolver that actually enforces it.

Ref polylogue-hook-authority-conflict-proof, polylogue-foee, polylogue-0ai7p
@Sinity
Sinity force-pushed the feature/topology/hook-authority-conflict branch from 69e84cf to 656968d Compare August 19, 2026 06:54
@Sinity
Sinity merged commit a9bf501 into master Aug 19, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/topology/hook-authority-conflict branch August 19, 2026 08:02
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