Repository navigation
fix(storage): close worker-8 read, usage and snapshot review debt - #5792
Merged
Merged
Conversation
Source-only corrections for polylogue-1tyq5.107, .108 and .109. Regression tests are written but not run; no checks executed. Nineteen triaged findings remain untouched. Prepared on pinned master fddc7a1.
Landing review of the worker-8 commit against current master: - Writers refuse a never-provisioned tier only when they open it directly; the index version-zero exemption, attached siblings, sealed staging and assert_tier_schema_supported keep master's read semantics. - ReadFrame.resume rebinds only for a held read transaction and refuses while a stream pins the snapshot; it no longer rebinds on every external commit, which would have reset data_version and hidden a mixed source census from its end-of-census check. - One effective-context owner (effective_context_window plus a shared boundary query) serves both the API and the pinned read.effective_context operation, which now composes the lineage transcript too. - Single, batch and list profile reads all hold one snapshot. - Attachment-library pages order within a message by attachment ID, as the session read does; attachment_refs.position is an identity coordinate. - Checkpoint blockers stay named when the checkpoint failed. - Cumulative-lane reportedness follows counter evidence like the request lane, so an explicit zero stays reported. - Subscription equivalents fail closed: an unrated model or a tier the catalog no longer declares yields None rather than $0. - put_query raises instead of asserting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg
Sinity
force-pushed
the
fix/codex-debt-w8-storage-reads
branch
from
September 29, 2026 04:36
7eca10a to
02c3d8c
Compare
Sinity
marked this pull request as ready for review
September 29, 2026 04:48
|
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
Lands worker 8's review-debt fixes for
polylogue-1tyq5.107,.108and.109(storage reads, usage, query objects, connection profile), rebased onto current master and reviewed. Of 52 findings: 24 fixed with regression tests, 9 already fixed on master, 19 not reached.Problem
The worker's commit could not be run by its author. On review, several fixes were right in intent but wrong in shape:
ReadFrame.resumerebound on every external commit, which resetsdata_versionand would hide a mixed source census from_require_current_source_census_frame;read.effective_contextoperation reading own rows with the old boundary rule;attachment_refs.position, an identity coordinate rather than a display ordinal;Solution
resumerebinds only for a held read transaction and refuses while a stream pins the snapshot.effective_context_windowplus one boundary query is now the single owner for both effective-context routes, and both compose the lineage transcript. Single, batch and list profile reads hold one snapshot. Library pages order by attachment ID within a message, matching the session read. Checkpoint blockers stay named when the checkpoint failed. The cumulative lane uses the same counter-evidence rule as the request lane. Subscription equivalents areNonewhen the rate or tier is unknown.put_queryraises instead of asserting.No Origin to Provider reversal is added.
coverage.providerwas already present and is unchanged.Verification
agentctl job start polylogue verify_quick --workspace /realm/worktrees/salvage-w8 --wait→ job 2311succeeded(head 65a248e762, same tree as 02c3d8c).agentctl job start polylogue pytest_focused --workspace /realm/worktrees/salvage-w8 --wait -- <30 test files>→ job 2314:790 passed, 4 failed. All four failures are inherited: job 2294 reproduces them with every production file reset toorigin/master:test_diagnostics.py::test_latency_plain_zero_rows_reports_unknown_drop_accountingtest_facade_contracts.py::test_archive_facet_buckets_count_unique_sessions_for_duplicate_hitstest_facade_contracts.py::test_no_undiscovered_async_methodstest_mapped_bytes_budget.py::test_async_attached_tier_profiles_map_main_only[configure_read_connection]origin/master, the new regression tests fail on their assertions (job 2262:40 failed; job 2315:3 failed, covering the revised attachment test, the updated budget test and the cumulative-lane test).Self-review
operations/read_view_extras.py. Both now calleffective_context_window. The one-snapshot fix covers all three profile reads. Reportedness now uses the same counter-evidence rule for the request and cumulative lanes. The schema refusal applies only where a writer opens a tier. Reader, sibling, sealed-staging andassert_tier_schema_supportedcallers keep master behaviour.revalidate()would have defeated the census end check, so it was dropped.ReadFrameExpiredErrorfromresumeduring a stream is an existing typed error, and the census never resumes mid-stream. Theassertinput_querybecame a raise.get_messagesalready did. See residuals.LEFT JOIN messagesis on the primary key.finally.ReadFrame.closeretires stream cursors before closing the connection.resumenever proves an anchor on a held snapshot.upgrade_runtime, separate fromretryand drift. Checkpoint blockers are kept on error.unavailable, and a lane with an explicit zero isreported. An unknown subscription rate or tier isNone, not $0.BEGIN DEFERREDends withROLLBACKinfinally.test_mapped_bytes_budgetwas updated to three writers.read_view_extrasuses the new owner._own_messages,read_model_usage_batch_async,_resolve_subscription_tier_setting) exist and are called on the production route. Each test states its anti-vacuity condition.Per-finding dispositions
polylogue/storage/sqlite/connection_profile.py:900-910; :1193-1206holds on current masterpolylogue/storage/sqlite/connection_profile.py:932-945holds on current masterpolylogue/storage/sqlite/connection_profile.py:932-945holds on current master_assert_schema_supportedkeeps the empty-tier exemption for read-only opens only;open_connection/open_daemon_connectionon a never-provisioned tier now raiseSchemaSkewbefore any SQL. Attached siblings keep the absent-tier read answer.test_writers_refuse_an_uninitialized_durable_tiermapped_bytes_budgetandMappedBytesBudgetCheck.concurrent_profile_budget_bytescount three ordinary writer profiles (index, source, publication reservation).test_memory_budget_includes_source_and_reservation_writersReadFrame.resumerebinds a live frame whose connection holds a read transaction before proving the anchor, and refuses withReadFrameExpiredErrorwhile a stream pins the snapshot.test_resume_releases_a_held_snapshot_before_proving_the_anchor, ::test_resume_refuses_while_a_stream_pins_the_snapshotReadFrame.closecloses registered stream cursors before the connection, so later generator cleanup has nothing to do.test_stream_can_be_closed_after_its_frameread_frameandReadFrame.__init__refuse NaN and infinite snapshot bounds.test_read_frame_rejects_nonfinite_snapshot_boundsformat_session_markdownuses the recordedsource_urlwhen an attachment has no local path.test_markdown_uses_remote_attachment_urls_without_a_local_pathtest_attachment_library_pages_keep_session_and_transcript_orderpolylogue/analysis/archive_models.py:79; polylogue/storage/derived/session/profiles.py:248; polylogue/storage/sqlite/queries/mappers_insight_profiles.py:54-56holds on current mastereffective_context_window(the single owner, used by both the API and the pinnedread.effective_contextoperation) falls back to the plain prefix unless 0 <= start <= end.test_effective_context_rejects_invalid_rangestest_newest_incomplete_compaction_does_not_reuse_an_older_summarytest_effective_context_includes_a_forks_inherited_prefix, ::test_pinned_operation_and_api_share_one_effective_context_decisiontest_effective_context_reads_boundary_in_the_message_snapshottest_profile_rows_and_usage_overlay_share_one_snapshotput_queryreturns the persisted row (including promotion metadata) after the idempotent insert.test_put_query_returns_existing_promotion_contractget_effective_contexthydrates blocks and derived text inside the same snapshot as the messages.test_effective_context_hydrates_structured_tool_blocksevent position + 1, leaving position 0 to the session-start snapshot.test_context_snapshot_start_precedes_the_first_compactionpolylogue/storage/sqlite/schema_manifest.py:92-129holds on current masterupgrade_runtime, separately from archive read failures (retry) and drift.test_canonical_ddl_runtime_failure_requests_runtime_upgradepolylogue/storage/sqlite/archive_tiers/archive.py:6694-6697; :8603-8616; polylogue/storage/sqlite/queries/sessions_search.py:25-27; polylogue/mcp/server_support.py:546-555holds on current masterpolylogue/storage/sqlite/schema.py:113-128; polylogue/storage/sqlite/schema_bootstrap.py:87-101holds on current mastertest_successful_checkpoint_does_not_label_current_snapshot_as_a_blockerpolylogue/storage/usage.py:237-247holds on current masterpolylogue/storage/usage.py:589-595holds on current masterprovider_request_lanes/provider_cumulative_lanesand printsunavailablefor an unreported lane.test_usage_cli_renders_disjoint_lanes_and_unavailable_requestsrequest_counter_event_count), in both the SQL and streaming stats paths. The cumulative lane follows the same counter-evidence rule.test_request_lane_reportedness_requires_request_counter_evidenceunavailable; an explicit request zero staysreported.test_request_lane_reportedness_requires_request_counter_evidencetest_stored_price_does_not_hide_a_missing_cache_ratesession_usage_costs_for_connectionbatches IDs at the connection'sSQLITE_LIMIT_VARIABLE_NUMBER.test_session_cost_lookup_pages_at_the_connection_bind_limittest_session_subscription_fallback_normalizes_provider_qualified_models, ::test_session_subscription_amount_is_unknown_without_a_rate_or_tiercredits_to_usdwith the archive's configured tier (defaultpro); a tier the catalog no longer declares yields None.test_session_subscription_amount_is_dollars_not_raw_creditsWorker claims narrowed rather than rejected: 107-09, 107-12, 107-18, 107-22 and 107-24 (see Problem), and 109-01/109-02 (fail closed). No worker
fixedclaim was dropped as not real.Derived-identity closure
devtools schema closureon the changed files. IN:storage/sqlite/connection_profile.py,queries/attachment_records.py,queries/message_query_reads.py,query_objects.py,query_store_archive.py,run_projection_relations.py,schema.py,wal_checkpoint.py,storage/usage.py. Out:cli/commands/diagnostics.py,operations/read_view_extras.py,rendering/core_markdown.py,queries/session_insight_profile_reads.py. Land this before a rebuild starts.Residuals
read.effective_contextoperation returns messages without hydrated blocks. The API route hydrates them. This predates the PR.get_messagesdoes._attach_sibling_tiersstill admits an empty sibling tier on a writer connection. Only direct writer opens refuse.🤖 Generated with Claude Code
https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg