Repository navigation
feat(reader): support non-conversation target kinds for marks (#1113) - #1179
Conversation
Extend marks, annotations, recall packs, and reader workspaces to
target sessions, work events, threads, content blocks, attachments,
and paste spans, not only conversations and messages.
Substrate
- core/user_state_targets.py: canonical TargetKind registry with
identity-key templates per kind.
- sqlite/schema_ddl_archive.py: user_marks/user_annotations CHECK
constraints admit the new kinds; schema bumped to v16.
- api/user_state_resolver.py: per-kind resolvers validating against
session_profiles, session_work_events, work_threads, and
content_blocks before write.
Surfaces
- api/archive.py: _resolve_user_state_target routes new kinds through
the resolver; recall-pack and workspace item resolvers handle them
with explicit resolved/missing status.
- cli/commands/user_state.py: --target-type accepts every registered
kind.
- daemon/user_state_http.py: create-mark/save-annotation reject
unknown target_type with 400.
Tests
- tests/unit/storage/test_user_state_target_kinds.py: registry,
identity keys, mark+annotation CRUD per kind, content-hash
invariance, recall-pack resolution + degradation, workspace
open-target round trip.
Ref #1113
|
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 (11)
✨ 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: 1551f29691
ℹ️ 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
Extend marks, annotations, recall packs, and reader workspaces to admit
six new target kinds in addition to
conversationandmessage:session,work_event,thread,content_block,attachment, andpaste_span. The substrate (user_marks,user_annotationsCHECKconstraints, schema bumped to v16), the storage write layer, the API
facade resolver, the recall-pack/workspace item resolvers, the CLI
--target-typechoices, the daemon HTTP validation, and the MCPpass-through all gain the new kinds in one PR.
Problem
#867shipped target-aware marks/annotations/recall-packs forconversations and messages and explicitly deferred the other kinds
called out in its acceptance criteria pending stable target identity.
#1113tracks that deferral. The reader now wants to mark a session,pin a work event for review, annotate a thread, or save a content
block into a recall pack — all of which the original CHECK
constraints and resolvers rejected as
unsupported_target_type.Solution
Substrate
polylogue/core/user_state_targets.py: new canonicalTargetKindregistry. Each kind declares the unit-of-identity in
target_id,whether it carries a
message_id, and anidentity_keytemplateused by recall packs and workspaces.
polylogue/storage/sqlite/schema_ddl_archive.py:user_marks.target_typeanduser_annotations.target_typeCHECKconstraints admit all eight kinds. The interlocking row CHECK keeps
conversation/message/content_block invariants strict and allows the
insight kinds free
target_idso they can carry insight-row IDsscoped to a conversation via the existing FK.
polylogue/storage/sqlite/schema_ddl.py:SCHEMA_VERSIONbumped15 → 16 (fresh-first; existing archives need to be re-created — no
in-place migration script ships in this PR, consistent with the
fresh-first policy in
docs/internals.md).polylogue/api/user_state_resolver.py: per-kind validation againstsession_profiles,session_work_events,work_threads, andcontent_blocks.attachmentandpaste_spanaccept any non-emptytarget_idscoped byconversation_id— these remainvalidation-light until their identity surfaces are promoted to
first-class tables (left as durable follow-up work; recall-pack
items pointing at unknown attachment/paste IDs still resolve
successfully because the CHECK and the FK on
conversation_idarethe substrate-level invariants in use).
Surfaces
polylogue/api/archive.py:_resolve_user_state_targetroutes new kinds through the resolver._resolve_recall_pack_itemrecognises every registered kind andproduces typed
resolved/missingitems with canonicalidentity_keys. Workspace open-targets reuse the same path.polylogue/storage/repository/archive/repository_writes.py:add_markvalidatestarget_typeagainst the registry and picksthe right defaulting rule for
target_idper kind.polylogue/cli/commands/user_state.py: every--target-typechoiceuses the registry.
polylogue/daemon/user_state_http.py: create-mark andsave-annotation reject unknown
target_typewith HTTP 400.Tests
tests/unit/storage/test_user_state_target_kinds.py:is_supported/identity_keysemanticsinvariance after writing the new mark/annotation rows
save_annotationwith sameannotation_idsession,work_event,thread,content_block) with specificValueErrormessagesidentity_key, missing status for unknown insight units, andunsupportedstatus retained for kinds outside the registry(e.g.
topology_edge— still gated on feat(topology): materialize session identity and lineage graph #866)status per insight kind
Alternatives considered
because the existing insight tables already carry the FK to
conversations(conversation_id)and the resolver's existence-probepattern is the simpler structural contract.
target_type: deferred — no currentsurface filters on
target_typealone at scale; the existingidx_user_marks_conversation/idx_user_annotations_targetcover today's read paths.
Out of scope (explicit deferrals)
topology_edgetargets — still gated on feat(topology): materialize session identity and lineage graph #866 (topology lineage).Recall-pack/workspace items of this kind remain
unsupported.attachmentsandpaste_spansstorage tables —current architecture keeps them inside
content_blocks/raw_conversations. When they become first-class, the resolvergains a strict FK check identical to
work_event/thread.tests/visual/fixture exercises
conversation/message; a per-kind visualsmoke is a useful follow-up but is not blocking the substrate
closure.
Verification
→
34 passed in 15.28s→
total_duration_s: 23.85, exit_code: 0(format + lint + mypy +render-all --check + topology + suppressions + manifests + CI
workflows + witness lifecycle + lane assertions all green).
Inherited failures
devtools verify --allsurfaces five pre-existing failures on master,unrelated to this PR (verified by stashing the diff and re-running):
tests/unit/cli/test_check.py::TestCheckCommandSupplementary(4 cases) —
doctor --repairchokes onmessage_embeddings(independent of feat(reader): support non-conversation/message target kinds for marks, annotations, recall packs #1113).
tests/unit/mcp/test_tool_schema_witness.py::test_mcp_tool_catalog_matches_witness— MCP tool catalog witness drift (cost_outlook vs cost_rollups,
independent of feat(reader): support non-conversation/message target kinds for marks, annotations, recall packs #1113).
Closes #1113