Skip to content

fix: Bind the message content identity into the session input projection - #5176

Merged
Sinity merged 1 commit into
masterfrom
fix/session-input-binding-content-identity
Sep 15, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/session-input-binding-content-identity

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

#5103 made an id-less message's identity content-derived. Two declarations still describe the world before it. One is a latent correctness gap in the session-input binding; one is a stale test fixture.

⚠️ This PR is IN the derived schema-identity closure. It must land before an archive rebuild starts, never during one. See the closure section.

Evidence

Receipt .cache/verify/runs/20260914T233651Z-all-207009-89ddea6b (verify_all, job 1699, 22,540 selected, 29 failed).

Caveat on that receipt: its run.json records git_head: f7964acd12b25134c0e2e4cd8f73f9e6557a4a4f — the tip of branch rebase-5165, not master and not an ancestor of it — and final_git_head: 724d17535. The shared checkout advanced across 7 merged PRs during the run, so it is not evidence of a frozen tree. I re-ran all 29 node ids at true master HEAD: 17 reproduce, 12 do not. These 2 are among the 17.

Per-failure classification

Failure Classification Cause
test_session_partition_convergence::test_the_partition_input_columns_are_projected_or_declared_excluded product defect (latent) content_identity / content_occurrence neither projected nor excluded in SESSION_INPUT_PROJECTION_COLUMNS; the binding digest can report VALID over a moved output
test_lineage_validation::test_hand_built_index_declares_every_production_column_of_route_backed_tables stale test test-side messages DDL mirror not updated for #5103

Problem

SESSION_INPUT_PROJECTION_COLUMNS is hashed into the session-input binding digest; a stored binding compares unequal only when a projected value moves. It is a freshness/invalidation digest, and the derived profile outputs embed message_id.

After #5103, message_id for an id-less message is generated from content_identity || '.' || content_occurrence. Neither column was classified.

They are not covered by the projected content_hash. I verified the two field sets directly rather than assuming:

  • content_identity hashes _HASHED_FIELDS["ParsedMessage"]: blocks, delivery_status, end_turn, is_aborted_mid_stream, material_origin, message_type, model_effort, model_name, occurred_at_ms, parent_message_provider_id, paste_spans, provider_message_id, recipient, role, sender_name, stop_reason, text, timestamp, user_context_text.
  • _message_content_hash (storage/sqlite/archive_tiers/write.py:2559+) hashes a strict subset — it omits is_aborted_mid_stream, parent_message_provider_id, paste_spans, timestamp.

Concrete counterexample: change parent_message_provider_id on an id-less message. content_identity moves → message_id moves → derived rows carry new message ids. content_hash does not move (that field is not among its inputs) and parent_message_id is itself declared-excluded. Every projected column is unchanged, so the binding reports VALID over a moved output.

content_occurrence is reachable independently: it is offset-continued on append, so a re-ingest ordering change renumbers it without touching any other projected value.

Solution

Project, do not exclude. Exclusion was not actually available: message_id is itself excluded, on a reason #5103 made false ("generated from session_id, position, variant_index and native_id"). Excluding its inputs as well would leave the entire message identity unbound by the digest. That stale reason is corrected here too.

Both options are AST-visible changes to input_binding.py and move the schema identity identically, so the cheaper-looking option was not cheaper.

The second change is a pure test fixture. grep -E "CREATE TABLE (IF NOT EXISTS )?messages" over polylogue/, devtools/, tests/ returns exactly one production DDL site, generated from the specs — so no production route could have silently dropped these columns. Its identity_source default ('positional' vs production 'content') was stale from the same PR and is corrected.

SESSION_INPUT_RECIPE_VERSION is not bumped: the projection tuple itself moved, so every stored binding already compares unequal.

Verification

devtools test tests/unit/devtools/test_lineage_validation.py tests/unit/storage/test_session_partition_convergence.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T013747Z-focused-test-322371-09072164/run.json

Because the projection is closure-bearing, I also ran every declared consumer of the binding and the derived-identity gates:

devtools test tests/unit/storage/test_session_profile_derivation.py tests/unit/storage/test_lineage_normalization.py \
  tests/unit/storage/test_derived_schema_identity.py tests/unit/storage/test_derived_schema_identity_admission.py \
  tests/unit/storage/test_derived_status.py tests/unit/storage/test_session_profile_cost_columns.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T013921Z-focused-test-323349-dafc4468/run.json

Schema closure

devtools schema closure polylogue/storage/derived/session/input_binding.py
IN   polylogue/storage/derived/session/input_binding.py
  Editing a file marked IN moves the derived schema identity: the archive must
  reconverge, and the change must land before a fresh rebuild starts, never during one.

devtools schema closure tests/unit/devtools/test_lineage_validation.py
out  tests/unit/devtools/test_lineage_validation.py

IN. This PR moves the derived schema identity and requires full reconvergence. Land it before any rebuild begins.

Anti-vacuity

The completeness test goes red on any messages column that is neither projected nor declared-excluded — removing either new entry reproduces the failure exactly. The lineage fixture test goes red by name if either column is dropped from the hand-built DDL.

Honest residual on the projection specifically: that completeness check proves the columns are classified, not that projecting them was the right classification. The existing role differential at test_session_partition_convergence.py:965 is not parameterized over these columns, so it does not cover them. The non-vacuous test would be a differential on a session of id-less messages that moves parent_message_provider_id (or paste_spans) so content_identity moves while content_hash and every other projected column hold still: the binding must change with the columns projected, and must not with them monkeypatched out. I have not added it — flagging it as follow-up test work rather than claiming coverage this PR does not have.

Residuals

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

#5103 gave an id-less message a content-derived identity: `message_id` is now
generated from `content_identity` and `content_occurrence` rather than from
position. Two declarations still describe the world before that.

The load-bearing one is `SESSION_INPUT_PROJECTION_COLUMNS`. Its digest decides
whether a stored session-input binding is still VALID, and the derived profile
outputs embed `message_id`. Neither new column was projected, and neither is
covered by the projected `content_hash`: that hash's field set is strictly
narrower, omitting `is_aborted_mid_stream`, `parent_message_provider_id`,
`paste_spans` and `timestamp`, all of which `content_identity` hashes. Change
`parent_message_provider_id` on an id-less message and `message_id` moves while
every projected column holds still -- the binding reports VALID over a moved
output. `content_occurrence` is reachable independently: it is offset-continued
on append, so a re-ingest ordering change renumbers it alone.

Excluding them instead was not available. `message_id` is itself excluded, on a
reason that #5103 made false; excluding its inputs as well would leave the whole
message identity unbound.

The second is a test-side mirror. `test_lineage_validation`'s hand-built index
is the only hand-written `messages` DDL in the tree -- production builds it from
the specs -- so its omission was a stale fixture, not a route that could drop
columns. Its `identity_source` default was stale from the same PR.

`SESSION_INPUT_RECIPE_VERSION` is not bumped: the projection itself moved, so
every stored binding already compares unequal.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@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.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 52 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: 1d3254a0-9944-4c52-a53b-82f5442b7419

📥 Commits

Reviewing files that changed from the base of the PR and between 724d175 and 4d7cfab.

📒 Files selected for processing (2)
  • polylogue/storage/derived/session/input_binding.py
  • tests/unit/devtools/test_lineage_validation.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 15, 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-15T01:45:48.606990Z 4d7cfab 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.

@Sinity
Sinity merged commit 06f5957 into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the fix/session-input-binding-content-identity branch September 15, 2026 01:51
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