Skip to content

feat(insights): declare readiness/cost/degraded contracts for default projections - #3198

Merged
Sinity merged 2 commits into
masterfrom
feat/insights/projection-readiness-declarations
Jul 20, 2026
Merged

Sinity merged 2 commits into
masterfrom
feat/insights/projection-readiness-declarations

Conversation

@Sinity

@Sinity Sinity commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Default analysis projections (analyze --facets, analyze --cost-outlook) now declare their cost/detail class, default interactive deadline, and prerequisites, and report an explicit ready/degraded/unavailable state instead of an opaque null or a silently slow success.

Problem

Two production smokes exposed one missing ProjectionSpec contract (polylogue-duti):

  • analyze --cost-outlook returned a syntactically valid but operationally useless null (with only an ad hoc {"reason": "no_cycle_anchor"} key) when a plan had no cycle_anchor_day — no typed remediation.
  • analyze --facets took 17.8s with no signal that a "cheap default" projection had blown any budget.

Solution

  • New polylogue.insights.projection_contracts registry: ProjectionContract declares cost class (cheap/expensive), default interactive deadline, and prerequisites with remediation for cost-outlook, facets, and facets-deferred.
  • New shared ProjectionAvailabilityPayload/ProjectionPrerequisitePayload envelope (polylogue/surfaces/payloads.py): state (ready/degraded/unavailable), reason, detail, remediation, deadline_s/elapsed_s/budget_exceeded, and per-prerequisite satisfaction.
  • Polylogue.facets() measures wall-clock execution and stamps cost_class/deadline_s/elapsed_s/availability onto FacetsResponse — this reaches the /api/facets daemon/HTTP route for free since it serializes the same response model.
  • analyze --cost-outlook CLI replaces the ad hoc {"reason": "no_cycle_anchor"} dict with the typed availability envelope on both the missing-prerequisite and success paths (JSON and plain text).
  • --explain on analyze --facets/--cost-outlook surfaces the declared contract (cost class, deadline, prerequisites) through the existing terminal-pipeline args payload.

Deliberately deferred (not silently dropped)

  • Bounded/resumable execution for expensive facet families is out of scope here — that QoS mechanism belongs to the shared query transaction (polylogue-z9gh.9). AC The gmd CLI monolith is blocking richer render surfaces #3's "opt-in, or a bounded resumable reference" is satisfied via the existing --include-deferred opt-in gate, not a new resumable-reference type.
  • No MCP tool wiring: no cost_outlook/facets MCP tool exists today (the standalone cost_outlook tool was retired in polylogue-t46.8/fix(mcp): harden six-tool cutover — session correlation, status(operation), SessionStart preamble #3095; MCP cost/usage design tracked in polylogue-hg97), so there is nothing to wire yet.
  • Other analyze modes (--count, --by, --postmortem, --portfolio) have no declared contract; --explain intentionally omits projection_contract for them rather than fabricating one.

AC matrix (polylogue-duti)

  1. Every default analysis ProjectionSpec declares prerequisites/cost class/deadline/degraded semantics — satisfied for the two projections named in the bead's evidence (cost-outlook, facets); other analyze modes deliberately out of scope (no evidence of a smoke against them).
  2. cost-outlook without a cycle anchor returns a typed unavailable result with remediation across CLI and machine payloads — satisfied.
  3. facets with default families meets its declared interactive budget; expensive families are opt-in — satisfied (opt-in already existed; this PR adds the declared deadline + measured budget_exceeded signal so a regression is now visible instead of silent). Resumable-reference alternative deliberately not built (see deferred above).
  4. explain exposes prerequisite/cost decisions; all surfaces adapt the same outcome — satisfied for CLI (--explain + JSON/plain output); HTTP gets it for free via the shared FacetsResponse model; MCP has no tool to adapt (deferred, tracked in polylogue-hg97).
  5. Seeded missing-prerequisite and slow-family mutations fail the production-route tests — satisfied: test_no_cycle_anchor_returns_json_null_outlook asserts the typed unavailable envelope; test_analyze_facets_reports_degraded_when_it_misses_its_declared_budget monkeypatches the clock through the real CLI route and asserts degraded/budget_exceeded — this is a genuine mutation-proof regression test for the exact 17.8s smoke.

Verification

  • devtools test tests/unit/insights/test_projection_contracts.py tests/unit/cli/test_cost_outlook_cli.py tests/unit/cli/test_click_app.py tests/unit/cli/test_plain_cli_snapshots.py — 121 passed. Remaining failures are pre-existing/environmental: test_json_status_snapshot (unrelated drift — this PR does not touch status.py and the diff to that test file is purely additive elsewhere) and 8 sqlite3.OperationalError: database is locked errors in postmortem/portfolio tests caused by a concurrent sibling worktree's devtools verify --seed-testmon contending on the shared /dev/shm//realm/tmp/polylogue-pytest seeded-db cache.
  • devtools test tests/unit/daemon/test_web_reader.py -k facets — 19 passed (route/facade parity test updated to also strip the now-volatile elapsed_s field, same treatment as the existing generated_at exclusion).
  • mypy --strict on touched files — clean.
  • devtools render all --check — sync OK (new payload models picked up by generated cli-output-schemas/openapi with no extra registration needed; new module triggered a docs/plans/topology-target.yaml regeneration).
  • devtools verify --quick — exit 0 (also re-ran clean via the pre-push hook).

Ref polylogue-duti

Summary by CodeRabbit

  • New Features

    • Added readiness and availability details to facets and cost-outlook analysis results.
    • Added cost classifications, timing, budget status, prerequisites, remediation guidance, and degraded-state reporting.
    • Added projection contract details to analyze --explain.
    • Added terminal readiness indicators and clearer messages for unavailable or over-budget results.
  • Documentation

    • Updated topology and status documentation to reflect current project mappings and totals.
  • Tests

    • Added coverage for projection contracts, availability states, budget handling, and CLI output.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: de8d69c3-fba6-4717-86a3-a7afe523fbc4

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6a85b and 465b407.

📒 Files selected for processing (12)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/api/archive.py
  • polylogue/cli/query_verbs.py
  • polylogue/insights/projection_contracts.py
  • polylogue/surfaces/payloads.py
  • tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr
  • tests/unit/cli/test_click_app.py
  • tests/unit/cli/test_cost_outlook_cli.py
  • tests/unit/cli/test_plain_cli_snapshots.py
  • tests/unit/daemon/test_web_reader.py
  • tests/unit/insights/test_projection_contracts.py
📝 Walkthrough

Walkthrough

Adds centralized projection readiness contracts and typed availability payloads for facets and cost-outlook analysis. Archive and CLI paths now report timing, cost, budget, prerequisites, and degraded or unavailable states, with updated tests and generated topology metadata.

Changes

Projection readiness

Layer / File(s) Summary
Projection contracts and payloads
polylogue/insights/projection_contracts.py, polylogue/surfaces/payloads.py
Defines projection cost classes, prerequisites, contracts, availability helpers, and shared response payloads.
Runtime availability and CLI output
polylogue/api/archive.py, polylogue/cli/query_verbs.py
Measures projection execution, attaches availability metadata, updates cost-outlook JSON and terminal output, and exposes contracts through --explain.
CLI validation and generated topology
tests/unit/insights/*, tests/unit/cli/*, tests/unit/daemon/*, docs/plans/topology-target.yaml, docs/topology-status.md
Validates readiness states, prerequisites, budget degradation, snapshots, route payloads, and generated topology counts and locations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Archive
  participant Contracts
  participant Response
  CLI->>Archive: request facets or cost-outlook analysis
  Archive->>Archive: measure projection duration
  Archive->>Contracts: compute availability state
  Contracts-->>Archive: return readiness and budget metadata
  Archive->>Response: serialize projection result and availability
  Response-->>CLI: render JSON or terminal output
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR’s main change: adding readiness/cost/degraded contracts for default projections.
Description check ✅ Passed The description covers Summary, Problem, Solution, Verification, and follow-up details, but it omits the template’s Changelog section.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/insights/projection-readiness-declarations

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.

@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: 0e6a85b10f

ℹ️ 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".

Comment thread polylogue/cli/query_verbs.py Resolved
Comment thread polylogue/cli/query_verbs.py Resolved

@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/cli/query_verbs.py`:
- Around line 154-165: The availability detail in the response-rendering block
currently sends Rich markup through click.echo, causing tags to display
literally. Update the avail.detail output in the query result display flow to
use the existing Rich console or click styling mechanism so the yellow
formatting renders correctly, while preserving the conditional output and
message text.
🪄 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: 5936011d-91e2-4d1a-b146-d2908f5d5789

📥 Commits

Reviewing files that changed from the base of the PR and between d11af85 and 0e6a85b.

📒 Files selected for processing (12)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/api/archive.py
  • polylogue/cli/query_verbs.py
  • polylogue/insights/projection_contracts.py
  • polylogue/surfaces/payloads.py
  • tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr
  • tests/unit/cli/test_click_app.py
  • tests/unit/cli/test_cost_outlook_cli.py
  • tests/unit/cli/test_plain_cli_snapshots.py
  • tests/unit/daemon/test_web_reader.py
  • tests/unit/insights/test_projection_contracts.py

Comment thread polylogue/cli/query_verbs.py Resolved
Sinity added a commit that referenced this pull request Jul 20, 2026
…s in plain output

CodeRabbit review fixes on #3198: (1) successful --cost-outlook JSON no
longer nests the documented CycleOutlook envelope under 'outlook' —
availability is additive alongside the existing top-level fields; (2) a
deadline-exceeding plain run now prints the degraded readiness line
before rendering the outlook instead of silently reporting success;
(3) availability detail renders via click.secho instead of literal Rich
markup.
@Sinity

Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

All three CodeRabbit findings addressed in d7b5487: (1) successful --cost-outlook JSON keeps the documented CycleOutlook envelope top-level with availability additive; (2) plain output now prints the degraded readiness line (with elapsed/deadline) before rendering the outlook, covered by a new test; (3) availability detail renders via click.secho instead of literal Rich markup.

Sinity added a commit that referenced this pull request Jul 20, 2026
Sinity and others added 2 commits July 20, 2026 12:09
… projections

Problem: two production smokes exposed one missing contract on default
analysis projections. `analyze --cost-outlook` returned a syntactically
valid but operationally useless `null` with only an ad hoc `reason:
no_cycle_anchor` key and no remediation when a plan had no
`cycle_anchor_day`. `analyze --facets` took 17.8s with no signal that a
"cheap default" projection had blown any budget.

What changed:
- New `polylogue.insights.projection_contracts` registry declares, per
  default projection, its cost/detail class (cheap/expensive), default
  interactive deadline, and prerequisites with remediation text
  (`cost-outlook`, `facets`, `facets-deferred`).
- New shared `ProjectionAvailabilityPayload`/`ProjectionPrerequisitePayload`
  envelope (`polylogue/surfaces/payloads.py`) reports state
  (ready/degraded/unavailable), reason, remediation, and measured
  cost (deadline_s/elapsed_s/budget_exceeded) alongside a projection's data.
- `Polylogue.facets()` now measures wall-clock execution and reports the
  declared cost class/deadline/elapsed/budget_exceeded on `FacetsResponse`
  (`cost_class`, `deadline_s`, `elapsed_s`, `availability`); this
  automatically reaches the `/api/facets` daemon/HTTP route since it
  serializes the same response model.
- `analyze --cost-outlook` (CLI) replaces the ad hoc `{"reason":
  "no_cycle_anchor"}` dict with the typed `availability` envelope on both
  the missing-prerequisite and success paths, in JSON and plain-text output.
- `--explain` on `analyze --facets`/`--cost-outlook` surfaces the declared
  contract (cost class, deadline, prerequisites) via the existing terminal
  pipeline `args` payload.

Deferred (documented, not silently dropped):
- Bounded/resumable execution for expensive facet families is explicitly
  out of scope here — that QoS mechanism belongs to the shared query
  transaction (polylogue-z9gh.9). Expensive families satisfy AC #3's
  "opt-in, or a bounded resumable reference" via the existing
  `--include-deferred` opt-in gate, not a new resumable-reference type.
- MCP: no `cost_outlook`/`facets` MCP tool exists today (the standalone
  `cost_outlook` tool was retired in polylogue-t46.8/#3095, tracked for a
  design decision in polylogue-hg97), so there is nothing to wire there yet.
- Other `analyze` modes (count/by/postmortem/portfolio) have no declared
  contract; `--explain` intentionally omits `projection_contract` for them
  rather than fabricating one.

Verification:
- `devtools test tests/unit/insights/test_projection_contracts.py
  tests/unit/cli/test_cost_outlook_cli.py tests/unit/cli/test_click_app.py
  tests/unit/cli/test_plain_cli_snapshots.py` — 121 passed (the only
  failures are `test_json_status_snapshot`, pre-existing drift unrelated to
  this diff, and 8 `sqlite3.OperationalError: database is locked` errors in
  postmortem/portfolio tests caused by a concurrent sibling worktree's
  `devtools verify --seed-testmon` contending on the shared
  `/dev/shm`/`/realm/tmp/polylogue-pytest` seeded-db cache).
- `devtools test tests/unit/daemon/test_web_reader.py -k facets` — 19
  passed (route/facade parity test updated to also strip the now-volatile
  `elapsed_s` wall-clock field, same treatment as the existing
  `generated_at` exclusion).
- `mypy --strict` on touched files — clean.
- `devtools render all --check` — sync OK (new payload models picked up by
  generated `cli-output-schemas`/`openapi` without extra registration; new
  module regenerated `docs/plans/topology-target.yaml`).
- `devtools verify --quick` — exit 0.

Ref polylogue-duti

Co-Authored-By: Claude <[email protected]>
…s in plain output

CodeRabbit review fixes on #3198: (1) successful --cost-outlook JSON no
longer nests the documented CycleOutlook envelope under 'outlook' —
availability is additive alongside the existing top-level fields; (2) a
deadline-exceeding plain run now prints the degraded readiness line
before rendering the outlook instead of silently reporting success;
(3) availability detail renders via click.secho instead of literal Rich
markup.
@Sinity
Sinity force-pushed the feat/insights/projection-readiness-declarations branch from d7b5487 to 465b407 Compare July 20, 2026 10:11
@Sinity
Sinity merged commit b460028 into master Jul 20, 2026
3 checks passed
@Sinity
Sinity deleted the feat/insights/projection-readiness-declarations branch July 20, 2026 10:12
@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.

  • 60.F049 / P1: fixed-already at the checked revision: polylogue/cli/query_verbs.py:2298 expands the successful CycleOutlook model into the top-level JSON object and adds availability beside it. The successful response no longer nests plan_name, window, or projection_method under outlook.

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

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

  • 61.F124 / P2: fixed-already at the checked revision: polylogue/cli/query_verbs.py:2306 checks degraded cost-outlook availability on the terminal route and prints its state, detail, and elapsed/deadline budget at line 2313 before rendering the outlook.

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