/improve_plan @thoughts/shared/plans/2026-04-06-internal-trpc-caller-setup.md
Private research annotation
Sign in to add a private research label or note.
- User
/improve_plan @thoughts/shared/plans/2026-04-06-internal-trpc-caller-setup.md
- User
improve_plan /improve_plan @thoughts/shared/plans/2026-04-06-internal-trpc-caller-setup.md
Assistant· claude-opus-4-6
I've read the plan. Let me spawn parallel research agents to understand the codebase before reviewing.
Assistant· claude-opus-4-6
Assistant· claude-opus-4-6
Got it — keep route handler caller, collapse phases, keep type export.
Now for the spike. The highest-leverage uncertainty I see:
Assistant· claude-opus-4-6
The spike found a critical gap: the plan's approach fails to typecheck without an additional change.
initTRPC.context<typeof createPlatformTRPCContext>()infers a narrow type from the function's actual return paths ("service" | "unauthenticated"only), so TypeScript rejects"internal"as impossible. The fix is introducing an explicitPlatformContexttype.Good news: the spike confirmed empty headers are completely safe — the observability middleware never reads from
ctx.headers.Now let me edit the plan with all findings incorporated.
Assistant· claude-opus-4-6
Now update Phase 2 (was Phase 3) — renumber and remove the "(Optional)" from the route handler caller since the user wants to keep it.
Assistant· claude-opus-4-6
Now add the Improvement Log at the bottom of the file.
Assistant· claude-opus-4-6
Plan updated. Here's the summary of what changed:
Critical fix (from spike): Added a new Step 1 to Phase 1 — define an explicit
PlatformContexttype and switchinitTRPC.context<>()from inferred to explicit. Without this, the plan's approach fails to typecheck becausetypeof createPlatformTRPCContextonly infers"service" | "unauthenticated"return types, rejecting"internal"as impossible.Structural changes:
- Collapsed Phase 1 + Phase 2 into a single Phase 1 (7 steps, one verification pass)
- Renumbered Phase 3 → Phase 2
- Removed "(Optional)" from route handler caller
Quality improvements:
pingnow returnssourcefromctx.authfor direct verification of auth propagation- Added documentation comments flagging the context bypass coupling between
createInternalCallerandcreatePlatformTRPCContext
Disproved concern: Empty
new Headers()is safe — the observability middleware never reads fromctx.headers.- User
question, is this system truly secure? can external hacker hack it?
Assistant· claude-opus-4-6
Good question. Let me assess the actual attack surface of this design.
The internal router is not HTTP-reachable.
internalRouteris never passed tofetchRequestHandleror anyserve()call. The only way to invoke it is throughcreateInternalCaller(), which is a direct in-process JavaScript function call — there's no network endpoint an attacker can hit.The HTTP surface is unchanged:
/api/trpc/[trpc]→ routes to only (JWT-authenticated via )
- User
all good
Assistant· claude-opus-4-6
Got it — plan is finalized. Ready to implement whenever you are.