Skip to content

fix(storage): land verified worker-5 archive, anchor and profile fixes - #5790

Merged
Sinity merged 8 commits into
masterfrom
fix/codex-debt-w5-storage
Sep 29, 2026
Merged

Sinity merged 8 commits into
masterfrom
fix/codex-debt-w5-storage

Conversation

@Sinity

@Sinity Sinity commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Lands the real fixes from the worker-5 pass over storage Codex review debt (beads polylogue-1tyq5.98, .99, .100, 75 findings). 28 findings are fixed here with production-route regressions. 13 were already fixed on master, 8 are stale, 2 are refuted and 24 were not reached. Every kept fix was re-checked against current master. None of the cited or touched storage files changed on master after the salvage base ab28700c1b, and the later master merge touched none of this PR's files.

Problem

Each defect below was confirmed on master by a regression test that fails against master's production code (revert-proof job 2488):

  • Archive location and tuples. A root named .index-generations resolved to its parent. Local ops/embeddings tiers refused a durable symlink farm. The tuple manifest loader normalized unknown, missing and coerced fields before recomputing the seal, and it admitted a sealed obsolete schema fingerprint. An inactive destination could be a symlink or hard link to a foreign database, which SQLite then initialized; this happened both through bootstrap and through embedding preparation. A forged destination generation passed when the caller gave no hint. A replaced audit.db escaped the authority digest. Neither new directory entry was fsynced. Any root that merely contained .archive-tuples was refused.
  • Readiness. With a zero denominator the result was UNMEASURED even when blocking evidence loss had been measured.
  • Block anchors. Relocation followed NULL-inheritance edges. A private 512-node composer hid blocks that production reads expose. It also bound one SQL variable per transcript message, returned the first sibling match instead of ambiguous, and skipped same-session drift when the anchored message had vanished.
  • Profiles and status. selected_part_facts reported valid while ordinary inspection reported stale under pending demand. A session missing only its latency sibling was never rediscovered. Sync hydration dropped direction/producer_ref. A shared dependency superset zeroed run_count on archives that lacked session_events.
  • Lineage and topology. A compact-lineage page with node_limit=1 could not advance past the seed. siblings() listed a child once per evidence edge. An unrelated component's cycle or conflict flagged a healthy topology.
  • Markers, embeddings and FTS. One accepted-marker convergence sweep delivered one batch and stopped. Reordered request options changed the recipe hash, and non-float32 recipes produced usable-looking contracts. A failing owned COMMIT in FTS repair ran outside rollback protection and left the transaction open.

Solution

  • archive_identity.py: the innermost generations marker owns the path. Symlink-farm admission counts only the source, user and audit tiers.
  • archive_tuple_location.py: exact manifest key and type validation before the seal. Schema fingerprints must equal the running writer's. The final tier entry must be absent or an unshared regular file (lstat, st_nlink == 1). The destination generation must equal the manifest's. The live location is re-resolved and the audit identity rechecked. Both new directory entries are fsynced. Only .archive-tuples/tuple-<id> marks a candidate path. The unused whole-tuple expected_tier is removed; single-tier writers keep it on validate_inactive_destination.
  • archive_readiness.py: positive blocking counts are evaluated before the zero-denominator return.
  • block_anchor.py: the private composer and its cap are deleted. Relocation walks every prefix-sharing and spawned-fresh neighbour once and collects the distinct own physical rows that match the hash. Each query binds two values. More than one match is ambiguous. Same-session drift is checked before lineage, even when the message is gone.
  • derivation.py: required-page discovery includes sessions missing a latency sibling. Selected facts use the demand-aware classifier.
  • rebuild.py: the sync loader selects and hydrates the attachment provenance columns. The input_binding.py exclusion reasons are updated to match.
  • status.py: each run projection declares exactly the relations its own body reads.
  • compact.py: the seed rides every page outside the node_limit budget.
  • topology.py, topology/derivation.py: siblings are deduplicated as nodes, while evidence edges stay on edges. Cycle and conflict flags come from the returned edges.
  • marker_domain.py: required_page returns the head as its continuation, and it ends the sweep when the head has not moved (held or failed). One pass drains every committed batch without looping on or overtaking a held head.
  • embeddings/identity.py: request options are sorted and duplicate keys refused; only float32 output is accepted. Production recipes carry no options, so no stored recipe hash or vector address moves.
  • fts_lifecycle.py: the owned COMMIT moves inside the rollback guard.

Derived-identity closure

This PR is identity-moving: it must land before the fresh rebuild, never mid-run. It touches 12 members of the committed closure baseline (docs/plans/schema-closure-baseline.json, unchanged; the schema-closure gate passed):
polylogue/analysis/topology.py, polylogue/storage/archive_identity.py, polylogue/storage/archive_readiness.py, polylogue/storage/archive_tuple_location.py, polylogue/storage/derived/lineage/compact.py, polylogue/storage/derived/session/{derivation,input_binding,rebuild,status}.py, polylogue/storage/derived/topology/derivation.py, polylogue/storage/embeddings/identity.py, polylogue/storage/fts/fts_lifecycle.py.
Not in the closure: polylogue/storage/block_anchor.py, polylogue/storage/derived/session/marker_domain.py.

Verification

All checks ran as AgentCTL jobs on this worktree; nothing ran in-process.

  • agentctl job start polylogue verify_quick --workspace /realm/worktrees/salvage-w5 returned job 2686 on head 2136284cf0: verify: PASSED exit=0 (all gates, including schema-closure, layering and mypy).
  • agentctl job start polylogue pytest_focused --workspace /realm/worktrees/salvage-w5 -- <36 test modules covering every changed module and its consumers> returned job 2687 on 2136284cf0: 855 passed, 3 failed, 1 error. The 3 failures and the error are test_archive_readiness::test_pinned_materialization_readiness_degrades_like_its_path_twin, test_read_view_operations::test_lineage_and_topology_use_the_pinned_graph_engines, test_session_partition_convergence::test_the_partition_input_columns_are_projected_or_declared_excluded, and a descriptor-leak teardown error in test_event_order_permutations_converge_to_the_same_relation. All four fail identically on master 1beb2e516a (job 2643) and are untouched by this PR.
  • Revert proof: the new regression tests ran on a master checkout (1beb2e516a, production code unchanged) in job 2488: 38 failed in 273.95s, which is every named regression. The rebuilt deep-anchor test then ran alone in job 2685 and failed on the assertion (message_id not found in the named session or its lineage neighborhood) in 10.6 s. On this branch it passes (job 2684, 22 passed).
  • Hosted: ci/circleci: quick-gate and stacked-review-threads gate the merge.

Self-review

  • Sibling sites. The final-entry link check sits in validate_inactive_destination, the one gate that bootstrap, embedding preparation and whole-tuple validation all call. The COMMIT-outside-try pattern also occurs in fts_invariant_snapshot_sync, but that closes a read-only snapshot transaction whose COMMIT cannot lose writes, so it is left as it is. The FTS derivation writers (fts/derivation.py) already commit inside their guard. The status dependency map was re-derived for all three run projections from the tables their SQL actually reads.
  • Cancellation, shutdown and loops. The marker page loop cannot spin. The kernel rejects a continuation it has already visited, and required_page returns no keys and no cursor once the head stops moving. The anchor neighbourhood walk visits each session once through a visited set, and it terminates on cycles.
  • Unbounded reads. The anchor walk is now bounded by the lineage component rather than by an arbitrary 512-node cap, which had produced wrong missing answers. Each step is one indexed edge query and one two-bind hash query. Removing the per-transcript IN list removes the only unbounded bind list.
  • Fail-open fallbacks. The manifest loader no longer defaults a missing state to inactive. Readiness no longer lets a zero denominator mask measured loss. Anchors refuse on ambiguity and never pick the first match.
  • Compatibility shims. There are none. The removed expected_tier parameter had no caller, and mypy (verify_quick) proves none remains. The float16 case was removed from test_embedding_request_identity.py because that element type is now refused.
  • Removed symbols still referenced. _MAX_LINEAGE_SEARCH_NODES, _prefix_edge, _composed_message_ids and _hash_matches_in_composed_session have no remaining references in code, tests or monkeypatch targets (grep, plus the mypy gate).
  • Tests on the production route. The regressions drive initialize_archive_database, prepare_inactive_embedding_generation, ArchiveTupleAllocator.load, resolve_block_anchor over write_parsed_session_to_archive data, converge() over a real derivation registry, load_sync_batch + hydrate_sessions, session_insight_status_sync, and repair_message_fts_index_sync with a real SQLite authorizer denying the first COMMIT. The 520-deep anchor test asserts that the cited session's read_archive_session_envelope really contains the block. Every named test fails on master (job 2488).

Per-finding dispositions

key disposition evidence test
98.01 fixed archive_identity innermost marker A::test_generation_root_uses_the_final_index_shape
98.02 fixed farm admission over durable tiers A::test_durable_symlink_farm_allows_local_disposable_tiers
98.03 fixed-already archive_readiness.py:798,1167 attach_readonly_database —
98.04 fixed blockers before zero denominator A::test_zero_denominator_does_not_erase_measured_evidence_loss
98.05 fixed-already archive_readiness.py:1886 attach_readonly_database —
98.06 fixed exact manifest shape before seal A::test_tuple_loader_rejects_unsealed_manifest_shape_changes
98.07 fixed fingerprints equal running writer A::test_tuple_loader_rejects_a_sealed_obsolete_schema
98.08 fixed unshared regular final entry A::test_inactive_writer_refuses_foreign_final_file_links
98.09 fixed generation bound to manifest A::test_destination_generation_must_match_its_manifest_without_a_caller_hint
98.10 fixed live re-resolve + audit identity A::test_tuple_writer_rechecks_audit_identity_after_allocation
98.11 fixed whole-tuple expected_tier removed (no caller; mypy) — (removed parameter)
98.12 fixed fsync archive root and tuples root A::test_allocation_fsyncs_both_new_directory_entries
98.13 fixed typed tuple-<id> child required A::test_reserved_name_alone_is_not_an_inactive_tuple
98.14 not reached — —
98.15 fixed-already blob_gc.py:235,258 catch SchemaSkewError —
98.16 fixed-already blob_gc.py:438-444 fsync marker + dir —
98.17 fixed-already blob_gc.py:497 64-hex check —
98.18 refuted pre-reset index as GC authority is forbidden legacy authority —
98.19 not reached — —
98.20 fixed-already blob_gc.py:1352-1355 marker only when not dry_run —
98.21–98.24 not reached — —
98.25 stale _write_jsonl_rows removed in e20f6f5 (#5680) —
99.01, 99.02 stale writer removed in e20f6f5 (#5680) —
99.03 fixed-already blob_integrity.py:1262 subtracts unowned —
99.04 stale no generation-scoped projection remains —
99.05–99.07 not reached — —
99.08 fixed only classified inheritance edges L::test_anchor_does_not_relocate_through_an_unclassified_edge
99.09 fixed private capped composer deleted L::test_anchor_relocation_reaches_an_ancestor_beyond_the_former_search_cap
99.10 fixed two binds per lookup L::test_anchor_hash_lookup_does_not_bind_every_transcript_message
99.11 fixed drift before lineage for a vanished message L::test_anchor_relocates_locally_after_its_original_message_disappears
99.12 fixed all distinct matches before uniqueness L::test_anchor_refuses_two_distinct_sibling_hash_matches
99.13 not reached — —
99.14 fixed-already iterative walk landed in df70214 (#5685); worker rewrite dropped —
99.15 fixed seed outside page budget test_compact_lineage.py::test_one_node_pages_advance_past_the_seed
99.16–99.18 not reached — —
99.19 stale plan-no-progress path gone —
99.20, 99.21 not reached — —
99.22 fixed demand-aware selected facts P::test_selected_profile_facts_do_not_certify_pending_demand
99.23 fixed latency sibling in discovery P::test_required_profile_page_recovers_a_missing_latency_sibling
99.24, 99.25 not reached — —
100.01 not reached — —
100.02 fixed head as continuation; stop on unmoved head test_accepted_marker_consumer.py::test_one_convergence_sweep_delivers_every_accepted_marker_batch
100.03 stale per-session marker-set cursor gone —
100.04 fixed-already applied_sequence + expected_prior_sequence in BEGIN IMMEDIATE —
100.05 fixed provenance through sync loader P::test_sync_hydration_preserves_stored_attachment_provenance
100.06, 100.07 fixed-already rebuild retires absent families; revision-matched acks —
100.08 stale thread-row stamping gone —
100.09 refuted retaining removed fields is a forbidden compatibility path —
100.10 fixed per-projection dependencies P::test_status_counts_runs_without_unrelated_product_tables
100.11 fixed siblings deduplicated as nodes L::test_topology_siblings_are_nodes_not_duplicate_evidence_rows
100.12 fixed flags from returned edges L::test_topology_fault_flags_are_scoped_to_the_returned_component
100.13–100.15 not reached — —
100.16 fixed-already generations.py:759 contract before child —
100.17 fixed options sorted, duplicates refused C::test_equal_provider_requests_have_equal_recipe_identities
100.18 fixed float32 only C::test_embedding_recipe_refuses_unimplemented_output_encodings
100.19–100.21 not reached — —
100.22 fixed shared final-entry check via embedding preparation A::test_embedding_preparation_rejects_a_foreign_final_symlink
100.23 fixed COMMIT inside rollback guard C::test_fts_owned_commit_failure_rolls_back_and_allows_retry
100.24 fixed-already index_generation.py:892,949 restore predecessor —
100.25 stale commit_candidate_membership removed in 0b1e99d (#5336) —

A = tests/unit/storage/test_archive_location_admission.py, L = test_block_anchor_lineage_and_topology.py, P = test_profile_selection_and_hydration.py, C = test_embedding_recipe_and_fts_commit.py.

Counts: .98 11 fixed / 6 fixed-already / 1 stale / 1 refuted / 6 not reached. .99 8 / 2 / 4 / 0 / 11. .100 9 / 5 / 3 / 1 / 7.

Residuals

  • 24 findings are not reached and remain open on their beads.
  • The link check on the final entry is a pre-open lstat. A process that swaps the entry between the check and SQLite's open is outside the single-writer contract.
  • The anchor neighbourhood walk costs grow with the size of the lineage component; the walk is not capped, because a cap produced wrong answers.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

Sinity and others added 8 commits September 29, 2026 04:53
Resolve the rebase onto the lineage depth-cap removal (#5685), keeping
only the seed-free lineage pagination. Recover the archive root from the
innermost generations marker, drop the unused whole-tuple expected_tier
parameter, fix the status dependency map (the spine is not a presence
key), relocate anchors by matching own physical rows across the whole
neighbourhood instead of a second composer, and name the test modules
by behaviour.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
The embedding recipe now refuses any element type other than float32,
so the address-stability test no longer lists float16 as a label field.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
The 521-session chain spent its 120 s timeout on per-session commits to
disk, so the test timed out in setup on both the fix and master. In
memory it runs in seconds, and master now fails on the assertion (the
capped resolver answers "missing") instead of on the clock.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
@Sinity Sinity changed the title fix(storage): address worker 5 Codex review debt fix(storage): land verified worker-5 archive, anchor and profile fixes Sep 29, 2026
@Sinity
Sinity marked this pull request as ready for review September 29, 2026 09:42
@Sinity
Sinity enabled auto-merge (squash) September 29, 2026 09:42
@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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 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
🔒 Security Review ✅ Completed 2026-09-29T09:49:48.728188Z 2136284 Draft marked ready
ℹ️ 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 543a038 into master Sep 29, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/codex-debt-w5-storage branch September 29, 2026 09:47
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