Repository navigation
fix(lineage): settle inherited prefixes through guard tables - #5803
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Sinity
added a commit
that referenced
this pull request
Sep 29, 2026
…#5809) ## Summary Realigns three tests in `tests/unit/storage/test_lineage_normalization.py` that fail on master (polylogue-ezvw3). Each one encodes a contract that a named PR changed deliberately. No production code changes. ## Problem At master 1beb2e5 (AgentCTL job 2441), these fail: - `test_prefix_sharing_child_provider_usage_keeps_its_own_reported_totals` (line 352). The child's `total_tokens`-only event (272 000) stores NULL input, cached and output totals, but the test expects 0. #5530 (904b2f8) replaced `_payload_int` with `_payload_optional_int` in `_provider_usage_event_row`, so an unreported lane now stays NULL. - `test_child_before_parent_reextracts_provider_usage_tail` (line 1730). The child rollup reads 0 instead of 130. The test put an all-zero cumulative tick after the child's 160/30/25 cumulative. #5530 also changed `_provider_usage_row_has_lane_totals` from "any non-zero" to "any present", and added `test_explicit_zero_cumulative_supersedes_prior_positive`. An explicit zero cumulative is now a measurement, and the latest one wins. - `test_late_parent_resolution_invalidates_child_derived_products` (line 873). The child is non-valid right after the test seeds a fresh profile. #5525 (ca25740) added trigger-captured `session_profile_demand`, and `_classify_partition_with_demand` reports a demanded session as stale until publication consumes the demand. The test's seed never consumed it. None of the suspects named on the bead (#5803, #5792, #5764, #5691) is the cause. #5803's PR body already lists these three as pre-existing failures. ## Solution - Prefix-sharing test: the `total_tokens`-only row now expects NULL input, cached and output totals. The docstring cites #5530. The rollup assertion (130/25/30) is unchanged, which proves the NULL row does not displace the latest lane totals. - Child-before-parent test: the same measured-zero tick, unchanged, now comes before the child's latest cumulative. The rollup stays exactly 130/25/30 before and after the parent arrives. The re-extraction assertion keeps both `cy` rows, including the tick's `request_id`, in their new order. A stale comment about the evidence predicate is corrected. - Late-parent test: `_seed_fresh_session_products` deletes the session's `session_profile_demand` row, as `publish_prepared_session_insight_partition` does. The docstring now says the retained-row assertion carries the anti-vacuity, because re-captured demand alone would also mark the child stale. Schema classification: none. No production file changes, so nothing enters the derived-identity closure. ## Verification - `agentctl job start polylogue pytest_focused --workspace /realm/worktrees/polylogue-mh-lineage -- tests/unit/storage/test_lineage_normalization.py` → job 2573: `devtools test: PASSED exit=0` (`105 passed` of 105, head 2d1d0a4). - `agentctl job start polylogue verify_quick --workspace /realm/worktrees/polylogue-mh-lineage` → job 2584: `verify: PASSED exit=0` (head 2d1d0a4). ## Self-review - **Contract, not bug.** For each failure I found the commit that changed the behavior and checked that it was intended. #5530's summary says "distinguish absent usage from explicit zero", and it added a test asserting that a zero cumulative supersedes a prior positive one. #5525 added the demand table, its triggers and the demand-aware classifier on purpose. No assertion was loosened. Every expected value is still exact. - **Anti-vacuity.** Test 1 would fail if re-extraction kept the `c1` row, dropped a `cy` row, or rebased the child against the parent. Test 2's NULL expectation fails if absent lanes are coerced to 0 again. Test 3's retained-row assertion fails if `_reextract_prefix_tail_db` stops deleting profiles. - **Siblings.** `_seed_fresh_session_products` has one caller. No other test in this file seeds profiles or reads partition status. - **Public boundary.** Test-only diff with synthetic fixtures. ## Residuals - Under #5530, a zero cumulative that follows a positive one within a session sets the rollup to 0. That is the declared contract. Whether a real provider emits such a reset, and whether billing should then take the maximum, is a product question this PR does not reopen. polylogue-ezvw3 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Settlement of a parent rewrite no longer holds any child's inherited prefix in Python (polylogue-ednjz, part 2 of 2; Codex finding
m5Esron #5685). The guard, the reanchor matching, the materialization plan and the before/after comparison stream through connection-private TEMP tables.Problem
_capture_inherited_prefixesbuilt each inheriting child's composed signature list and kept its inherited ids and signatures as Python tuples, for every child at once._settle_inherited_prefixescomposed each child again into a list._materialize_inherited_prefixbuilt fullsourcesandplanlists and a remap dict. A whale parent with several forks multiplies a prefix larger than the writer's memory. All of this runs inside the parent's replacement transaction, so an OOM rolls back and the same revision fails again on every retry.Solution
_iter_composed_rowsstreams(message_id, signature, owner)segment by segment, with_composed_db_signatures' composition rules;_disk_composed_db_signaturesnow builds on it.before (child, ordinal, message_id, signature, owner)and keeps only the child-to-parent map in Python. Reference capture and the rewritten-owned id set are SQL over it.now:_reanchor_inherited_rowsmatches lost rows forward by signature with indexed queries;reanchorsandcopies;_composition_matches_beforecompares the composition withbeforein lockstep._materialize_inherited_prefixbuilds TEMPsources(snapshot or live rows) andplaced(_plan_prefix_positions: the same keep-or-renumber rule, in SQL). Each plan row is decided one at a time against TEMPtakennatives andoccurrences. The identity scope's digests stream._restore_message_refs,_restore_dispatch_refsand_copy_in_lineagelook up copies and re-anchors in the TEMP tables._session_message_ids,_inherited_entries,_reanchored_ids,_prefix_positionsand_materialized_owner_in_lineageare removed.Schema classification: no DDL;
write.pyis in the derived-identity closure, so this lands before the rebuild. Identities, positions, hashes and the recorded scope are unchanged for the same inputs.Verification
agentctl … verify_quick: Success (job 2329).agentctl … pytest_focused -- tests/unit/storage/test_lineage_normalization.py tests/unit/storage/test_branch_point_witness.py tests/unit/daemon/test_convergence_debt.py tests/unit/storage/test_archive_tiers_write.py(job 2335): everything passes except the 3 provider-usage tests that fail on master (polylogue-ezvw3). That includes every existing materialization, reanchor, dispatch, scope and deep-chain test and the part-1 regressions.test_settlement_streams_inherited_prefixes_through_the_guard_tablesmaterializes three children of one parent while_composed_db_signatures(the list builder) raises inside capture and settlement.Self-review
I read the full diff line by line against the replaced list-based code. What I checked:
owner <> child), the same predicate as the removed_inherited_entries, and they precede the child's own rows, sobeforeordinals number the prefix from 0._plan_prefix_positionsreproduces_prefix_positions: unique(position, variant), non-decreasing in order and below the child's minimum means kept; otherwise it is a dense(session, position)slot by first appearance.INSERT OR IGNOREintotakeninserts it.copy_basesand the key and tail digests use_identity_sequence_digest's framing.Nonewhen a lost row has no match, which the caller treats as "materialize". Previously an unmatched row made theall(...)check fail; the outcome is the same._repair_stale_prefix_branch_points_dband_extract_prefix_tail, outside settlement, still compose into lists on the same parent write. They are pre-existing, and polylogue-fg2ar tracks them.🤖 Generated with Claude Code
https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg