Skip to content

fix(api): finish moving investigation queries to the unified schema - #191

Merged
bordumb merged 1 commit into
mainfrom
claude/practical-chaum-bbb68b-schema-followups
Sep 27, 2026
Merged

bordumb merged 1 commit into
mainfrom
claude/practical-chaum-bbb68b-schema-followups

Conversation

@bordumb

@bordumb bordumb commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Stacked on #183. Merge #183 first; this PR's base is #183's branch, so the diff shows only this change.

Summary

Follow-up to #183. These call sites still read columns that 013_unified_investigation.sql dropped, and they failed at runtime:

  1. Dashboard
    • get_dashboard_stats filtered on completed_at and on status values the generated status column never takes.
    • Migration 036 adds investigations.completed_at, set by a trigger the first time outcome is set. "Completed Today" counts completed_at today, and "Active" counts investigations with no outcome. The migration is re-runnable and has no BEGIN/COMMIT.
    • list_investigations now returns summaries from the alert JSONB: primary dataset, metric display name (else anomaly type) and severity. Imported replays show "unknown" instead of crashing GET /dashboard/.
    • Frontend: fetchDashboardStats requested /dashboard/stats without /api/v1, so it always failed and fell back to mock 3/7/2 numbers. It also read camelCase keys the API never sends. It now uses the generated client and maps the response, and DashboardStatsCards shows "—" and an error when loading fails.
  2. RBAC: PermissionService joined grants on investigations.data_source_id. The whole EXISTS/UNION query failed, so every can_access_investigation call raised. It now compares pg.data_source_id::text with alert->>'datasource_id' (4 places).
  3. Fix feedback export: the investigation context read investigations.issue_id. The new FixFeedbackService.investigation_context() names the latest issue from issue_investigation_runs, and leaves issue_id out when there's none.
  4. EE runbooks
    • Generating a runbook from an issue read issues.resolution/metadata and investigations.issue_id/synthesis. It now uses resolution_note, issue_labels and the latest linked investigation's outcome, and the route records that investigation in created_from_investigation_id.
    • _row_to_response now decodes JSONB text. AppDatabase has no JSONB codec, so every runbook route failed list validation before this.

Not changed: the issue route's AnomalyAlert was already fixed by #159. Sharing one issue→alert helper between CE and EE is deferred (flow fn-16.21).

Tests

Each test was written first and failed for the expected reason before the fix, all against the migrated schema via migrated_db:

  • test_investigation_completed_at.py
  • api/test_dashboard.py
  • core/test_permission_service.py
  • test_fix_feedback_export_context.py
  • EE api/test_runbook_from_issue.py
  • Frontend: lib/api/dashboard.test.ts, features/dashboard/dashboard-stats.test.tsx

Backend CI only runs on PRs into main, so this stacked PR gets none. Verified locally on this branch (#183 + this commit):

  • CE pytest: 2122 passed
  • EE pytest: 470 passed
  • CE integration: 9/9; EE integration: 8/8
  • mypy: clean
  • ruff (venv 0.14) and pinned hook ruff 0.3.0: clean
  • Frontend: typecheck, lint and 29/29 tests pass

The same change merged onto current main was also green except for #150's approvals POLICY entries, which #183 has to drop.

Merge notes

🤖 Generated with Claude Code

@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

Deployment failed for project dataing with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/bordumbs-projects?upgradeToPro=build-rate-limit

@bordumb
bordumb force-pushed the claude/practical-chaum-bbb68b branch from 5aeb687 to 1c8a7cf Compare September 27, 2026 20:18
@bordumb
bordumb changed the base branch from claude/practical-chaum-bbb68b to main September 27, 2026 21:49
Follow-up to #183. These call sites still read columns that
013_unified_investigation.sql dropped and failed at runtime:

- Dashboard: get_dashboard_stats filtered on completed_at and on statuses
  the generated status column never takes. Migration 036 adds
  investigations.completed_at, stamped by a trigger the first time outcome
  is set; active = no outcome, completed today = completed_at today.
  list_investigations now returns summaries from the alert JSONB (primary
  dataset, metric display name or anomaly type, severity), "unknown" for
  imported replays. The frontend called /dashboard/stats without /api/v1,
  read camelCase keys the API never sends and fell back to mock numbers;
  it now uses the generated client and shows "—" and an error on failure.
- RBAC: PermissionService matched datasource grants on
  investigations.data_source_id, so every access check raised. It now
  compares with alert->>'datasource_id'.
- Fix feedback export: the investigation context read investigations.issue_id;
  it now names the issue from issue_investigation_runs.
- EE runbooks: generation from an issue read issues.resolution/metadata and
  investigations.issue_id/synthesis; it now uses resolution_note,
  issue_labels and the latest linked investigation's outcome, and the route
  records that investigation. Runbook responses also decode JSONB text,
  which failed validation on every runbook route.

Integration tests run against the migrated schema via migrated_db.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
@bordumb
bordumb force-pushed the claude/practical-chaum-bbb68b-schema-followups branch from af05a59 to ec36ee8 Compare September 27, 2026 21:53
@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

Deployment failed for project dataing-docs with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/bordumbs-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

Deployment failed for project dataing-app with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/bordumbs-projects?upgradeToPro=build-rate-limit

@bordumb
bordumb merged commit fcffde5 into main Sep 27, 2026
4 of 8 checks passed
github-actions Bot pushed a commit that referenced this pull request Sep 27, 2026
## [1.24.4](v1.24.3...v1.24.4) (2026-09-27)

### Bug Fixes

* **api:** finish moving investigation queries to the unified schema ([#191](#191)) ([fcffde5](fcffde5))
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