feat: PHIE Phase 1 — Personal Health Intelligence Engine (backend) - #59
Merged
Conversation
Scaffolded by Sonnet subagent via ADE v4 design check phase. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Full implementation of the Personal Health Intelligence Engine services on top of the Phase 3 stubs: Pearson correlation + p-value stats, correlation discovery engine, linear trajectory projector with confidence bands, AI chat tool integration (query_correlations, query_projections), and intelligence query layer. Phase 5 quality gate passed: build clean, 332 backend tests green.
Addresses 3 HIGH and 9 MEDIUM findings from parallel code review: HIGH - correlation upsert no longer overwrites first_detected_at on re-run - /api/correlations top query param capped at 100 (prevents DoS) - remove stale TODO comments from fully-implemented route handlers MEDIUM — logic - linearRegression returns r2=0 (not 1) on zero-variance y series - confidence bands use proper OLS prediction interval formula (propagates meanX and ssXX from linearRegression) - trajectory projector returns early on empty metric filter instead of firing useless DB queries against missing defaults - listCorrelations now honors metric and minConfidence filters MEDIUM — conventions - strip apiKeyMiddleware from GET routes (matches sibling convention: GET open, POST protected) - remove @deprecated tags on newly-implemented filter fields - auto-format correlation-engine.ts per Prettier MEDIUM — security - length-bound :metric path param and LLM-supplied metric tool args - parseDate throws generic 'Invalid date' to avoid leaking raw (potentially prompt-injected) input via error logs
Closes Phase 7 verification gaps against AC3, AC4, AC5. - Wire runCorrelationAnalysis + runTrajectoryProjections into generateWeeklyReport as a non-blocking post-save step. Failures are logged under [intelligence] prefix and do not affect the returned report. - Also wire into runReportInBackground (async path) with the same non-blocking try/catch pattern. - Add correlation-engine.test.ts with coverage for: 14+ days produces >=1 strong correlation, <MIN_DATA_POINTS produces none, zero-data path is graceful. - Add trajectory-projector.test.ts with coverage for: 30-day projection with widening confidence bands, min-data-points skip, empty-metric early return. - reports.test.ts: add mocks for intelligence modules and a new test asserting report generation returns 200 when the correlation analysis rejects.
Add Intelligence section (UC-INT-01..05) to product-capabilities.md covering correlation discovery, trajectory projection, REST endpoints, and AI chat tools. Documents Phase 1 limitations (backend-only, no scheduled run yet — follow-up ticket). Update architecture.md: - Add correlations and projections tables to the Data Model inventory - Add GET /api/correlations and GET /api/projections/:metric endpoints - Note non-blocking intelligence pipeline in the report generation flow
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backend-only correlation discovery + trajectory projection engine for personal health data. Introduces a new intelligence layer that runs automatically after each weekly report, surfacing patterns the user didn't explicitly ask for, and makes them queryable via REST + AI chat tools.
first_detected_atacross re-runs).σ·√(1 + 1/n + (x*−x̄)²/SSxx)) — confidence bands widen with distance from the observed mean.[intelligence]and do NOT affect the returned report.GET /api/correlations(filters: category, confidence, status, metric, minConfidence, top) andGET /api/projections/:metric.query_correlations,predict_trajectory,simulate_change. Length-bounded inputs; `parseDate` sanitized to avoid leaking raw prompt-injected values to logs.Commits
21 files changed, +2092 / −2 lines.
Test coverage
Acceptance criteria — verified
Phase 1 limitations (documented)
Migration required
New migration: `010_intelligence.sql` — creates 2 tables, 5 indexes. Must run before deploying this branch.
Test plan
🤖 Generated with Claude Code