Repository navigation
feat(reader): identity-preserving marks across reimport (#1114) - #1188
Conversation
Marks and annotations now survive the conversation row's lifecycle. They
carry a stable ``identity_key`` (``conversation:{cid}`` or
``message:{cid}:{mid}``) and the FK from ``user_marks``/``user_annotations``
to ``conversations``/``messages`` uses ``ON DELETE SET NULL`` instead of
cascade. After a logically identical conversation is re-imported, the new
save_via_backend path calls ``repoint_user_state_by_identity`` to rebind
the resolved ``conversation_id``/``message_id`` columns from the stored
identity_key.
Schema bumped to v16 with a v15->v16 upgrade plan that rebuilds both
user-state tables in place and backfills identity_key from the existing
conversation_id/message_id columns. Also fills the missing v14->v15
upgrade plan so the version chain stays continuous.
Closes #1114
Ref #867
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (10)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0052ef7802
ℹ️ 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".
…1288) ## Summary Restore a green master baseline by fixing 11 pre-existing pytest failures introduced by #1113 (v15→v16 non-conv mark targets) and #1114 (v16→v17 identity-preserving marks/annotations), plus drift from adjacent runtime-catalog / verify-pipeline additions. Adds the `devtools verify-test-infra-currency` lint from the issue's ambitious-expansion section so this drift class fails the local gate immediately on the next SCHEMA_VERSION bump. Closes #1208 ## Problem After #1179 (#1113) and #1188 (#1114) landed, `pytest -q --ignore=tests/integration` on `origin/master` reports 12 failures (issue cited ~11; one is the canonical `tests/infra/storage_records.py:620 no such table: user_marks`). The git pre-push hook runs `devtools verify --quick` which doesn't trip them because affected tests aren't in the testmon-selected set for typical changes — the cliff is only exposed once an unrelated change invalidates testmon. The failures cluster: - **Test-infra schema drift (#1113/#1114)**: `tests/infra/test_storage_records.py::test_store_records_commits_within_lock` exercises `store_records` against a `:memory:` SQLite connection that has no schema. The newly-added `_repoint_user_state_by_identity_sync` helper (mirroring async `repoint_user_state_by_identity`) issues `UPDATE user_marks ...` / `UPDATE user_annotations ...` and crashes with `OperationalError: no such table`. - **Surface boundary (#1113)**: the new `polylogue/api/user_state_resolver.py` accepts `ConversationRepository` via TYPE_CHECKING, which the surface→storage boundary lint rejects without an allow-list entry. - **Topology projection drift**: the new `polylogue/storage/message_type_backfill.py` was unclassified by `devtools build-topology-projection` (target=`TBD`, owner=`storage-domain`), which the topology-projection witness tests flag. - **Snapshot-shaped catalog tests**: production code added `query-productivity-rollups` operation, `productivity-rollup-query-loop` + `tool-usage-query-loop` artifact paths, `message_embeddings` maintenance target, and the `verify-witness-coverage` quick-verify step. Their pinning assertions in `tests/unit/{operations,core,devtools}/...` were left out of sync. ## Solution - **`tests/infra/test_storage_records.py`**: monkey-patch `_repoint_user_state_by_identity_sync` for the in-memory `TrackingConnection` test. Mirrors the existing comment + monkey-patch for `_upsert_conversation_stats_sync`. Production `ConversationBuilder` flows already run the full schema bootstrap so they're unaffected — the in-memory unit test is the only consumer that needs the suppression. - **`tests/unit/architecture/test_surface_storage_boundary.py`**: extend the docstring + `ALLOWED` frozenset with `polylogue/api/user_state_resolver.py`. The import is TYPE_CHECKING-only and the file is a typed resolver, not a back-channel into storage. - **`devtools/build_topology_projection.py`**: add `message_type_backfill.py` to `STORAGE_ROOT_KEEP` so it classifies as a storage-root cross-cutting helper. - **`docs/plans/topology-target.yaml`**, **`docs/topology-status.md`**, **`docs/test-quality-workflows.md`**, **`docs/devtools.md`**, **`AGENTS.md`**: regenerated via `devtools render-all`. - **Snapshot updates**: `tests/unit/operations/test_specs.py`, `tests/unit/devtools/test_scenario_coverage.py`, `tests/unit/core/test_artifact_specs.py`, `tests/unit/core/test_artifact_graph.py`, `tests/unit/devtools/test_artifact_graph.py`, `tests/unit/core/test_maintenance_targets.py`, `tests/unit/devtools/test_verify.py` — each updated to track the live catalog. No production behavior changed. ### Ambitious-expansion lint - **`devtools/verify_test_infra_currency.py`** (new): collects every CREATE TABLE / CREATE VIRTUAL TABLE name from `polylogue/storage/sqlite/schema_ddl_*.py`, then AST-walks every non-test module under `tests/infra/` and scans only string literals that look like SQL (contain a SQL verb, skip docstrings). For every `FROM`/`UPDATE`/`INSERT INTO`/`DELETE FROM`/`JOIN` table reference found, asserts the table exists in the current schema. SQLite built-ins (`sqlite_master`, ...) are allowlisted. - Wired into `build_verify_steps` so `devtools verify` and `devtools verify --quick` run it. - Registered in `devtools/command_catalog.py` and documented in the regenerated `docs/devtools.md`. - Verified to detect the regression class: removing `user_marks` from the schema reproduces the lint failure pinpointing `tests/infra/storage_records.py:622`. ## Verification ``` $ pytest -q --ignore=tests/integration 7928 passed, 2 xfailed in 158.67s $ devtools verify --quick ... 19 steps green, total_duration_s ≈ 49s "exit_code": 0 $ devtools verify-test-infra-currency schema tables: 34 helper table refs: 8 helper refs without matching schema table: 0 ``` One pre-existing hypothesis deadline flake in `tests/unit/core/test_filters_props.py::test_filter_chain_never_crashes_on_build` passes on rerun; unrelated to this change. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Marks and annotations now survive the conversation row's lifecycle. They
carry a stable
identity_key(e.g.conversation:{cid}ormessage:{cid}:{mid}) and the FK fromuser_marks/user_annotationsto
conversations/messagesusesON DELETE SET NULLinstead ofcascade. After a logically identical conversation is re-imported, the
save_via_backendpath callsrepoint_user_state_by_identityto rebindthe resolved
conversation_id/message_idcolumns from the storedidentity_key.
Problem
#867's acceptance criteria called for "user metadata survives reimport where
identity evidence is available." The substrate had two parallel systems:
conversation_user_metadata(keyed by identity_key, survived soft delete)and
user_marks/user_annotations(keyed by conversation_id withON DELETE CASCADE, died on every hard delete). The latter violated theacceptance criterion: any
delete_conversationfollowed by re-importlost marks and notes even though the conversation_id is deterministic
across reimport.
#1114 closes that gap.
Solution
Storage substrate (option 1 from the issue's design — structurally clean
identity-key column, not a post-hoc reset hook):
polylogue/storage/sqlite/schema_ddl_archive.py: rebuilduser_marksanduser_annotationswithidentity_key TEXT NOT NULLas a first-class column. FK to
conversations/messageschanges toON DELETE SET NULL, the legacy CHECK that tiedtarget_idtoconversation_idis dropped (target_idis now the stable identity;conversation_id/message_idare resolved pointers that may be NULLbetween delete and reimport).
polylogue/storage/sqlite/queries/conversations_identity.py: newuser_state_identity_keyhelper matches theTargetRefPayloadsurfaceconvention exactly.
add_markandsave_annotationcompute andpersist the identity_key on every write. New
repoint_user_state_by_identityrebinds orphan rows after a freshlywritten conversation lands; message-target rows are only rebound when the
message_id is still a member of the reimported conversation, so a
conversation that loses a message keeps the mark orphaned (NULL pointers)
rather than silently silently relinking to an unrelated row.
polylogue/storage/repository/archive/writes/conversations.py:save_via_backendcallsrepoint_user_state_by_identityonce perupsert.
Schema migration:
SCHEMA_VERSIONbumped 16 -> 17. v16 -> v17 (build_v16_to_v17_upgrade_plan)rebuilds the two tables in place via the SQLite copy-and-swap pattern and
backfills
identity_keyfrom the existingconversation_id/message_idpair. The v15 -> v16 path (filling the gap left by feat(reader): support non-conversation/message target kinds for marks, annotations, recall packs #1113's fresh-first bump)
reuses the same rebuild so v15 archives reach v17 in one step. The previously
missing v14 -> v15 plan (feat(insights): learning feedback loop — corrections as deterministic rebuild signal #1131) is also added so the chain stays continuous.
_upgrade_tail_statementsskips the redundantv16 -> v17 rebuild when an archive enters via the v15 path.
Tests (
tests/unit/storage/test_marks_identity_preserving.py):test_user_state_identity_key_matches_payload_conventionand...rejects_message_without_message_id: identity_key shape contract.test_add_mark_records_identity_key: storage round-trip.test_marks_survive_conversation_delete_and_repoint_on_reimport: thecore feat(reader): identity-preserving marks and annotations across reimport #1114 acceptance — mark survives hard delete (NULL pointer), gets
rebound on reimport.
test_message_target_marks_repoint_on_reimport: message-level rebind.test_repoint_leaves_orphan_when_message_disappears_on_reimport:message disappears -> mark stays orphaned (no spurious relink).
test_repoint_is_idempotent: repeated calls are no-ops.test_user_state_does_not_affect_conversation_content_hash:content-hash exclusion regression for user state.
tests/infra/storage_records.pymirrors the repoint in its syncstore_recordsbuilder so tests exercising reset/reimport via the syncfixture see the same rebinding behaviour as production async ingest.
Verification
devtools verify --quick->"exit_code": 0(format + lint + mypy +render-all --check + manifest lints).
python3 -m pytest tests/unit/storage/test_schema_upgrades.py tests/unit/storage/test_user_state_contracts.py tests/unit/storage/test_marks_identity_preserving.py tests/unit/storage/test_user_state_target_kinds.py->
25 passed.python3 -m pytest tests/unit/storage/ tests/unit/cli/test_user_state_command.py tests/unit/daemon/->
1250 passed in 71.73s.backfilled correctly for both conversation and message target rows.
Closes #1114
Ref #867