refactor(api): migrate brand identities to Effect programs - #1042
Conversation
Extract all six brand-identities handlers into Effect programs with typed domain errors, runBrandIdentityProgram bridge, and thin Hono routes. Preserves HTTP semantics including pre-rate-limit validation, workflow rollback, default-identity switching, and QStash cleanup. Co-authored-by: Cursor Agent
|
The latest updates on your projects. Learn more about Vercel for GitHub. 5 Skipped Deployments
|
There was a problem hiding this comment.
1 issue found across 5 files
Confidence score: 3/5
- In
apps/api/src/routes/brand-identities.ts, Redis job creation or update failures can now surface as an unhandled 500 while leaving the newly inserted brand identity behind, creating an inconsistent persisted state. Restore the documented 503 response and clean up the inserted identity on failure.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/routes/brand-identities.ts">
<violation number="1" location="apps/api/src/routes/brand-identities.ts:344">
P2: When Redis job creation or job update fails, this delegated path now produces an unhandled 500 and leaves the newly inserted brand identity behind instead of returning the documented 503 and cleaning it up. Keep job lifecycle failures in the queue-failure recovery path so the identity is removed and the caller receives `Failed to queue brand identity analysis`.</violation>
</file>
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Re-trigger cubic
| throw new Error("Failed to create brand identity"); | ||
| } | ||
| const result = await runBrandIdentityProgram( | ||
| createBrandIdentity({ |
There was a problem hiding this comment.
P2: When Redis job creation or job update fails, this delegated path now produces an unhandled 500 and leaves the newly inserted brand identity behind instead of returning the documented 503 and cleaning it up. Keep job lifecycle failures in the queue-failure recovery path so the identity is removed and the caller receives Failed to queue brand identity analysis.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/routes/brand-identities.ts, line 344:
<comment>When Redis job creation or job update fails, this delegated path now produces an unhandled 500 and leaves the newly inserted brand identity behind instead of returning the documented 503 and cleaning it up. Keep job lifecycle failures in the queue-failure recovery path so the identity is removed and the caller receives `Failed to queue brand identity analysis`.</comment>
<file context>
@@ -352,115 +340,25 @@ brandIdentitiesRoutes.openapi(createBrandIdentityRoute, async (c) => {
- throw new Error("Failed to create brand identity");
- }
+ const result = await runBrandIdentityProgram(
+ createBrandIdentity({
+ db: c.get("db"),
+ organizationId: orgId,
</file context>
Route Redis job create/update failures through BrandAnalysisQueueFailedError with the same rollback path as workflow failures (delete brand row, mark job failed when applicable, return 503). Add BrandIdentityInUseError when projects or geo content briefs reference the identity; pre-migration delete surfaced raw FK errors for the same case. Co-authored-by: Cursor Agent
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Do not delete brand identity after workflow acceptance; post-workflow Redis update failures return 503 only. Clean up partial Redis job keys before workflow, and route delete failures through respondToBrandIdentityFailure. Co-authored-by: Cursor Agent
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Include installation account type/login in the GitHub integration query used by publishChangelogToGitHub so merged main typechecks in CI. Co-authored-by: Cursor Agent
Only roll back the brand identity when the dashboard explicitly rejects workflow start (4xx or pre-flight configuration/auth failures). Transport, timeout, and other ambiguous trigger errors mark the job failed and return 503 without deleting the row. Co-authored-by: Cursor Agent
Use _tag-based type guards for workflow trigger rejection classification instead of instanceof, matching schedules.ts patterns. Refactor failBrandAnalysisQueue to Effect.fnUntraced for consistency with integrations delete cleanup helper.
b807ef4 to
14c3863
Compare
Description
Give a short summary of what this PR does and why it's needed.
Screenshot/Recording (if applicable)
Attach a screenshot or recording of the change. This is optional, but can help reviewers understand the change. You can use Cap to record a video.
Checklist
Summary by cubic
Refactors brand identity API handlers into Effect programs with typed errors. Delete now returns 409 when the identity is referenced by projects or content briefs, instead of surfacing a raw foreign-key error.
Refactors
apps/api/src/programs/brand-identities.ts; database errors die and hit the central error handler.respondToBrandIdentityFailuremapping for consistent error responses.maintypechecks.Written for commit 14c3863. Summary will update on new commits.