Skip to content

feat(dev): log the failing procedure in a tRPC batch - #5750

Merged
iscekic merged 2 commits into
mainfrom
dev/trpc-batch-onerror
Aug 31, 2026
Merged

feat(dev): log the failing procedure in a tRPC batch#5750
iscekic merged 2 commits into
mainfrom
dev/trpc-batch-onerror

Conversation

@iscekic

@iscekic iscekic commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

The problem

A batched tRPC call answers 207 when one of its procedures fails, and folds that
failure into the response body. apps/web/src/app/api/trpc/[trpc]/route.ts passed
fetchRequestHandler only endpoint and createContext, with no onError hook,
so nothing reached the server log.

An operator saw this and nothing else:

POST /api/trpc/organizations.securityAgent.getPermissionStatus,organizations.securityAgent.getConfig,
organizations.securityAgent.getRepositories,organizations.securityAgent.listFindings?batch=1 207 in 78ms

Four procedures, one of them failing, and no way to tell which or why.

What it cost

mobile-ui-repairs-63e7 spent most of a night on one screen showing
Could not load Security Agent. It ruled out, with evidence:

  • the data — the organization finding row exists and is correct;
  • authorization — all four procedures are organizationMemberProcedure, and the log
    records Access granted, calling next four times before the batch;
  • preconditions — each of the four handlers tolerates an absent integration,
    configuration, repository, or remediation row.

Three classes eliminated, and the cause is still unknown, because the error itself is
never printed. The screen remains unproved.

The change

Ten lines. onError logs the procedure type, its path, and the error code and message.

Development only: process.env.NODE_ENV === 'development', matching the convention in
lib/constants.ts and lib/account-linking-session.ts. Production reporting is
unchanged and gains no log line.

For other orchestrators

Any section that hits an opaque 207 can cherry-pick dev/trpc-batch-onerror into its
worktree to see the failing procedure, without waiting for this to merge.

Checks

  • pnpm --filter @kilocode/web run typecheck — exit 0, no errors.
  • oxfmt applied; the file is clean.
  • The callback parameters are inferred from HTTPErrorHandlerOptions, so the signature
    cannot drift from @trpc/server.

@iscekic iscekic self-assigned this Aug 30, 2026
@kilo-code-bot

kilo-code-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • apps/web/src/app/api/trpc/[trpc]/route.ts
  • apps/web/src/app/api/trpc/[trpc]/route.test.ts
Previous Review Summaries (2 snapshots, latest commit f54446c)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit f54446c)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/app/api/trpc/[trpc]/route.ts

Previous review (commit 9677c81)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/web/src/app/api/trpc/[trpc]/route.ts

Reviewed by grok-4.6 · Input: 56.2K · Output: 7.7K · Cached: 176.1K

Review guidance: REVIEW.md from base branch main

@iscekic iscekic added the human-ready The PR is ready for human review. label Aug 30, 2026
A batched tRPC call answers 207 when one of its procedures fails, and the
failure is folded into the response body. The fetch handler defined no
onError hook, so nothing reached the server log. An operator saw `207 in
78ms` and had no way to tell which of a dozen batched procedures raised.

That cost a mobile E2E section most of a night: it could confirm the data,
the membership, and every handler precondition, and still could not name the
failing call.

Development only. Production reporting is unchanged.
@iscekic
iscekic force-pushed the dev/trpc-batch-onerror branch from 9677c81 to f54446c Compare August 31, 2026 10:45
@iscekic
iscekic enabled auto-merge (squash) August 31, 2026 14:50
@iscekic
iscekic merged commit f004fcb into main Aug 31, 2026
17 checks passed
@iscekic
iscekic deleted the dev/trpc-batch-onerror branch August 31, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants