Repository navigation
feat(assertions): export user-tier assertions (#1883) - #2098
Conversation
|
Warning Review limit reached
More reviews will be available in 44 minutes and 47 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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (24)
📝 WalkthroughWalkthroughThis PR introduces a new ChangesAssertion Export Feature & Feedback Storage Migration
Archive Query Response Shape Update
Devtools Fixes and Test Infrastructure
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: f6c6c9119b
ℹ️ 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".
f6c6c91 to
e10cf2f
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@tests/unit/cli/test_archive_maintenance_cli.py`:
- Around line 51-55: The _seed_assertion_export_rows helper function is directly
creating and initializing the user.db database via sqlite3.connect and
initialize_archive_tier instead of using the proper test fixtures. Refactor this
function to accept workspace_env and SessionBuilder as parameters (or have the
calling tests use these fixtures) and use SessionBuilder to create the database
connection and perform initialization, replacing the direct sqlite3.connect call
and the explicit initialize_archive_tier invocation with the appropriate
SessionBuilder methods for proper test setup.
In `@tests/unit/storage/test_archive_tiers_assertions.py`:
- Around line 355-357: Refactor the test function
`test_list_assertions_for_export_covers_all_kinds_and_statuses` to use the
mandated fixture stack instead of directly initializing the database. Replace
the `tmp_path` parameter and `_connect` call with the `workspace_env` fixture
for isolated XDG paths and use `SessionBuilder` to set up the database
connection. If the test performs timestamp-sensitive operations, also add the
`frozen_clock` fixture as a parameter. Update the function signature and body to
accept these fixtures and use them for database initialization instead of the
current direct connection approach.
In `@tests/unit/storage/test_no_string_interpolated_sql.py`:
- Line 151: Remove the variable names `_assertion_columns`, `any_terms`, and
`session_clause` from the global `_TRUSTED_IDENTIFIER_NAMES` set since trusting
them globally bypasses safety checks for all future f-string SQL interpolations
without proper audit context. Instead, whitelist only the specific audited call
sites that legitimately use these variables by adding them to `_AUDITED_SITES`
with full context, ensuring each usage is explicitly reviewed and approved
rather than implicitly trusted by variable name.
🪄 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: 609c4fd6-6e4d-4971-a3a3-e137b0765b7a
📒 Files selected for processing (21)
devtools/query_memory_budget.pydevtools/verify.pydocs/test-quality-workflows.mdpolylogue/cli/commands/maintenance.pypolylogue/cli/commands/status.pypolylogue/storage/insights/feedback/__init__.pypolylogue/storage/sqlite/archive_tiers/user_write.pytests/conftest.pytests/unit/cli/__snapshots__/test_help_snapshots.ambrtests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambrtests/unit/cli/__snapshots__/test_terminal_snapshots.ambrtests/unit/cli/test_archive_maintenance_cli.pytests/unit/cli/test_click_app.pytests/unit/cli/test_diagnose_and_error_discipline.pytests/unit/cli/test_query_exec_laws.pytests/unit/daemon/test_daemon_cli.pytests/unit/daemon/test_web_reader.pytests/unit/sources/test_live_batch_support.pytests/unit/storage/test_archive_tiers_assertions.pytests/unit/storage/test_no_string_interpolated_sql.pytests/unit/test_pytest_temp_policy.py
| def _seed_assertion_export_rows(archive_root: Path) -> None: | ||
| with sqlite3.connect(archive_root / "user.db") as conn: | ||
| conn.row_factory = sqlite3.Row | ||
| initialize_archive_tier(conn, ArchiveTier.USER) | ||
| upsert_assertion( |
There was a problem hiding this comment.
Replace direct SQLite seeding with the required test setup fixtures.
This helper bypasses the required test setup contract by creating and initializing user.db directly instead of using workspace_env and SessionBuilder.
As per coding guidelines, “For tests: use workspace_env fixture for isolated XDG paths, SessionBuilder for database setup, and frozen_clock fixture for timestamp-sensitive tests…”.
🤖 Prompt for 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.
In `@tests/unit/cli/test_archive_maintenance_cli.py` around lines 51 - 55, The
_seed_assertion_export_rows helper function is directly creating and
initializing the user.db database via sqlite3.connect and
initialize_archive_tier instead of using the proper test fixtures. Refactor this
function to accept workspace_env and SessionBuilder as parameters (or have the
calling tests use these fixtures) and use SessionBuilder to create the database
connection and perform initialization, replacing the direct sqlite3.connect call
and the explicit initialize_archive_tier invocation with the appropriate
SessionBuilder methods for proper test setup.
Source: Coding guidelines
| def test_list_assertions_for_export_covers_all_kinds_and_statuses(tmp_path: Path) -> None: | ||
| conn = _connect(tmp_path / "user.db") | ||
| try: |
There was a problem hiding this comment.
Use the mandated test fixture stack for this new storage test.
This test initializes user.db via tmp_path/_connect rather than the required workspace_env + SessionBuilder setup contract for tests.
As per coding guidelines, “For tests: use workspace_env fixture for isolated XDG paths, SessionBuilder for database setup, and frozen_clock fixture for timestamp-sensitive tests…”.
🤖 Prompt for 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.
In `@tests/unit/storage/test_archive_tiers_assertions.py` around lines 355 - 357,
Refactor the test function
`test_list_assertions_for_export_covers_all_kinds_and_statuses` to use the
mandated fixture stack instead of directly initializing the database. Replace
the `tmp_path` parameter and `_connect` call with the `workspace_env` fixture
for isolated XDG paths and use `SessionBuilder` to set up the database
connection. If the test performs timestamp-sensitive operations, also add the
`frozen_clock` fixture as a parameter. Update the function signature and body to
accept these fixtures and use them for database initialization instead of the
current direct connection approach.
Source: Coding guidelines
| # compile-time SELECT column-list constants (record projections) | ||
| "_session_record_select", | ||
| "_message_record_select", | ||
| "_assertion_columns", |
There was a problem hiding this comment.
Avoid globally trusting clause-bearing SQL fragments by variable name.
Adding any_terms and session_clause to the global trusted-name set lets any future f-string SQL interpolation with those names bypass this safety test without site-specific audit context. Keep these out of _TRUSTED_IDENTIFIER_NAMES and whitelist only audited call sites in _AUDITED_SITES.
Suggested tightening
- "any_terms",
- "session_clause",Also applies to: 167-168
🤖 Prompt for 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.
In `@tests/unit/storage/test_no_string_interpolated_sql.py` at line 151, Remove
the variable names `_assertion_columns`, `any_terms`, and `session_clause` from
the global `_TRUSTED_IDENTIFIER_NAMES` set since trusting them globally bypasses
safety checks for all future f-string SQL interpolations without proper audit
context. Instead, whitelist only the specific audited call sites that
legitimately use these variables by adding them to `_AUDITED_SITES` with full
context, ensuring each usage is explicitly reviewed and approved rather than
implicitly trusted by variable name.
e10cf2f to
ba36dec
Compare
ba36dec to
dd48264
Compare
|
Review follow-up at dd48264:\n\n- Fixed Codex P2: async correction listing now preserves valid flat assertion values as payloads, with regression coverage in tests/unit/insights/test_feedback.py.\n- Tightened the SQL interpolation audit per CodeRabbit: removed broad trusted names and moved assertion/session query interpolation to line-specific _AUDITED_SITES entries with rationale.\n- I did not apply the SessionBuilder fixture suggestion literally for user-tier assertion tests: these tests exercise the split user.db assertion helpers directly, and SessionBuilder is session/archive fixture infrastructure rather than the owner of user_tier.assertions. The tests still use isolated tmp/workspace roots and direct user-tier initialization where that is the unit under test.\n\nVerification after the fixes:\n- devtools test tests/unit/storage/test_no_string_interpolated_sql.py tests/unit/insights/test_feedback.py -k 'no_unaudited_string_interpolated_sql or audited_sites_are_real_violations or FeedbackStorage' -> 8 passed.\n- devtools verify --quick -> exit_code 0. |
|
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
Adds a durable assertion export surface for
user.db, moves split-archive learning-correction storage onto assertion rows, and fixes the verification harness issues exposed while proving the broad seed run.Problem
#1883 still had a backup/export/reset gap: assertions are irreplaceable user-tier state, but there was no direct export surface that included inactive/candidate/deleted rows. The split archive had also removed the old correction table while the async feedback storage path could still try to use it. During broad verification, the seed run exposed unrelated harness fragility: progress writes could race in parallel tests, xdist basetemp cleanup could interrupt report flush, and the memory-budget probe could report parent RSS larger than total tree RSS for very short commands.
Solution
ops maintenance assertion-exportwith JSONL/JSON output,--out,--kind,--status, and non-negative--limitfilters.list_assertions_for_export(...)andassertion_envelope_to_payload(...)over the typed assertion envelope so export output is deterministic and includes all statuses by default.user_tier.assertionswhen splituser.dbis present, and tombstone correction assertions on delete/clear.keyis absent buttarget_refcarries the note id.list_assertion_claimsand current CLI command inventory.Verification
devtools testfocused assertion/export/user-state/harness node set:29 passed.devtools testbroad-run regression nodes:7 passed.ruff checkandmypy --strictover changed files: passed.devtools verify --quick:exit_code: 0.devtools verify --seed-testmon --skip-slow: pytest seed completed with11280 passed, 1 xfailed; the enclosing first seed command failed only becausetests/unit/test_pytest_temp_policy.pyneeded formatting, then formatting and quick gate passed.devtools verify:exit_code: 0, affected pytest7 passed.Ref #1883
Summary by CodeRabbit
New Features
maintenance assertion-exportCLI command to export durable assertions from the archive in JSON or JSONL formats with optional filtering by kind and statusDocumentation