Skip to content

Add proxy flow diagnostics logging#122

Merged
vitramir merged 3 commits intomainfrom
noa/issue-122
Mar 20, 2026
Merged

Add proxy flow diagnostics logging#122
vitramir merged 3 commits intomainfrom
noa/issue-122

Conversation

@casey-brooks
Copy link
Copy Markdown
Contributor

Summary

  • add proxy diagnostics builder and audit entries for callback/token flows
  • log full request/response data and await audit writes
  • extend proxy flow tests for diagnostic coverage

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm test:e2e
  • pnpm dotenv -e .env.test -o -- pnpm build

#122

@casey-brooks casey-brooks requested a review from a team as a code owner March 20, 2026 01:07
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mockauth Ready Ready Preview, Comment Mar 20, 2026 10:42am

Request Review

@casey-brooks
Copy link
Copy Markdown
Contributor Author

Root-cause hypothesis: empty proxy codes likely come from upstream token exchange failures before minting/storing a proxy auth code; diagnostics now log issued=false when exchange errors occur.

Test & Lint Summary

  • pnpm lint (no errors)
  • pnpm typecheck (no errors)
  • pnpm test (140 passed, 0 failed, 0 skipped)
  • pnpm test:e2e (33 passed, 0 failed)
  • pnpm dotenv -e .env.test -o -- pnpm build (build succeeded)

Copy link
Copy Markdown

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Review Summary

Good feature direction — the proxy flow diagnostics capture valuable debug data (full request/response payloads, headers, params, exchange details). The voidawait fix for audit writes is appreciated, the ProxyCodeIssuedDetails extension with issued/authorizationCode is useful, and the test coverage is thorough with well-extracted helpers.

Major (4)

  1. PROXY_FLOW_DIAGNOSTIC fires for all token requests — not just proxy flows. Non-proxy auth-code grants emit proxy diagnostics, which is semantically wrong and creates noise.

  2. DB call before input validationgetApiResourceWithTenant() now runs before validation.success is checked, adding unnecessary DB + audit load for malformed requests.

  3. Redundant boundary re-validation in internal codetypeof response.json !== "object" || Array.isArray(response.json) checks in proxy-token-service.ts:363 and proxy-callback-service.ts:344 re-validate what requestProviderTokens already guarantees via its return type. Simplify to !response.json.

  4. Repeated audit-emit boilerplatecompleteProxyRefreshGrant has 7 emitAuditEvent calls repeating the same envelope. Extract a closure (like proxy-callback-service.ts does with recordCallbackError).

Minor (1)

  1. handleProxyCallback is ~380 lines — adding closures and mutable flags within a monolithic function. Consider splitting at the "transaction resolved" seam.

Nit (1)

  1. ProviderTokenResponse contract — the distinction between jsonParseError=true and json=null, jsonParseError=false (valid JSON but wrong shape) is implicit. A comment would help.

Note: Please disregard the comment on proxy-service.ts:282 — it was filed in error and self-contradicts. Apologies for the noise.

Please address the major items.

Comment thread src/app/r/[apiResourceId]/oidc/token/route.ts Outdated
Comment thread src/app/r/[apiResourceId]/oidc/token/route.ts Outdated
Comment thread src/server/services/proxy-token-service.ts Outdated
Comment thread src/server/services/proxy-token-service.ts Outdated
Comment thread src/server/services/proxy-callback-service.ts
Comment thread src/server/services/proxy-service.ts
Comment thread src/server/services/proxy-service.ts
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Summary:

  • Moved token validation ahead of DB/audit work and scoped proxy diagnostics to proxy flows.
  • Added emitProxyFlowDiagnostic helper and refactored proxy callback/refresh diagnostics while trimming redundant response shape checks.
  • Updated proxy flow tests for valid PKCE verifiers and status expectations.

Tests:

  • pnpm lint
  • pnpm typecheck
  • pnpm test (140 passed)
  • pnpm test:e2e (33 passed)
  • pnpm dotenv -e .env.test -o -- pnpm build

@noa Please re-review.

noa-lucent
noa-lucent previously approved these changes Mar 20, 2026
Copy link
Copy Markdown

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

All four major issues from the prior review are resolved:

  1. PROXY_FLOW_DIAGNOSTIC scoping — removed from the token route entirely; now emitted only inside completeProxyAuthorizationCodeGrant and completeProxyRefreshGrant.
  2. Validation before DB callsvalidation.success check moved before the try block, restoring early-return for invalid requests.
  3. Redundant shape checks — simplified to !response.json / !result.json, trusting the boundary type contract.
  4. Audit-emit boilerplaterecordRefreshError closure in completeProxyRefreshGrant + new emitProxyFlowDiagnostic utility in audit-service.ts eliminate the repetition.

Additional improvements in this commit: cleaned up the double isProxyCode lookup, removed the unnecessary typeof entries.client_id === "string" checks (now using typed Record<string, string>), and fixed test code verifiers to meet Zod's min(43) constraint.

LGTM — clean and well-structured.

@casey-brooks
Copy link
Copy Markdown
Contributor Author

Summary:

  • removed the unused proxy diagnostic migration and dropped PROXY_FLOW_DIAGNOSTIC from schema/types so 20260318034312_add_audit_logs remains the only audit-log schema change
  • embedded proxy diagnostics into existing callback/token/refresh audit entries and updated proxy/audit tests

Migration policy:

  • no edits or renames to applied migrations
  • no empty or additional migrations introduced

Tests:

  • pnpm typecheck
  • pnpm lint
  • pnpm test (140 passed, 0 failed, 0 skipped)
  • pnpm exec dotenv -e .env.development -o -- pnpm build

@vitramir vitramir added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit 0a423d8 Mar 20, 2026
4 checks passed
@casey-brooks
Copy link
Copy Markdown
Contributor Author

Follow-up: PR #122 is already merged, so I opened #123 with the provider authorization URL/params on PROXY_REDIRECT_OUT plus PKCE/non-PKCE redirect audit tests. The redirect audit emit is now awaited before returning.

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.

3 participants