← Back to Pull requests

feat(core): headless core contract — RunResult / RunReporter / CancelToken / error taxonomy (#363) #364

Closed
unknown closed this pull request without merging on Nov 22, 2026 14:55 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 13:24 UTC
Author

First step of #363: the typed headless core contract, so Fluvo's capabilities can be driven by consumers other than the terminal (a server process, an automation layer, a GUI) without re-implementing orchestration or scraping the CLI's human-facing output.

This PR adds the vocabulary only — no command changes behaviour. Migrating assess/compare to return RunResult and report via RunReporter, and the later import-engine retrofit, are follow-on work on the same issue.

What's here — fluvo.lib.core

  • RunResult + ReconStats — one typed outcome for every capability, carrying the reconciliation counters the e2e suite already asserts (created + failed + unaccounted == total). The identity is a write-path property: read-only capabilities leave the counters at their reconciled default and report findings through their own result types. RunError captures a typed, serialisable error record so a result can cross a process/protocol boundary.

  • RunReporter protocol + NullReporter — progress reporting decoupled from rich. The core calls on_phase / on_progress / on_message; adapters (a rich reporter for the CLI, a notification reporter for a server, a queue/stream reporter for a UI) live with their consumer, not in the core. core imports nothing presentation-specific.

  • CancelToken — an externally settable, thread-safe stop signal (threading.Event-backed), replacing "the only way to stop is Ctrl+C on the main thread". Any thread may cancel(); a worker checks cancelled / raise_if_cancelled() between units of work.

  • FluvoError taxonomy — InputError, ConnectError (named so it never shadows the built-in ConnectionError), SourceReadError, NothingToDoError, OperationCancelledError — so no consumer has to read a None return as "fatal". exit_code carries the CLI adapter's default mapping. CompareError now subclasses FluvoError (still a RuntimeError, so existing except CompareError handlers are unaffected).
  • Design note surfaced while writing it

    The reconciliation identity is a write-path invariant. An early draft let a read-only run put "rows looked at" in total, which breaks the identity (total=500 with empty buckets ≠ reconciled). Corrected: read-only runs leave ReconStats at zero; any row counted-but-not-written belongs in an explicit bucket. There's a regression test for exactly this.

    Checks


  • tests/test_core.py — 23 tests (identity, status, cancel across threads, taxonomy, protocol conformance). Full suite green.

  • ruff, pydoclint (baseline-aware), mypy all clean. Synthetic values only; no datasets.
  • Diff: 330 lines (+247 / -83) across 4 files Reviewer: bosd Review duration: 90m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.65) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 330 lines diff across 4 files
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    57%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.347
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    1 comments
    "Review active on #364"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.3% (HIGH) · Higher = larger blast radius
    65.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.0% · Lower = rushed or shallow review
    58.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.4% · Safe to merge
    27.4%
    Repository