Files
HealthLog/.planning/STATE.md
T
Marc-André BombeckandClaude Opus 4.7 2f7f487228 fix(ai): Codex OAuth flow — correct issuer + api-key exchange
The "Connect with ChatGPT" button never actually completed an OAuth
flow. The implementation hit `chatgpt.com/authorize` and
`chatgpt.com/oauth/token`, which are not OAuth endpoints — ChatGPT
silently rendered its normal web app, dropped our params on the
floor, and the user landed on a regular logged-in chat session with
nothing else happening. There was no error and no callback, which is
why the regression survived multiple releases.

The canonical issuer for ChatGPT-OAuth is `auth.openai.com`. The
official `openai/codex` CLI confirms this in
`codex-rs/login/src/auth/manager.rs` and `codex-rs/login/src/server.rs`.
The flow is also slightly more involved than a vanilla PKCE
authorisation:

  1. PKCE authorize against `auth.openai.com/oauth/authorize` with the
     `openid profile email offline_access api.connectors.read
     api.connectors.invoke` scope set, plus `id_token_add_organizations`
     and `codex_cli_simplified_flow` flags so the resulting `id_token`
     carries the ChatGPT-subscription claims.
  2. Token exchange against `auth.openai.com/oauth/token` (form-
     urlencoded body, NOT JSON) yields `{ id_token, access_token,
     refresh_token }`.
  3. **Second token exchange** with grant
     `urn:ietf:params:oauth:grant-type:token-exchange`, swapping the
     `id_token` for an OpenAI API key (`requested_token=openai-api-key`).
     This key bills against the ChatGPT subscription rather than a
     separate API plan — exactly what the v1.2/v1.3 design intended.
  4. HealthLog stores the API key in `codexAccessTokenEncrypted`
     (re-purposing the existing column to avoid a migration) and the
     OAuth refresh token in `codexRefreshTokenEncrypted`. When the
     key is about to age out we refresh + re-exchange transparently
     before the next request.

The downstream provider is now a regular `OpenAIClient` tagged with
`providerType: "codex"` so logs and analytics still distinguish
ChatGPT-subscription billing from plain BYOK. The bespoke
`codex-client.ts` (which hit the chatgpt.com/backend-api/codex/responses
endpoint with the OAuth access token) is still on disk for now so the
prisma columns and the provider tag stay stable, but is unreferenced
by the active path.

The public Codex CLI client ID `app_EMoamEEZ73f0CkXaXp7hrann` is
shipped as a default; operators who registered a private OAuth app
with OpenAI can override via `CODEX_OAUTH_CLIENT_ID`. The
`isCodexOAuthConfigured()` gate is a no-op now because the default
always has a value, so the UI surface no longer silently hides the
"Connect with ChatGPT" button.

Tests cover the new shape end-to-end: PKCE generation, the
authorize-URL parameters, the form-encoded token exchange, the
api-key exchange, the refresh path, and the encrypt/decrypt
round-trip. The provider integration test is updated to expect a
`providerType: "codex"` OpenAIClient instead of the legacy
`CodexClient`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 09:31:13 +02:00

3.4 KiB
Raw Blame History

v1.4.6 marathon — state log

Status: release tagged, awaiting Coolify deploy (2026-05-09 ~02:30)

Phase 0 — Bootstrap ✅

Committed ecca54d.

Phase 1 — CI green ⚠️

  • e2e workflow fixed in bcd1de4 (pnpm-version override) and 46e686f (mobile project → Pixel 5, locale-cookie anchor, login-form open).
  • Latest run on the v1.4.6 SHA is queued; conclusion not yet known at tag time. Per release-spec, e2e green is not a hard gate.

Phase 2 — Tier 1 fixes (T1–T9) ✅

ID Commit Note
T1 + T2 8aae7d6 tile fill + muted-foreground hierarchy
T3 a75fbc6 primary recommendation chart-token render
T4 eba898f aiBaseUrl cross-provider leak fix + test
T5 c8ee28d insights/generate 502 → 422
T6 4aeb8c9 admin status-card hrefs + tightened test
T7 31959e4 bug-report toggle now blocks /api/feedback + UI
T8 c3ca861 data-wipe preserves AuditLog + scope copy
T9 1adda80 per-card window 360+24 buckets, 7 generators + tests

Phase 3 — Chart bucketing ✅

6a64df0 — bucketTimeSeries helper + chip in chart header + 14 unit tests.

Phase 4 — Tier 2 polish ✅

P1-P5 in fda8dd8, P6+P10 in dc6db82, P7-P9 in 5c884b3, P11 in e903d9a, P12 in c7b6005, P13 in 4a159d2, P14 in dcc697c, P15+P16 in 89b5b80, P17 in 505f318, P18 in 86a4b52, P19 in 2654337, P20 in dc4507a.

Phase 5 — QA ✅

3 parallel reviewers (security / design / code-review). No CRITICAL / HIGH carried into v1.4.6 except 3 quick follow-ups applied in 6757518:

  • ai-section.tsx orange tokens → dracula tokens (also fixes contrast)
  • status-card-grid.tsx CTAs relabelled honestly ("Open integrations", "Open system status")
  • idempotency.ts text.includes("sk-") → tightened regex with false-positive regression tests for "task-id" / "risk-management"

Deferred to v1.5: notification-channel data-wipe scope (M1), Berlin TZ DST math in cross-metric joins (HIGH from code-review), exhaustive-deps + set-state-in-effect refactor in about-section.

Phase 6 — Pre-release verification ✅

pnpm typecheck clean, pnpm lint 0 errors / 12 warnings, pnpm format:check clean (after the prettier sweep in 02b9955), pnpm test 714 passed, pnpm test:integration 10 passed. pnpm build fails locally on Node 25 (Reflect.get private member bug in Turbopack); CI Docker uses Node 22 and is the canonical release build path.

Phase 7 — Release ✅

  • package.json 1.4.6 (a852612)
  • CHANGELOG.md v1.4.6 block (a852612)
  • Tag v1.4.6 pushed
  • GHCR docker-publish: in_progress
  • Coolify deploy: pending GHCR

Phase 8 — Releases ✅

GitHub releases v1.4.2, v1.4.3, v1.4.4, v1.4.5, v1.4.6 backfilled from the CHANGELOG blocks. URLs: https://github.com/MBombeck/HealthLog/releases/tag/v1.4.{2,3,4,5,6}

GHCR untagged-manifest cleanup: not run; pre-existing tagged versions (v1.x.x) are pinned, no orphan manifests visible. Defer unless Marc asks.

Phase 9 — Docs / landing 🔄

general-purpose agent dispatched to bring healthlog-docs from v1.2 to v1.4.6 and apply minimal updates to healthlog-landing. Running in background.

Phase 10 — Summary

docs/audit/v146-summary.md — last step.