Skip to content

fix(storage): Stamp the input binding the ingest refresh computed from - #5322

Merged
Sinity merged 1 commit into
masterfrom
fix/ylh7v-retained-aggregates
Sep 21, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/ylh7v-retained-aggregates

Conversation

@Sinity

@Sinity Sinity commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Summary

The ingest-path refresh wrote session_profiles rows without stamping the input
binding it computed from, so its own output could never be found stale.

Problem

storage/derived/session/refresh.py is a second live writer of
session_profiles / session_latency_profiles, reached from
pipeline/services/ingest_batch/_core.py:3067 and
storage/repository/archive/writes/sessions.py:5. It published rows without the
input-binding stamp that the derivation path uses to decide staleness — so a
row it wrote was doomed by construction: no later pass could tell whether the
inputs behind it had moved.

Solution

Stamp the binding the refresh actually computed from. The row now carries the
same evidence the derivation path carries, so staleness is decidable for both
writers.

This does not retire refresh.py as a second writer — that needs
SessionInsightCounts field changes which rebuild.py:2211,2409 also populate,
and rebuild.py was outside this dispatch's scope. What lands here is the
doomed-by-construction half.

Verification

  • devtools test tests/unit/storage/test_session_insight_refresh.py — 40 passed,
    including 3 new tests over the live ingest materialize route
    _apply_session_insight_session_update(s)_async
  • Two anti-vacuity mutations executed, not asserted: removing the stamp → 3
    failed / 37 passed; pinning input_content_hash="frozen-constant" → 3 failed /
    37 passed. A constant stamp does not survive.
  • devtools test tests/unit/pipeline/test_ingest_batch.py — passed (the
    production caller of the changed function)
  • devtools verify --quick — exit 0, 23 gates
  • devtools render all --check — exit 0, grep -ci 'out of sync' = 0
  • devtools schema closure polylogue/storage/derived/session/refresh.py → out.
    The only production file edited, so no identity move and no rebuild
    constraint
    .

Two refutations worth recording

The bead's two self-justifying probes are stale. Duplicate ::note: presence
is deduped at derivation.py:88-99 with dict.fromkeys, comment naming the
reason; the usage-committing publication wrapper was removed by #5312, which made
usage a prerequisite domain (derivation.py:539). Neither survives on dead code
— publish_session_profile (derivation.py:411) is a callerless predecessor and
a separate entry, not either probe.

The 2026-09-15 design note's "four families, only two have owners" is wrong at
head.
threads (index.py:955) and session_tag_rollups (index.py:1718)
are VIEWS, and provider/day is a read-time grouping helper
(derived/session/aggregates.py). There are no retained thread/tag/provider-day
aggregate tables, so they need no partition key, inspect query or atomic
replacement. The retained family is two tables, not four; work-event and
phase rows were already retired.

Residuals

  • AC5/AC6 and the marker half of AC7 are blocked by lane ownership, and the
    worker stopped rather than editing: separating marker delivery from profile
    validity requires registering a domain in
    daemon/session_profile_composition.py:59 and changing where the prepared
    bundle binds marker_candidates (rebuild.py:1839). One lane needs to own
    daemon composition + rebuild.py + derivation.py together.
  • AC4's third clause (a candidate present only in a superseded input surviving
    coalescing) is reproducible at the storage level today, but fixing it is the
    full source-to-user batch/cursor protocol including a durable source.db
    addition behind a verified backup. Out of one PR's scope.
  • Inherited red, reproduced on a clean tree:
    tests/unit/storage/test_session_insight_profiles.py fails 2, not the 1 the
    known-red baseline records.

Advances polylogue-ylh7v.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq

The ingest materialize stage (refresh_session_insights_bulk) hydrates every
changed session and writes its profile family, but never passed
input_content_hash. inspect_session_profiles treats a profile with no stored
binding as stale -- a row that cannot say what it was computed from never
certifies itself -- so the daemon converger hydrated, rebuilt and rewrote the
identical family on its next pass. Every ingested session was materialized
twice by construction; the full-rebuild and degraded/large-session builders
already stamp, so only the incremental hydrated paths were affected.

Read the binding on the same connection as load_async_batch and pass it to
build_session_insight_records in both the bulk and single-session paths.

Verification: devtools test tests/unit/storage/test_session_insight_refresh.py
-> 40 passed (receipt 20260921T023452Z-focused-test-2883215-700ba68f).
Executed mutations: dropping the stamp, and stamping a constant instead of
session_input_bindings_async, each turn the three new tests red.
devtools verify --quick exit 0; devtools render all --check exit 0, no
"out of sync"; devtools schema closure reports refresh.py out of the derived
closure.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
@Sinity
Sinity enabled auto-merge (squash) September 21, 2026 03:04
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: dd39a5ce-e833-40c6-8e2e-f83f9c3946fb

📥 Commits

Reviewing files that changed from the base of the PR and between 2b20817 and 5af3657.

📒 Files selected for processing (2)
  • polylogue/storage/derived/session/refresh.py
  • tests/unit/storage/test_session_insight_refresh.py

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 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
📝 Code Review ✅ Completed 2026-09-21T03:10:51.224026Z 5af3657 PR opened
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5af36574af

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity merged commit a3ac887 into master Sep 21, 2026
3 checks passed
@Sinity
Sinity deleted the fix/ylh7v-retained-aggregates branch September 21, 2026 03:15
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