Repository navigation
feat(insights): materialize incident work-evidence graphs from archive content - #3336
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?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 reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. 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, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
✨ 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 |
…e content Problem: z9gh gap #2 of 3 (git/GitHub/Beads effect adapters = gap #1, done via PR #3327; MCP continuity replay = gap #3, separate parallel work). devtools.mandate_continuity_replay.build_repository_claim_graph builds work-evidence claim nodes purely from the external .beads/interactions.jsonl ledger -- it never reads a single archived session, message, or action. An operator investigating a real incident ("agent X did Y around time Z in repo R") needs to start from the archive's own record of what actually ran, which had no materialization path at all: node_from_projected_run and session_segment_from_observed_events (work_evidence.py) existed but were only ever exercised by unit tests, never called from production code. What changed: - polylogue/insights/incident_evidence_materialization.py: pure graph builder. Adapts real ProjectedRun/ObservedEvent evidence into a WorkEvidenceGraph -- one run node per session run (invoked-linked parent->subagent via each run's own parent_run_ref), one session-segment node per run summarizing its observed events, one claim node per subagent's own self-reported final result (subagent_finished events, produced-linked from the run), and one unresolved/inferred effect node per commit/PR/issue an in-session tool call mentioned (mentioned-linked from its segment). - polylogue/operations/incident_evidence_materialization.py: production wiring. Resolves an incident's session set, loads each full Session, and compiles its real run projection via the existing compile_session_run_projection (already used by storage.insights.session.rebuild's materialization-ledger stamp). This path is used deliberately over the thinner query_runs/query_observed_events read-model routes: after polylogue-dab/itvd those are CTE/source-derived only and never emit subagent self-reports or mentioned commit/PR/issue refs (confirmed by reading storage/sqlite/run_projection_relations.py) -- compiling from the full Session is what actually surfaces those signals. - polylogue/cli/commands/materialize_incident_evidence.py + click_command_registration.py: `polylogue ops materialize-incident-evidence`, selecting sessions by explicit --session-id and/or --repo/--since/--until/--contains (the same sparse clues a real incident starts from), dry-run by default, --yes to persist. Deliberately out of scope (see module docstring): actor/execution-context node population. node_from_projected_run already accepts optional actor_ref/execution_context_ref for a follow-on pass; fabricating a content-addressed ExecutionContextRef from a run's bare cwd/git_branch without a positive-evidence rule belongs to OriginSpec (polylogue-2qx), not guessed here. Ref polylogue-z9gh Co-Authored-By: Claude <[email protected]>
Problem: the prior commit (d8e5ac1) added the source-to-graph incident materialization module but had no tests, a real-data mypy bug (SessionSummary has .id, not .session_id), and no doc footprint -- devtools verify docs-coverage and hash-boundary-census both failed clean. What changed: - polylogue/cli/commands/materialize_incident_evidence.py: fix the SessionSummary.session_id -> .id attribute bug caught by mypy --strict. - tests/unit/insights/test_incident_evidence_materialization.py: pure graph-builder tests against a real compile_session_run_projection output (Task subagent + PR-mentioning tool call), covering run/segment nodes, invoked/represented_by/produced/mentioned edges, claim/effect derivation, and the content-addressed corpus snapshot ref. - tests/unit/operations/test_incident_evidence_materialization.py: end-to-end round trip through a real seeded SQLite archive (SessionBuilder -> SessionRepository.get_many -> materialize -> replace_work_evidence_graph -> get_work_evidence_graph), plus dry-run and not-found error paths. - tests/unit/cli/test_materialize_incident_evidence_command.py: CLI smoke tests for --session-id selection, dry-run vs --yes persistence, and the unknown-session-id UsageError. - docs/internals.md: document the new module/CLI command and why it uses compile_session_run_projection instead of the thinner query_runs/query_observed_events read-model routes. - docs/plans/hash-boundary-registry.yaml: register the new incident_corpus_snapshot_ref identifier-hash call site. - docs/cli-reference.md, docs/plans/topology-target.yaml, docs/topology-status.md: regenerated (devtools render all --check). Verification: - devtools test tests/unit/insights/test_incident_evidence_materialization.py \ tests/unit/operations/test_incident_evidence_materialization.py \ tests/unit/cli/test_materialize_incident_evidence_command.py -> 15 passed - mypy --strict polylogue/insights/incident_evidence_materialization.py \ polylogue/operations/incident_evidence_materialization.py \ polylogue/cli/commands/materialize_incident_evidence.py <the 3 new test files> \ -> Success: no issues found in 6 source files - ruff check / ruff format --check on all changed files -> clean - devtools render all --check -> exit 0 - devtools verify docs-coverage, hash-boundary-census -> clean - devtools verify --quick: one remaining failure is mypy's pre-existing, unrelated tests/unit/core/test_timestamp_guards.py:424 Hypothesis strategy-typing error, confirmed present via git stash against this same branch before these changes -- not touched by this PR. Ref polylogue-z9gh Co-Authored-By: Claude <[email protected]>
9a536f9 to
1678d20
Compare
…k bool env vars (#3340) ## Summary Fresh `devtools verify --all` re-triage of polylogue-p6rz ("pre-existing test failures unrelated to MCP cutover") against current master. Fixes several confirmed real regressions and stale test assertions found during the pass; files properly-scoped follow-up beads for the rest instead of leaving them as anonymous re-discoveries. ## Problem polylogue-p6rz's original list (from 2026-07-18) was stale: a lot has merged since. A fresh `devtools verify --all` run (107 failed, 14 errors on the pre-fix baseline) needed re-triage to separate fixed / persisting / newly introduced failures, and specifically to catch any real regression from this session's merges (query DSL AST schema, browser-capture approval flow, GitHub effect adapters, continuity replay wiring, etc.). ## Solution **Confirmed real regressions, fixed:** - `polylogue/config.py`: PR #3202's strict bool-env coercion rejected a blank `POLYLOGUE_FORCE_PLAIN=""` value with `ConfigError` instead of the old passthrough-as-falsy behavior, breaking a long-standing CLI test convention (and inconsistent with this same module's own NO_COLOR "blank means not requested" convention). Blank bool-key env values now resolve to `False`. - `polylogue/storage/sqlite/queries/mappers_support.py` and `polylogue/storage/blob_integrity.py`: PR #3155's three-tier JSON facade introduced `polylogue.core.json.JSONDecodeError` (a `ValueError` subclass, NOT a stdlib `json.JSONDecodeError` subclass), but two call sites still caught the stdlib type — silently losing `DatabaseError` diagnostic wrapping (field/record id context) and blob-corruption graceful degradation since 2026-07-19. **Stale test assertions / drifted mocks, fixed:** - `tests/unit/cli/test_color_and_layout.py`: tested `no_color_requested()`/ `should_use_plain()` as if they read `NO_COLOR` from the environment directly; PR #3079 made them pure passthroughs (env resolution moved to `config.py`, already covered elsewhere). Rewrote to test the passthrough contract. - `tests/unit/storage/test_durable_migrations.py`: hardcoded `USER_SCHEMA_VERSION == 9` / `applied_versions` tuple; PR #3068 bumped it to 10 without updating these two tests. - `tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr`: stale `index.db` `user_version`/`sqlite_stat1_rows` snapshot from before PR #3235's schema bump 42→43. - `tests/unit/cli/test_diagnostics.py`: `_patch_tool_count_store`'s fake `ArchiveStore.open_existing` lambda didn't accept the `read_timeout` kwarg PR #2964 added, and the fake store was missing `begin_read_snapshot()` (also from #2964's interruptible-read protocol) — 8 tests broken since 2026-07-17. - `tests/unit/devtools/test_mandate_continuity_replay.py` and `tests/unit/operations/test_work_effect_reconciliation.py`: both asserted the real `GitHubPullRequestEffectAdapter` fails against `Sinity/polylogue` — true only in an environment without `gh` auth (e.g. stock CI), false on any dev machine with `gh` authenticated for this repo (confirmed: `gh pr list --repo Sinity/polylogue` succeeds fine here). Forced deterministic unavailability via a nonexistent `gh_path` instead. - `tests/unit/storage/test_delegations_view.py`: 3 tests opened a bare `index.db`-only `ArchiveStore` (no `user.db`); PR #3068's new `archive_snapshot_epoch()` unconditionally requires `user_tier` attached. Added a sibling `user.db` bootstrap to the 3 affected fixtures — matches every other test's full-tier archive construction. - `tests/unit/architecture/test_surface_storage_boundary.py`: allow-listed two CLI commands (`reconcile_work_effects.py`, and `materialize_incident_evidence.py` — the latter landed on master via a concurrent session's PR #3336 mid-rebase) that construct `SessionRepository` directly instead of through `AppEnv.repository`, per the test's own documented remediation path. Filed polylogue-a7uk for the proper fix. **Concurrent-session note:** this branch was rebased onto master mid-flight after another session's PR #3332 landed fixing the exact same `test_timestamp_guards.py` hypothesis-6.161 mypy break I'd independently found and fixed — kept master's version (identical `st.one_of` split approach) rather than duplicating it. **Already tracked, not duplicated:** - `test_execution_control.py` `api.query_units` naming mismatch + `>=50000 VM steps` anti-vacuity mutation tests → polylogue-1ldl (fully root-caused 2026-07-20: PR #3018 made the mutation-under-test no longer expensive at this data scale). - `test_live_batch_support.py` stale `failed=[...]` assertion → polylogue-5202. - `test_archive_maintenance_cli.py` / `test_daemon_cli.py` 6-node cluster → polylogue-p5li. - `tests/infra/surfaces.py` stale `list_sessions`/`search` MCP tool-name lookups (affects `test_retrieval_readiness_laws.py`, `test_cross_surface_agreement.py`) → polylogue-t46.8 (MCP tool-sprawl replacement epic; p6rz's own original text already called this out-of-scope). **New follow-up beads filed (confirmed pre-existing, not this-session regressions, but not safe/minimal to fix inline):** - polylogue-57w4 — repair path still disagrees with converger on NULL-sort-key session-profile staleness (regresses PR #2900's own invariant; root cause not fully diagnosed). - polylogue-lbgc — seeded-archive corpus build hits `database is locked` under xdist parallel first-build (affects `test_plain_cli_snapshots.py`, `test_schema_generation.py`, likely others); confirmed not simple cross-worker contention (the build already holds an exclusive flock across the whole build+integrity-check section) — more likely an unclosed intra-process connection. - polylogue-e6a0 — `test_index_v37_fast_forward.py`'s v36 fixture predates the `action_pairs` runtime index added by PR #3210; attempted fix revealed the fixture's intended "before" shape needs the full same-version benign-DDL-convergence set, not just `ensure_runtime_indexes_sync` — reverted the attempt rather than ship an incomplete fixture. No regression found from this session's headline PRs (query DSL AST schema, browser-capture approval flow, continuity replay wiring) — the two GitHub effect-adapter tests and the `materialize_incident_evidence.py` boundary violation are environment/pattern issues in supporting test/command code, not in the new capability logic itself. ## Verification - `devtools test` on every changed test file individually: all green (see per-file evidence above). - `mypy --strict` on every changed `.py` file: clean. - `ruff format --check` / `ruff check`: clean. - Fresh `devtools verify --all` run against this branch in progress; will update this PR/polylogue-p6rz with the final authoritative count once it completes (~14 min runtime). Ref polylogue-p6rz
An independent, evidence-first audit of polylogue-z9gh's full 7-item acceptance criteria (not just the "3 named gaps" checkpoint closed this session via PRs #3327/#3336/#3334) found 4 of 7 AC items still have open child beads, with two genuinely operator/live-archive-gated: z9gh.7's AC2 (replaying the actual 2026-07-15 incident against a promoted archive) and polylogue-4s3c (live-scale steady-state envelope measurement). bd's own computed epic_closeable=false corroborates this independently. Co-Authored-By: Claude <[email protected]>
…ence through AppEnv (#3356) ## Summary Routes `reconcile_work_effects_command` and `materialize_incident_evidence_command` through the standard `AppEnv.repository` / `@click.pass_obj` context-object pattern instead of constructing `SessionRepository(db_path=active_index_db_path())` directly, removing a tracked architecture-boundary allow-list exception. ## Problem Both commands (from PR #3199/#3327 and PR #3336) imported `SessionRepository` directly from `polylogue.storage.repository` and constructed it manually instead of going through `AppEnv.repository` — the pattern every other CLI command uses. `tests/unit/architecture/test_surface_storage_boundary.py` had to special-case both files in its `ALLOWED` set rather than fix the violation (tracked by polylogue-a7uk). ## Solution - Added `@click.pass_obj` to both commands, with `env: AppEnv` as the first parameter. - Replaced the manual `async with SessionRepository(db_path=active_index_db_path()) as repository:` construction with `env.repository`, which resolves to the same cached repository via `RuntimeServices.get_repository()` (same underlying archive path). - Removed the now-unneeded allow-list entries in `test_surface_storage_boundary.py`. - Updated both commands' CLI tests (`test_reconcile_work_effects_command.py`, `test_materialize_incident_evidence_command.py`) to invoke through the real `cli` root group (`ops reconcile-work-effects` / `ops materialize-incident-evidence`) instead of the bare leaf command, matching `test_excise.py`'s existing pattern — this is what lets the root callback build a properly runtime-resolved `AppEnv` (an ad hoc `AppEnv()` constructed directly in a test has no resolved database path). ## Verification - `devtools test tests/unit/cli/test_reconcile_work_effects_command.py tests/unit/cli/test_materialize_incident_evidence_command.py tests/unit/architecture/test_surface_storage_boundary.py` → 162 passed - `mypy --strict polylogue/cli/commands/reconcile_work_effects.py polylogue/cli/commands/materialize_incident_evidence.py` → Success: no issues found in 2 source files - `ruff check` / `ruff format --check` on all changed files → clean - `devtools render all --check` → no "out of sync" surfaces - Pre-push hook (`devtools verify --quick`) passed on push Ref polylogue-a7uk Co-authored-by: Claude <[email protected]>
Summary
Implements gap #2 of polylogue-z9gh's three remaining named gaps
("source-to-graph incident materialization"). Gap #1 (production
git/GitHub/Beads effect adapters) landed in PR #3327. Gap #3 (real
paged/cancelled/cold-model MCP continuity replay) is separate, parallel
work by another agent and is not touched here.
Problem
devtools/mandate_continuity_replay.py'sbuild_repository_claim_graphbuilds work-evidence claim nodes purely from the external
.beads/interactions.jsonlledger — it never reads a single archivedsession, message, or action. An operator investigating a real incident
("agent X did Y around time Z in repo R") needs to start from the
archive's own record of what actually ran. That materialization path
did not exist:
node_from_projected_runandsession_segment_from_observed_events(polylogue/insights/work_evidence.py)were already defined but were only ever exercised by unit tests, never
called from production code (confirmed by grep — zero non-test callers).
Solution
polylogue/insights/incident_evidence_materialization.py(pure):adapts real
ProjectedRun/ObservedEventevidence into aWorkEvidenceGraph— onerunnode per session run (invoked-linkedparent→subagent via each run's own
parent_run_ref, never inferred fromtime/name proximity), one
session-segmentnode per run summarizing itsobserved events (
represented_by-linked), oneclaimnode persubagent's own self-reported final result (
subagent_finishedevents,produced-linked from the run that authored it), and oneunresolved/inferred
effectnode per commit/PR/issue an in-session toolcall mentioned (
mentioned-linked from its segment — deliberately notclaimed as independently observed; that corroboration is
insights.work_effects's job, layered on top exactly like it alreadylayers onto the Claude Workflow and Beads-ledger graphs).
polylogue/operations/incident_evidence_materialization.py(production wiring): resolves an incident's session set, loads each full
Session, and compiles its real run projection via the existingcompile_session_run_projection(already used bystorage.insights.session.rebuild's materialization-ledger stamp) —deliberately not the thinner
query_runs/query_observed_eventsread-model routes. Those routes are CTE/source-derived only after
polylogue-dab/itvd and only ever emit
session_started/tool_finishedevents with bare
tool-callobject refs (verified by readingstorage/sqlite/run_projection_relations.py) — no subagentself-reports, no mentioned commit/PR/issue refs. Compiling from the full
Sessionis what actually surfaces those real per-session signals.polylogue/cli/commands/materialize_incident_evidence.py+registration:
polylogue ops materialize-incident-evidence, selectingsessions by explicit
--session-idand/or--repo/--since/--until/--contains(the same sparse clues a realincident investigation starts from). Dry-run by default;
--yespersists via the same
replace_work_evidence_graphroute the ClaudeWorkflow materializer and work-effect reconciliation already use.
docs/internals.md: documents the module/CLI command and thedeliberate choice of
compile_session_run_projectionover the read-modelroutes.
Deliberately out of scope (honest accounting)
Actor/execution-context node population.
node_from_projected_runalreadyaccepts optional
actor_ref/execution_context_refand the node/edge modelalready has dedicated
actor/execution-contextkinds, so a follow-on passcan attach them without touching this module's shape — fabricating a
content-addressed
ExecutionContextReffrom a run's barecwd/git_branchstrings without a positive-evidence rule is exactly what OriginSpec
(polylogue-2qx) exists to police, not something to guess here.
Verification
devtools test tests/unit/insights/test_incident_evidence_materialization.py tests/unit/operations/test_incident_evidence_materialization.py tests/unit/cli/test_materialize_incident_evidence_command.py→ 15 passed. The operations/CLI tests seed a real session viaSessionBuilder(productionwrite_parsed_session_to_archivepath) with aTasksubagent call and a PR-mentioning tool result, then round-trip through the real repository:get_many→compile_session_run_projection→materialize_incident_evidence_graph→replace_work_evidence_graph→get_work_evidence_graph.mypy --strict(full repo) →Success: no issues found in 2335 source filesruff check/ruff format --checkon all changed files → cleandevtools render all --check→ exit 0devtools verify docs-coverage,hash-boundary-census→ cleandevtools verify --quick→exit_code: 0One incidental fix included:
tests/unit/core/test_timestamp_guards.py:424had a pre-existing, unrelated mypy failure (confirmed present viagit stashbefore this branch's changes) blocking the pre-push hook — already diagnosed and fixed the same way on an unmerged sibling branch and tracked/closed as polylogue-q7ol. Applied the identical scopedtype: ignore[arg-type]here since that fix isn't yet onmaster.Ref polylogue-z9gh
Ref polylogue-q7ol
🤖 Generated with Claude Code