Repository navigation
fix(storage): Stop profile publication from writing canonical usage - #5386
Conversation
PR #5312 removed the hidden usage commit from the *prepared* session-profile publisher only. The same reconciliation survived on the unprepared route: `publish_session_profile` rebuilds through `rebuild_session_insights_sync`, whose chunk loop re-aggregated `session_model_usage` and stamped the usage domain's binding for every session it touched. A call whose subject is a profile therefore rewrote canonical usage and certified a rollup no caller asked it to reconcile — and could still return False afterwards, which is the untruthful refusal polylogue-bp12n.1 AC2 forbids. `SESSION_USAGE_ROLLUP_DOMAIN` already exists and is already a declared prerequisite of the profile domain, so the reconciliation now lives there outright: `_refresh_provider_usage_rollup`, its async twin and the binding stamp move out of `rebuild.py` into `usage_rollup.py` as `reconcile_session_usage_rollup(s)`, verbatim aggregation, provider reconciliation, disjoint token lanes and catalog repricing. This also removes the inverted lazy import `usage_rollup` needed to call back into `rebuild`. The rebuild keeps the stage under an explicit `reconcile_usage_rollup` flag: a bulk index rebuild owns both jobs and commits the rollup rows, their stamp and the profiles built from them in one chunk transaction, and the mutation actuator states that choice rather than inheriting it. A profile publisher passes False, and because the profile's stored binding covers the rollup's inputs rather than its rows, `publish_session_profile` refuses a session whose rollup the prerequisite has not settled instead of silently publishing against superseded cost values. Both refusals now commit nothing. Verification: devtools test over the session profile/rollup/partition/insight rebuild and mutation-actuator suites (185 passed), plus the wider readiness / rebuild-route / actuator route selection (248 passed); devtools verify --quick; devtools render all --check (0 "out of sync"). Anti-vacuity executed, not asserted: passing `reconcile_usage_rollup=True` from `publish_session_profile` turns the skewed rollup 10200 back into the ingest total 1200 inside a profile publication (test_profile_publish_writes_no_usage red); deleting the prerequisite guard publishes against a MISSING rollup (test_profile_needs_a_settled_rollup red). The skew is load-bearing — on an archive whose rollup already agrees with its inputs a refresh rewrites the same numbers and neither test could tell the fix from the defect. Derived index schema identity moves dba2f05e -> df72816c (ops unchanged); all six changed production files were already closure IN, so membership is unchanged and no --update is needed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
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. |
|
Warning Review limit reachedNext included review available in 13 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (10)
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. Comment |
Summary
polylogue-bp12n.1AC2 and the refresh-wrapper half of AC7. The bead's rollup read "3/3 children complete — eligible for close"; that was wrong, and this is the half that is now actually true.Problem (at
ba2c63c47)PR #5312 cleaned only the prepared publisher.
_refresh_provider_usage_rollup+_stamp_refreshed_usage_bindingssurvived in therebuild_session_insights_sync/_asyncchunk loops, reachable frompublish_session_profileand fromInsightsRebuildActuator.apply— a real mutation actuator. So publishing a profile performed a hidden committed write to canonical usage.Solution
The reconciliation moves to
storage/derived/session/usage_rollup.pyasreconcile_session_usage_rollup(_async)/reconcile_session_usage_rollups(_async)— aggregation, provider reconciliation, token lanes and catalog repricing moved verbatim, with no provider total re-summed a second way.The rebuild keeps it behind an explicit
reconcile_usage_rollupkeyword: the bulk index rebuild commits rollup rows + binding stamp + profiles in one chunk transaction (AC2's joint-publication branch), the mutation actuator states that choice explicitly, andpublish_session_profilepassesFalse.Because the profile binding covers the rollup's inputs and not its rows,
publish_session_profileadditionally refuses — returns False, commits nothing — wheninspect_session_usage_rollupsdoes not report VALID. The prerequisite domain is then the only writer of canonical usage.Anti-vacuity — two mutations executed
reconcile_usage_rollup=True:test_profile_publish_writes_no_usageFAILED —At index 0 diff: ('claude-sonnet-4-5', 1200, ...) != ('claude-sonnet-4-5', 10200, ...). The skewed 10200 was silently reconciled back to the ingest total inside a profile publication.test_profile_needs_a_settled_rollupFAILED —assert publish_session_profile(...) is False→AssertionError: assert True is False.Both restored; the file returns 8 passed.
The skew in mutation 1 is load-bearing and worth naming: it edits a
session_model_usagerow directly, leaving the binding untouched so the rollup still inspects VALID. On a fresh archive whose rollup already agrees with its inputs, the refresh would rewrite identical numbers and the test would have stayed green under its own mutation. Opposite direction is pinned in both tests — a blanket refusal fails them.Verification
Exit codes read directly from
$?, not through a filter.Route census unchanged (
gate rebuild-routesok). Writer-module census unchanged —rebuild.pyandusage_rollup.pywere both already declaredtiers:[index], so moving DML between them moves no baseline (gate layeringok).Schema identity
All six changed production files are closure IN, so membership is unchanged and
gate schema-closurepasses with no--update. INDEX movesdba2f05e… → df72816c…; OPS unchanged at86866235…. Must land before a fresh rebuild starts, never during one. NoINDEX_SCHEMA_VERSIONbump — that is the coordinator's per-wave call, not a per-lane one.AC4 is not addressed, and its text needs repair before anyone dispatches it
The
_STALEmarker gates are live production, not dead code:operations/session_profile_convergence.pypasses both marker connections intoSessionProfileDerivation, and two gates consume them (inspectandselected_part_facts)._marker_assertions_presentcounts rows with no status predicate, andlower_markerspreserves every terminal agent judgment as a row — so a human judgment does not trip the gate; only a genuinely absent row does, i.e. lowering never ran or failed. That is exactly the livelock AC4 names: aSessionProfileMarkerLoweringErrorleaves a partition that is current by its own binding reported STALE, so every later pass republishes the whole profile family purely to retry a user-tier write. No delivery cursor exists —applied_position/source_batch/marker_cursor/stream_positionreturn nothing acrossarchive_tiersandmarkers/.On the authoring conflict I flagged when dispatching: AC4's "user effects and applied stream position commit together" reads as one commit across
source.dbanduser.db, which SQLite cannot do — but the bead's own design field disambiguates it the other way ("the user consumer reads a bounded contiguous batch above its own last applied source position … under its one real user-db transaction … and advances the applied position"). So the position is a single-fileuser.dbcommit and the AC is under-specified, not impossible. The repair is to restate AC4 in the design's terms.Residuals
publish_session_profilestays exported with routeunreachedin the census (tests only; the daemon owner uses the prepared route). Retiring it also means moving ~20 test call sites — a separate cut.test_a_drifted_rollup_no_longer_dooms_the_first_profile_computationhas a 127-character nodeid and cannot be selected by id (pre-existing; seepolylogue-5coki). The two new tests are 96 and 95.🤖 Generated with Claude Code
https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy