Repository navigation
fix: Refuse in-process insight maintenance with its sealed owner named - #5030
Conversation
Problem: `Polylogue.rebuild_insights` routed through `_execute_facade_mutation` into `OperationExecutor.execute_bound`, which #4867 made a hard refusal for `mutate-rebuild-insights`. The landing commit added the whole insight-acceptance machine and never touched the facade, so the Python API and the MCP maintenance dispatcher (its only non-test production caller) were both dead, surfacing an internal `MutationTransactionError` as `internal_error`. Solution: the facade has no execution route for insight maintenance, because it cannot have one. A sweep is authorized page by page -- manifest frozen, previews staged, parts sealed, ordinals started through `begin_accepted_insight_part` -- which needs durable audit authority, a pinned index generation, and the resident session-profile publication owner. `polylogued run` is the required live-write owner for exactly that reason. So the facade raises the typed `InsightMaintenanceRequiresDaemonError` naming `polylogued run` and the daemon operation `maintenance.insights.rebuild`, and MCP maps it to a `daemon_required` refusal carrying that route. Rejected: loosening `begin_bound` re-opens the bypass its guard names -- an unsealed staging page as execution authority, and `session_ids=None` becoming an accepted full sweep after the fact. Delegating over `DaemonClient.operation_to_completion` is viable transport but not viable today: the completed insight envelope carries the machine-lifecycle state, which does not satisfy the declared `InsightRebuildResult` counts contract, so `validate_operation_result` would reject the daemon's own result. `InsightsRebuildActuator` is untouched and stays the plan builder used by `insight_planning`. Verification: devtools test on the three storage insight files plus tests/unit/api/test_facade_contracts.py, tests/unit/api/test_operation_executor_routes.py, tests/unit/mcp/test_privileged_tools.py and tests/unit/core/test_insight_export_bundles.py -- PASSED exit=0, receipt .cache/verify/runs/20260913T195912Z-focused-test-1334982-216de19e. devtools verify --quick exit 0. `devtools schema closure` marks polylogue/core/errors.py IN the derived closure, but the measured index and ops identities are byte-identical before and after this change (bd388fcf53e4.../0a44d6a6764c...), so no reconvergence is required. Residual: MCP and library callers still cannot run a rebuild; the sanctioned route is the daemon operation, and closing the `InsightRebuildResult` contract gap is the prerequisite for delegating instead of refusing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
…erializer Problem: eleven tests across the storage insight files, four facade-contract tests, and the API/MCP route tests drove insight materialization through `Polylogue.rebuild_insights`, which now refuses in process. Two further facade-contract failures were unrelated to that cluster and equally pre-existing on the branch tip. Solution: tests that assert *what the materializer produces* now call `rebuild_session_insights_sync` through one shared helper, `tests.infra.storage_records.materialize_session_insights`. That is a production route, not a test shim: both sanctioned owners reach it -- `InsightsRebuildActuator.apply` and the daemon's own per-session publication path in `storage/derived/session/derivation.py`. What each law proves is unchanged; only who asks for the rows moved. Anti-vacuity, per law touched: - materialization laws: profile/session agreement, no phantom profiles, no orphan work events or phases, rebuild idempotence -- red if the materializer emits a row for a missing session, drops one for a live session, or changes the profile set on a second pass. - provenance: red if a materialized row stops carrying its materialized_at and input provenance, or if tag-rollup session counts stop matching the tagged sessions. - rebuild progress: red if the full-rebuild DELETE phase stops emitting a per-table heartbeat, or if a failed full rebuild stops preserving prior profiles. The heartbeat is asserted at its source rather than through a facade parameter that no longer reaches it. - executor route: renamed to state its real subject -- the facade refuses *without entering the executor*. It now also records `prepare_bound_for_archive`, so staging a preview before refusing is red, as is re-raising `MutationTransactionError` to a public caller. - MCP maintenance: red if a confirmed rebuild executes in process (`is_error` false) or leaks the internal guard again (`internal_error`). The two unrelated failures: `get_session_orchestration` was a genuinely uncovered async facade method and is now categorized as bespoke, naming the file that covers it -- the discovery gate working as designed. The `stale_work_event_inference_count` expectation was stale: the profile row in that test is inserted by hand and carries no input binding, so binding-based inspection (#4849) correctly reports its inference rows stale. Asserting 1 keeps the reading honest; it goes red if inspection stops classifying unbound rows. Verification: devtools test on the three storage insight files plus tests/unit/api/test_facade_contracts.py, tests/unit/api/test_operation_executor_routes.py, tests/unit/mcp/test_privileged_tools.py and tests/unit/core/test_insight_export_bundles.py -- PASSED exit=0, receipt .cache/verify/runs/20260913T195912Z-focused-test-1334982-216de19e. tests/unit/core/test_resume.py passes except test_resume_candidates_preserve_resolvable_exact_jaccard, confirmed failing on the untouched tip (receipt .cache/verify/runs/20260913T200236Z-focused-test-1339607-d2348922): a resume overlap-scorer failure with no connection to this cluster, left for its owner. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reachedNext included review available in 49 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (12)
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 |
…e unit (#5031) Closes `polylogue-6rcy2` (P0). Unblocks the campaign's own pre-build verification and `polylogue-1xc.14.1` AC14. ## Summary Make every test directory a package so the corpus collects as one unit — **22,436 tests, zero dropped** — and add a quick gate so the precondition cannot silently regress. ## Problem The full corpus could not collect, so it had never run as one. CLAUDE.md requires exactly that: "the corpus runs as one collection; partitioning it would drop the edges of every test the last shard did not collect." Both the campaign's full-corpus gate and `devtools verify --all` were therefore unobtainable. `pyproject.toml` sets `testpaths = ["tests"]` with default *prepend* import mode, which needs unique module basenames or `__init__.py` packages. `tests/unit/` had one but its subdirectories did not, so modules imported under bare top-level names and collided. Fifteen duplicate basenames existed on master. It went unnoticed because any selection touching only one side of a collision collects fine — `tests/unit/daemon + tests/unit/storage` ran 5,476 tests happily because `operations/` was not selected. Every focused run was green; only the run nobody completed was broken. ## Solution 19 `__init__.py` files. The protection is **structural, not the gate**: with every test directory a package, module names are package-qualified by path, so a new duplicate basename becomes *harmless* rather than fatal. `devtools gate test-packages` (`devtools/verify_test_packages.py`, `in_quick=True`) defends the precondition that makes that true — it fails when any directory holding a collectible module, or any ancestor in its package chain, lacks `__init__.py`. A new test directory without one fails the quick gate before it can ever collide. Anti-vacuity is named in the test file: remove the `__init__.py` check or the ancestor walk and two tests go red. A second, separate collection error is also fixed: conftest's `pytest_make_parametrize_id` called `repr()` unguarded, so a parameter whose `__repr__` raises turned into `RuntimeError: repr failed` at collection time. ## Verification — nothing was dropped This is the hazard worth proving rather than asserting: a packaging change can make collection *succeed while collecting fewer tests*, which would be worse than the honest failure it replaced. Per-top-level-directory counts, BEFORE measured as three collision-free partitions covering the corpus once each (a single `tests/unit` collection is impossible before the fix): | top-level | BEFORE | AFTER | delta | |---|---|---|---| | fixtures | 9 | 9 | 0 | | fuzz | 394 | 394 | 0 | | infra | 78 | 78 | 0 | | integration | 189 | 189 | 0 | | property | 223 | 223 | 0 | | unit | 21448 | 21496 | **+48** | | visual | 20 | 20 | 0 | Pytest's own totals agree: BEFORE 21921 + 138 + 329 = 22388; AFTER one collection = 22436. Stronger than counts — the actual node-id **sets** were diffed: - **in BEFORE but not AFTER: 0.** Nothing silently dropped. - in AFTER but not BEFORE: 48, every one accounted for — `test_devtools_main.py` (23) + `test_project_motd.py` (18), the 41 tests that were uncollectable due to the `repr()` bug, plus `test_verify_test_packages.py` (7), this gate's own tests. ``` devtools verify --quick 15/15 gates incl. the new one, exit 0 devtools render all --check exit 0 ``` ## What the first full run revealed The corpus run was killed at 89% by a host-side reaper, so it is **interrupted verification, not a result** — but it produced the first real measurement of the red surface, which had been undercounted at 33. Roughly 168 F/E across 50 files. The 16 largest offenders were re-run **in isolation on this head** to classify them: - **~109 genuine head failures.** Fail alone at `f494b276f`: `test_embed_status_fast` (31F), `test_reset` (20F), `test_query_exec_laws` (10F), `test_plain_cli_snapshots` (7F/8E), `test_temporal_source_taxonomy` (6E), `test_excise` (6F), and others. The largest shares one root cause — `TypeError: unsupported embedding status configuration: _Cfg`, production code refusing the test's config type. A real contract break, not pollution. - **~9 order-dependent.** Pass alone, fail combined: `test_mcp_call_log` (4F), `test_insight_export_bundles` (3F), `test_session_insight_rebuild_progress` (2F). - **6 already fixed** by #5030 — `test_insight_materialization_laws` passes here. - ~34 single-failure files not individually classified. **None are caused by this change**: `test_embed_status_fast`, `test_reset` and `test_query_exec_laws` fail identically at pristine `f494b276f` with both commits absent. Tracked under `polylogue-7lhl5`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an automated validation check to ensure test directories are structured as valid Python packages. * Added human-readable and machine-readable reporting for package validation results. * **Bug Fixes** * Test collection now continues when a parameter cannot be represented, using a safe fallback identifier instead of failing. * **Tests** * Added coverage for package validation, including nested directories, configuration-only directories, and cache directories. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Triage of the daemon/async share of the 58 corpus failures. **21 of 23 fixed** across 17 commits — and it uncovered **silent production data loss** that would have crippled the from-scratch rebuild. ## The finding that matters The brief framed the four `test_daemon_resilience` failures as "grouping or daemon lifecycle". Raising the module timeout — a 300s wait under a 120s ceiling could **never** complete — unmasked the real diagnostics. On an **idle** machine `sigkill_recovery` reported *byte-identically* the same "20 messages" as the corpus run, proving load was not the cause. **The daemon ingested one session per root and stopped.** `FileIntakeAdapter.discover` advanced its cursor past the entire discovered page while the dispatcher consumed only its head, and the walk only moves forward. Compounding it, adapters charge `estimated_cost` in **bytes** while the service budget was `64` — a *count*. Every session after the lexicographically-first was retained on disk and never archived. Introduced by `#4913`, which made the dispatcher the sole discovery authority and disabled the watcher's own catch-up. This is not a test defect. The fresh-start ruling is *"move the six database files aside, start the daemon fresh, let ordinary convergence rebuild everything from the actual sources"* — so the rebuild **is** this code path. Building on the previous head would have produced an archive containing roughly one session per source root and reported success. ## Classification of all 23 **PRODUCT-BUG (8)** — the discovery/budget loss above (resilience ×3 + `large_session_file`); workload probe ×2 (the adapter treated "file exists" as "tier bootstrapped", and `inspect` opened a DB to answer an empty question); MCP clamp (the CLI clamps `limit=-1`, MCP refused it — the declared clamp was applied to the routing probe but not the typed request); daemon SIGTERM forensics (the signal handler wrote without the process-wide lease, `UnleasedWriteError` swallowed → `(None, 'signal')`). **STALE-TEST (8)** — the insight cluster ×4 (still calling the facade #5030 retired); visual ×2, red since #4645's WebUI cutover because `tests/visual/` is not in the fast gate; `daemon_status` (`(0 sessions, 1 message)` is unreachable by construction post-#5027); demo seed. **ORDER-DEPENDENT (3)** — `test_daemon_cli.py`. Passed alone *and* across `tests/unit/daemon`; the corpus receipt showed a `MagicMock` and a shut-down adapter leaking through the process-global `_SHARED_COMPUTE_ADAPTER`. `reset_daemon_compute_adapter()` already existed and **nothing called it**. Verified red→green with a deterministic two-file reproducer. **TEST-INFRA (3)** — `live_read_amplification` (double drifted from a keyword-only signature); `resume` (rename debris from #4614, `insights` vs `analysis`); `write_path_state_machine`. **Root verb (1)** — `verification-export` regrew the surface `985e0f9d9` folded. The verb was wrong, not the test. ## Two left unfixed, deliberately - **`test_demo_seed_verify`** — Codex declares `parent_dispatch` structurally absent, so `mapping_state:resolved` is unreachable for that fixture (confirmed by counterfactual: forcing the origin gate only changes the refusal reason). A Claude Code delegation fixture was started; each step revealed another required piece, so it was **reverted cleanly** rather than left half-built. - **`test_installed_package_smoke`** — diagnosed precisely, then **both commits reverted** after three fixes each broke a different legitimate caller. The third was rejected by `devtools gate layering`'s own ratchet. That the architecture refuses the CLI-layer catch says this needs a deliberate owner decision, not a triage patch. Full rationale is in the revert commit. ## Verification ``` 2,976 passed, 0 failed devtools verify --quick exit 0, 15/15 gates ``` ## Residuals recorded in commits A pre-existing `_assert_resolved_link` property failure (replayed against base — fails there too, no delete involved); an unleased-writer bug in the daemon health/cursor-lag path; a whale-pass deadlock against the daemon's own ownership flock; and a note that two reds in `tests/unit/sources/` assert FTS convergence debt which the inline repair here makes obsolete. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Updated the verification export command to use `verify export`. * Newly ingested sessions become searchable immediately. * Improved intake processing so skipped items can be rediscovered. * **Bug Fixes** * Out-of-range session list limits are now handled safely. * Improved daemon lifecycle signaling under write-lease enforcement. * Clearer errors are provided when source databases are missing required data. * Intake processing now uses a byte-based default budget. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Closes the largest cluster under
polylogue-7lhl5— 11 test failures plus the 6pre-existing
test_facade_contracts.pyfailures.Summary
Replace a leaked internal
MutationTransactionErrorwith a typed, actionablerefusal naming the sanctioned route, and retarget the insight materialization
laws onto their production materializer.
Problem
Polylogue.rebuild_insightswas dead. It called_execute_facade_mutation(
api/archive.py:2734-2770) intoexecutor.execute_bound, which is refused atoperations/mutation_transaction.py:910-920. Landing commit1d901ec73(#4867)added the whole insight-acceptance machine and never touched
api/archive.py,so the facade was simply left behind.
Live impact: MCP's
rebuild_insightsdispatcher(
mcp/server_cutover.py:2384-2389, gated onconfirm=true) was the solenon-test production caller and was dead; the public Python API was dead. The
daemon route (
maintenance.insights.rebuild) always worked. The CLI has norebuild-insights verb.
Decision: typed refusal, not delegation
The facade cannot hold the authority. A sweep is sealed page by page — manifest
frozen, previews staged, parts sealed, ordinals started through
begin_accepted_insight_part— which needs durable audit authority, a pinnedindex generation and recipe binding, and the resident session-profile
publication owner. CLAUDE.md names
polylogued runthe required live-writeowner for exactly this.
Delegation was pursued and rejected on evidence, not preference. The
transport does exist and is reusable:
daemon_client.pyhasDaemonClient.operation_to_completion, already used by CLI verbs to delegatemutations from non-daemon processes. It was rejected on a concrete blocker — the
completed insight envelope's result is the machine-lifecycle state from
machine_request_state, carryingparts/affected_countbut not thedeclared
InsightRebuildResultcounts, sovalidate_operation_resultwouldreject the daemon's own result. Delegating today means shipping unverifiable
code against a wire contract that is itself unfulfilled. When that contract is
completed, this refusal is the natural place to swap in delegation.
Neither guard was loosened, and
InsightsRebuildActuatoris untouched — itremains the plan builder used by
insight_planning.py.What callers now experience
InsightMaintenanceRequiresDaemonError(code="daemon_required",HTTP 503) naming
polylogued runandmaintenance.insights.rebuild. Themessage is fixed strings only, never user data, so any surface can forward it.
daemon_requirederror envelope carrying that route, insteadof
internal_errorwrapping aMutationTransactionError.Neither can run a rebuild — which is honest, and an improvement over dead.
The six facade-contract failures
All confirmed pre-existing on untouched tip
a3d6ffe2b(receipt20260913T193858Z-focused-test-1293934-0eb4f721) before being touched:test_no_undiscovered_async_methodswas the discovery gate workingcorrectly —
get_session_orchestrationis genuinely uncovered there. It isnow categorized as bespoke, naming the file that covers it.
stale_work_event_inference_countwas a stale expectation: the profile row ishand-inserted with no input binding, so binding-based inspection (feat: Converge aggregate insights by canonical partition with value-com… #4849)
correctly calls its inference rows stale. Asserting 1 is the honest reading.
Scope widened where the same root cause reached
tests/unit/core/test_resume.pyandtest_insight_export_bundles.pyalso calledthe dead facade. Tests now go through one helper on a real production route —
both
InsightsRebuildActuator.applyand the daemon's own per-session publicationpath call
rebuild_session_insights_sync. Per-law anti-vacuity conditions are inthe test commit message.
Verification
Schema closure — measured, not assumed.
devtools schema closuremarkspolylogue/core/errors.pyIN the derived closure, so the identity wascomputed rather than inferred: index and ops identities are byte-identical
before and after (
bd388fcf53e4…/0a44d6a6764c…). No reconvergence isrequired. Closure membership is not the same as an identity move.
Residuals
Not this cluster, left for its owner:
test_resume_candidates_preserve_resolvable_exact_jaccardfails on theuntouched tip (receipt
20260913T200236Z-focused-test-1339607-d2348922) — aresume overlap-scorer failure unconnected to insight maintenance. Tracked under
polylogue-7lhl5.🤖 Generated with Claude Code
https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK