Skip to content

refactor(tags): back user tags with assertions (#1842) - #2144

Merged
Sinity merged 3 commits into
masterfrom
feature/refactor/assertion-overlay-commands
Jun 19, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/refactor/assertion-overlay-commands

Conversation

@Sinity

@Sinity Sinity commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

User tag writes now mirror into the assertion substrate, and the root tags command is reduced to the live tag-count read surface. Tag mutation remains available through the query-first find ... then mark --tag-add/--tag-remove path, so #1842 can keep shrinking overlay roots without preserving a separate polylogue tags SESSION --add-tag workflow.

Problem

#1842 explicitly blocks the user-overlay command cleanup on assertion-backed equivalence for tags, blackboard, feedback, and user-state. Before this change, user tags were table-only state: upsert_session_tag wrote session_tags, removals deleted only that table row, and the root tags command exposed its own add/remove path alongside query-first mark mutation. That kept user tags outside the assertion substrate and left two CLI mutation homes.

Solution

  • Mirror user session_tags writes into deterministic kind=tag assertions when the active tier owns the assertions table.
  • Mark mirrored user-tag assertions deleted when ArchiveStore.remove_user_tags removes the user tag.
  • Keep root polylogue tags as read-only live tag counts, with help/hints pointing tag mutation to polylogue find QUERY then mark --tag-add/--tag-remove.
  • Update generated CLI help/reference and focused storage/API/CLI tests to prove the storage helper, archive facade, public Polylogue.add_tag/remove_tag, and CLI read path.

This does not delete the root tags command yet: it remains the live user-tag count view until that read capability has an equivalent home.

Verification

  • devtools test tests/unit/storage/test_archive_tiers_assertion_write_through.py tests/unit/storage/test_archive_tiers_archive.py::test_archive_tiers_archive_facade_adds_user_tags tests/unit/storage/test_user_state_contracts.py::test_tags_and_metadata_remain_table_backed_user_metadata tests/unit/api/test_facade_contracts.py::test_archive_tiers_api_user_mutations_write_user_tier tests/unit/cli/test_command_aux_runtime.py::test_tags_command_plain_paths_cover_empty_hint_and_tabular_counts tests/unit/cli/test_json_envelope_contract.py::TestTagsJsonEnvelope::test_tags_json_has_status_ok 'tests/unit/cli/test_json_envelope_contract.py::TestQueryShapedJsonMatrix::test_format_json_uses_success_envelope[args0-tags]' tests/unit/cli/test_deterministic_output.py::TestJsonOutputValidity::test_tags_json_is_valid tests/unit/cli/test_deterministic_output.py::TestJsonDeterminism::test_tags_json_deterministic 'tests/unit/cli/test_deterministic_output.py::TestJsonEnvelopeParametrized::test_json_only_commands_reject_other_formats[tags-yaml-rejected]' -> 22 passed
  • devtools render all --check -> sync OK
  • devtools lab scenario verify-baselines -> 76 exercises, all baselines match
  • devtools verify --quick -> exit_code 0
  • devtools verify --seed-testmon --skip-slow -> terminated after the broad seed lane emitted multiple failures and then ran for ~88 minutes without a final report; branch-specific focused tests and verify --quick are green, but the fresh-worktree seed baseline is not green

Ref #1842

Summary by CodeRabbit

Release Notes

  • API Changes

    • Updated polylogue tags command to list tags only; tag add/remove operations now use polylogue find ... then mark --tag-add/--tag-remove workflow.
  • Documentation

    • Updated CLI reference and help text to reflect simplified tag listing interface and new tag modification workflow.
  • Improvements

    • Enhanced tag persistence and tracking in the database.

Problem: #1842 cannot finish the user-overlay command cleanup while user tags remain a direct table-only mutation path. The root tags command also still exposed its own add/remove workflow instead of the query-first mark action that owns tag mutation.

What changed: user tag writes now mirror active tag assertions and removals tombstone the mirrored assertion. The root tags command is read-only tag-count output; tag mutation is taught through polylogue find QUERY then mark --tag-add/--tag-remove. Storage, facade, CLI, generated help, and showcase baselines were updated together.

Verification: devtools test affected storage/API/CLI selection -> 22 passed; devtools render all --check -> sync OK; devtools lab scenario verify-baselines -> 76 exercises, all baselines match; devtools verify --quick -> exit_code 0.

Ref #1842
@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Sinity, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 51 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 656854f1-5128-48dd-a616-c0b54485fc03

📥 Commits

Reviewing files that changed from the base of the PR and between fc97b8a and fdaabc8.

📒 Files selected for processing (2)
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • tests/unit/storage/test_archive_tiers_archive.py
📝 Walkthrough

Walkthrough

The PR narrows the tags CLI command to list-only by removing session mutation options (--add-tag, --remove-tag, SESSION_ID) and updating hints, docs, and baselines to redirect mutations to mark --tag-add/--tag-remove. Simultaneously, it introduces deterministic assertion-ID helpers and write-through mirroring of user session tags into the assertions storage tier on both upsert and delete.

Changes

Session tag assertion mirroring and tags CLI simplification

Layer / File(s) Summary
Deterministic assertion ID and upsert helpers
polylogue/storage/sqlite/archive_tiers/user_write.py
Adds assertion_id_for_session_tag (normalizes tag, computes deterministic ID) and upsert_session_tag_assertion (builds TAG assertion value payload and upserts for user-source tags only); both exported via __all__.
Write-through mirroring in upsert and delete
polylogue/storage/sqlite/archive_tiers/write.py, polylogue/storage/sqlite/archive_tiers/archive.py
upsert_session_tag calls _mirror_session_tag_assertion_if_available (guards on tag_source == "user" and assertions table presence via _table_exists) after the row write. remove_user_tags calls mark_assertion_status(..., "deleted") for each actually-deleted row's derived assertion ID.
tags CLI command narrowed to list-only
polylogue/cli/commands/tags.py, docs/cli-reference.md, tests/baselines/showcase/help-tags.txt
Removes session_id, --add-tag, and --remove-tag from the Click command; updates empty-result hint, docstring examples, CLI reference docs, and help baseline to list-only usage directing mutations to mark.
Storage write-through and contract tests
tests/unit/storage/test_archive_tiers_assertion_write_through.py, tests/unit/storage/test_archive_tiers_archive.py, tests/unit/storage/test_user_state_contracts.py
New test verifies full mirrored assertion envelope after upsert_session_tag; existing tests extended to assert active/deleted assertion statuses for specific session tags.
Facade contract and CLI runtime tests
tests/unit/api/test_facade_contracts.py, tests/unit/cli/test_command_aux_runtime.py
Facade test asserts deleted/active assertion statuses for review/bulk-a tags after mutation calls. CLI tests update empty-hint string expectations to the new polylogue find QUERY then mark --tag-add text.

Sequence Diagram(s)

sequenceDiagram
  participant WriteLayer as upsert_session_tag
  participant Mirror as _mirror_session_tag_assertion_if_available
  participant UserWrite as upsert_session_tag_assertion
  participant Archive as remove_user_tags
  participant AssertionStore as mark_assertion_status

  WriteLayer->>Mirror: conn, session_id, tag, tag_source=user
  Mirror->>Mirror: _table_exists(conn, assertions)
  Mirror->>UserWrite: upsert TAG assertion with deterministic ID
  UserWrite-->>Mirror: ArchiveAssertionEnvelope
  Archive->>Archive: DELETE from session_tags, capture rowcount
  Archive->>AssertionStore: assertion_id_for_session_tag, mark status=deleted
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Sinity/polylogue#1581: Modifies the same tags_command empty-hint logic and corresponding test_command_aux_runtime.py expectations that this PR also updates.
  • Sinity/polylogue#1928: Uses the same pattern of deterministic assertion IDs and mark_assertion_status(..., "deleted") for mirrored assertion rows during user-tier deletions.
  • Sinity/polylogue#2078: Touches the same test_user_state_contracts.py assertion-parity expectations around tag/metadata mirroring into the assertions table.

Poem

🐇 Hop, hop, the tags command grew lean,
No add, no remove — just list what's been seen!
The storage now mirrors each tag with care,
A deterministic ID floating through the air.
mark --tag-add is the new rabbit trail,
Every assertion tracked, without fail! 🏷️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: refactoring user tags to be backed by assertions instead of table-only state, matching the primary objective of this PR.
Description check ✅ Passed The description comprehensively covers all template sections: summary of changes, problem statement, detailed solution, verification steps with test commands and results, and risks/follow-ups section addressing seed-testmon concerns.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/assertion-overlay-commands

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 and usage tips.

github-actions Bot pushed a commit that referenced this pull request Jun 19, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@polylogue/storage/sqlite/archive_tiers/archive.py`:
- Around line 1226-1233: Add a table existence check before calling
mark_assertion_status to prevent crashes when the assertions table doesn't
exist. Wrap the mark_assertion_status call that updates the assertions table
with a guard condition using _table_exists(user_conn, "assertions"), similar to
the defensive check pattern already implemented in write.py. This ensures that
when user.db contains session_tags but not assertions, the code handles the
missing table gracefully instead of raising sqlite3.OperationalError.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f8c03d24-5ba1-4a4e-b794-06d7ae99f5aa

📥 Commits

Reviewing files that changed from the base of the PR and between 8c695a1 and fc97b8a.

📒 Files selected for processing (11)
  • docs/cli-reference.md
  • polylogue/cli/commands/tags.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/storage/sqlite/archive_tiers/user_write.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • tests/baselines/showcase/help-tags.txt
  • tests/unit/api/test_facade_contracts.py
  • tests/unit/cli/test_command_aux_runtime.py
  • tests/unit/storage/test_archive_tiers_archive.py
  • tests/unit/storage/test_archive_tiers_assertion_write_through.py
  • tests/unit/storage/test_user_state_contracts.py

@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: fc97b8a666

ℹ️ 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 added 2 commits June 19, 2026 05:05
Problem: CodeRabbit correctly noted that remove_user_tags could tombstone a mirrored assertion even when a legacy user.db still had session_tags but no assertions table.

What changed: guard the assertion tombstone with the existing archive-tier table-existence helper and add a regression that drops assertions from user.db before removing a tag.

Verification: devtools test tests/unit/storage/test_archive_tiers_archive.py::test_archive_tiers_archive_facade_adds_user_tags tests/unit/storage/test_archive_tiers_archive.py::test_archive_tiers_remove_user_tags_tolerates_legacy_user_db_without_assertions -> 2 passed; devtools verify --quick -> exit_code 0.

Ref #1842
Problem: Codex correctly noted that adding an already-present user tag skipped the upsert helper, so archives with pre-existing table-only session_tags would not repair their missing assertion mirror.

What changed: duplicate add_user_tags calls now still route through upsert_session_tag to backfill the mirrored assertion while preserving affected_count=0. A regression deletes the assertion row and proves the duplicate add restores an active mirror.

Verification: devtools test tests/unit/storage/test_archive_tiers_archive.py::test_archive_tiers_archive_facade_adds_user_tags tests/unit/storage/test_archive_tiers_archive.py::test_archive_tiers_remove_user_tags_tolerates_legacy_user_db_without_assertions tests/unit/storage/test_archive_tiers_archive.py::test_archive_tiers_duplicate_user_tag_add_backfills_missing_assertion -> 3 passed; devtools verify --quick -> exit_code 0.

Ref #1842
@Sinity
Sinity merged commit 07c48c0 into master Jun 19, 2026
14 checks passed
@Sinity
Sinity deleted the feature/refactor/assertion-overlay-commands branch June 19, 2026 03:18
Sinity added a commit that referenced this pull request Jun 19, 2026
## Summary

Move the user-overlay command families off the root `polylogue` surface
and under the existing `polylogue user-state` owner. This removes root
`blackboard` and `feedback`, keeps their behavior available as
`polylogue user-state blackboard ...` and `polylogue user-state feedback
...`, renames the implementation modules away from root-command names,
refreshes generated help/docs/baselines, and deletes the stale CLI audit
document that contradicted the reopened #1842 scope.

## Problem

#1842 was reopened because the public CLI still taught a flat command
zoo after several earlier absorption slices landed. After #2144, user
tags are assertion-backed and the next coherent overlay step is to make
reader-user-state own the remaining blackboard/feedback surfaces instead
of leaving them as root command families. The stale `docs/cli-audit.md`
also preserved old conclusions such as root feedback/blackboard and old
query verbs, making it more misleading than useful.

## Solution

- Register `user-state` as a lazy Click group and attach `blackboard`
and `feedback` beneath it, without hidden root aliases or compatibility
shims.
- Rename `polylogue/cli/commands/blackboard.py` and `feedback.py` to
`user_state_blackboard.py` and `user_state_feedback.py`, and update
examples/docstrings to the new command path.
- Update archive route metadata, behavior tests, JSON command smoke
coverage, completion tests, snapshots, generated help baselines, CLI
reference, topology projection, and agent/docs surfaces.
- Delete `docs/cli-audit.md`; the live reopened issue #1842 is now the
durable command-floor spec.
- Add per-exercise progress output to `devtools lab scenario
verify-baselines` so the 96-command showcase help lane is observable
instead of appearing hung.

## Verification

- `devtools test tests/unit/cli/test_blackboard.py
tests/unit/cli/test_json_output.py
tests/unit/cli/test_click_app.py::TestCliMetadata::test_retained_command_owners_are_registered
tests/unit/cli/test_completion_matrix.py
tests/unit/cli/test_status.py::test_archive_cli_route_catalog_reports_user_tier_surfaces
tests/unit/cli/test_status.py::TestNoArchiveStatus::test_direct_status_json_reads_archive_file_set_from_archive_tiers
tests/unit/cli/test_help_snapshots.py
tests/unit/cli/test_terminal_snapshots.py
tests/unit/cli/test_plain_cli_snapshots.py
tests/unit/showcase/test_exercise_catalog.py::TestExercisesByGroup::test_all_command_paths_have_generated_help_exercises
tests/unit/showcase/test_exercise_catalog.py::TestExercisesByGroup::test_inventory_includes_nested_command_paths`
-> `189 passed`
- `devtools lab scenario verify-baselines --update` -> `Ran 96
exercises`, updated baselines
- `devtools lab scenario verify-baselines` -> `Ran 96 exercises`, `All
baselines match.`
- `devtools render all --check` -> sync OK
- `devtools verify --quick` -> `exit_code: 0`
- `devtools verify` -> refused because this fresh worktree has no seeded
testmon DB: `pytest-testmon is not seeded; run devtools verify
--seed-testmon ...`

Ref #1842
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 75.F114 / P2: refuted at the checked revision: The requested backfill concerns user tags retained in the predecessor table-only archive representation. AGENTS.md:74-77 forbids importing or reading that old state into fresh v1, and :192-194 rejects dual-write/compatibility paths; rebuilding a legacy mirror is not the current tag contract.

Only the rows listed above are dispositioned. Held findings remain open.

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