Skip to content

feat(api,ui): forecast explainability & driver attribution slice (#224)#231

Merged
w7-mgfcode merged 2 commits into
devfrom
feat/explainability-driver-attribution
May 19, 2026
Merged

feat(api,ui): forecast explainability & driver attribution slice (#224)#231
w7-mgfcode merged 2 commits into
devfrom
feat/explainability-driver-attribution

Conversation

@w7-mgfcode
Copy link
Copy Markdown
Owner

Summary

Adds the explainability vertical slice — rule-based driver attribution for baseline forecasts — closing #224.

  • New app/features/explainability/ slice: models, schemas, service, routes, explainers, reason_codes + full test suite (unit + integration).
  • Three endpoints under /explain:
    • POST /explain/forecast — explain an ad-hoc baseline h=1 forecast.
    • GET /explain/runs/{run_id} — explain a registry model_run.
    • GET /explain/jobs/{job_id} — explain a completed predict job.
  • Baseline models only (naive / seasonal_naive / moving_average); lightgbm / regression → clean RFC 7807 400. Time-safe (reads only <= as_of_date).
  • New forecast_explanation table (migration f84258c4cb44) persists each explanation as an audit trail.
  • Frontend: ExplanationPanel component + use-explanations hook, wired into the run-detail and forecast-visualization pages.

Bundled fix — fix(ui) (#230)

The slice's dogfood surfaced a pre-existing, repo-wide bug: api.ts only treated application/json as JSON, so RFC 7807 application/problem+json error bodies were never parsed and the raw JSON string leaked into every ErrorDisplay. Fixed here (one line + regression test) because the ExplanationPanel error UX depends on it. Root cause tracked in #230.

Validation

  • ruff / mypy --strict / pyright --strict — clean.
  • Backend: 1288 unit + 8 explainability integration tests pass.
  • Frontend: 104 vitest tests pass; tsc --noEmit + lint clean.
  • Real-browser dogfood (PRP Level 5): verified the Forecast Explanation card on /explorer/runs/{id} (full panel), /visualize/forecast (full panel for an explainable predict job), and the graceful neutral message for an unexplainable job.

Notes

  • uv.lock has an unrelated local version-string drift (0.2.80.2.14) left out of this PR.

Closes #224.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @w7-mgfcode, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 01d4eb32-8dba-4610-8e40-e61aa6ef2f38

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/explainability-driver-attribution

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 and usage tips.

@w7-mgfcode w7-mgfcode merged commit af1a5be into dev May 19, 2026
10 checks passed
@w7-mgfcode w7-mgfcode deleted the feat/explainability-driver-attribution branch May 19, 2026 10:35
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