/improve_plan @thoughts/shared/plans/2026-04-09-github-org-binding.md
- User
/improve_plan @thoughts/shared/plans/2026-04-09-github-org-binding.md
- User
improve_plan /improve_plan @thoughts/shared/plans/2026-04-09-github-org-binding.md
Assistant· claude-opus-4-6
Now let me spawn parallel research agents to understand the codebase areas this plan touches.
Assistant· claude-opus-4-6
Now I have comprehensive research from all three agents. Let me load
AskUserQuestionfor the scope questions.Assistant· claude-opus-4-6
Assistant· claude-opus-4-6
Good. Now before I edit the plan, let me propose a spike for the highest-leverage uncertainty.
The entire binding enforcement depends on fetching GitHub account details via
GET /app/installations/{id}using a GitHub App JWT. The plan's approach (getActiveToken) is broken (Critical #1 and #3). The fix requirescreateGitHubAppJWTto be accessible from the callback context — but we need to verify:- Where
createGitHubAppJWTlives and whether it's exportable - Whether the provider
configobject in the callback has the fields it needs (appId,privateKey) - Whether the API call actually returns
account.idas expected
- Where
Assistant· claude-opus-4-6
What would you like to clarify about the spike?
- User
you can spike it, but how are you gonna test it without valid keys? are you thinking of using the lightfast-db skill
Assistant· claude-opus-4-6
Good point — I can't actually hit GitHub's API or the database without real credentials. A spike in an isolated worktree would only prove the code compiles and the imports resolve, not that the JWT → API call →
account.idflow works end-to-end.What I can verify structurally:
- Where
createGitHubAppJWTlives, its signature, and whether it's exportable - What shape the provider
configobject has in the callback context (does it carryappId/privateKey?) - Whether the
githubAppInstallationSchemaalready handlesaccount.idafter the plan's change
That's enough to confirm the fix is sound without needing live keys. Let me do that as a quick codebase trace instead of a full spike.
- Where
Assistant· claude-opus-4-6
The trace confirms the fix is clean and safe:
createGitHubAppJWTis atgithub/index.ts:34-40, module-private, just needsexportadded- The callback's
configalready hasappId+privateKey— exactly what it needs - There's even an existing pattern at
github/index.ts:278-298(healthCheck.check) that does the exact sameGET /app/installations/{id}call with a JWT
No spike needed — the fix is mechanical. Let me now edit the plan with all findings incorporated.
Assistant· claude-opus-4-6
Now I have the full plan read. Let me apply all the fixes. I'll make the edits in batches.
Batch 1: Phase 1 fixes (relations, FK note)
Assistant· claude-opus-4-6
Batch 2: Phase 2 critical fixes (JWT auth, error handling, race condition)
Assistant· claude-opus-4-6
Now fix the binding INSERT race condition and replace the dead error page with BroadcastChannel error signaling.
Assistant· claude-opus-4-6
Now replace the dead error page with BroadcastChannel error signaling in the existing connected page.
Assistant· claude-opus-4-6
Batch 3: Phase 3 fixes (router type, setup gate error handling)
Assistant· claude-opus-4-6
Batch 4: Remove Phase 4 entirely and update Phase 3's implementation note + "What We're NOT Doing"
Assistant· claude-opus-4-6
Now update "What We're NOT Doing" to include Clerk metadata, and update Testing/Performance sections to remove Phase 4 references.
Assistant· claude-opus-4-6
Batch 5: Update manual testing steps for error UX and add the Improvement Log.
Assistant· claude-opus-4-6
Now add the Improvement Log at the end of the file.
Assistant· claude-opus-4-6
Plan updated. Here's a summary of what changed:
Critical fixes (3)
getActiveToken→createGitHubAppJWT— the original would 401 at runtime (wrong auth type) and crash before that (missing argument to a method that isn't even exportable)- Dead error page replaced with BroadcastChannel error signaling — users now see inline error messages when binding is rejected
- Added
onConflictDoNothing+.returning()check — prevents unhandled 500s from concurrent callback races
Convention fixes (2)
- Added
satisfies TRPCRouterRecordto match existing router pattern - Removed phantom
lifecycleLogsrelation addition
Scope changes (2)
- Cut Phase 4 (Clerk publicMetadata) — deferred to follow-up
- Documented that
onDelete: "set null"FK is cosmetic
The plan is now 3 phases instead of 4, with all code paths verified against the actual codebase.