Skip to content

Consolidate the three-way reviews wire-type duplication - #971

Merged
selfcontained merged 1 commit into
mainfrom
debt/reviews-wire-types
Aug 17, 2026
Merged

Consolidate the three-way reviews wire-type duplication#971
selfcontained merged 1 commit into
mainfrom
debt/reviews-wire-types

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Tech-debt run: sub-item (b) of the server↔web wire-type cluster — the largest remaining pair from the 2026-08-14 duplicate-block audit (12 duplicated 7-line windows), and the only three-way one.

What was duplicated

apps/server/src/agents/reviews.ts declares the reviews record tree. It was hand-copied twice:

  1. apps/web/src/hooks/use-agent-reviews.ts restated all four types field-for-field — ReviewThreadMessage (7 fields), ReviewFeedbackItem (14 + messages), Review (10), ReviewListItem (13).
  2. apps/server/src/shared/mcp/server.ts (the listReviewFeedback entry in McpRequestContext) restated the 14-field feedback-item tree inline, plus a narrowed 4-field message shape.

What changed

Both copies now derive from the server declarations. Web import types directly from the leaf module and keeps every exported name as an alias, so all 13 importers are untouched:

exporttypeReviewThreadMessage=ReviewThreadMessageRecord;exporttypeReviewFeedbackItem=ReviewFeedbackItemRecord&{messages: ReviewThreadMessage[]};exporttypeReview=ReviewRecord;exporttypeReviewListItem=ReviewListItemRecord;exporttypeReviewWithItems=ReviewWithItemsRecord;

The MCP deps entry becomes Array<ReviewFeedbackItemRecord & { messages: ReviewThreadMessageRecord[] }> — which is exactly what listFeedbackItemsForAgent returns, so the declaration now matches its producer instead of approximating it. This widens the declared message shape from 4 fields to 7; the sole consumer (dispatch_review_list_feedback in persona-interaction-tools.ts) only reads messages.length and rest-spreads the item, the tool has no outputSchema, and the runtime objects are unchanged, so there is no behavior change.

+17 / −69, 2 files.

Drift check: none

Diffed field by field against the server declarations. All four web types were byte-equivalent — same field names, same nullability, same inline content: { body: string; resolution?: "fixed" | "dismissed" | null }. Unlike #863 (which found a missing field and over-broad unions) and #965 (one over-broad union), this copy had not diverged at all. Worth stating explicitly: the value here is preventing future drift, not fixing present drift.

Deliberately excluded (near-misses, not duplication)

  • shared/mcp/server.ts — the other five review callbacks (resolveReviewFeedback, reopenReviewFeedback, submitReview, addReviewFeedback, addReviewThreadMessage). Each declares a deliberately tiny ad-hoc result ({ id, reviewId, status, resolution: null }, { review: { id, status, summary, items: Array<{ id }> } }), not a copy of the record tree. Aliasing them would widen narrow contracts for no gain.
  • shared/mcp/server.ts:getReviewFeedbackItem — typed Promise<Record<string, unknown> | null>. That is a type gap, not a duplicate; tightening it changes what the consumer can do. Backlogged separately.
  • apps/server/src/db/seed/reviews.ts:13FeedbackSeed — carries resolutionNote/resolution/status, but it is a seed authoring input: no id/reviewId/baseRef/timestamps, status and resolution narrowed to literals, and messages: ThreadMsg[] uses minutesAgo. Same category as the db/seed/jobs.ts exclusion in Derive the remaining within-server agent-type tables from shared #950.
  • use-agent-reviews.tsSubmitReviewInput — resembles the server's CreateReviewInput but is genuinely the POST body shape: non-nullable optionals, no diffSnapshot, no agentId/reviewerType.
  • feedback-card-parts.tsx:200 — a component prop named resolutionNote: string | null, not a record copy.

A repo-wide content grep for resolutionNote (a middle field of the table) at the end of the job returns exactly one type declaration outside the seed fixture: reviews.ts:28. That is the completeness proof.

Validation

  • pnpm run check
  • pnpm run check:web with apps/server/src/generated/deleted ✅ — rules out the Alias web release/assisted-update wire types to the server definitions #863 generated-file failure mode for the new cross-boundary import
  • pnpm run finalize:web ✅ — proves esbuild erases the type-only import (nothing from agents/reviews.ts reaches the bundle)
  • pnpm --filter @dispatch/server test ✅ 2783 passed, 9 skipped
  • cd apps/web && pnpm vitest run ✅ 932 passed
  • pnpm run test:e2e ✅ 180 passed, 12 skipped

Leaf check: agents/reviews.ts imports only pg types and shared/review-limits.js (itself import-free), so no service layer enters web's TS program.

Queued next

Sub-item (c): apps/server/src/brain/store.ts vs apps/web/src/hooks/use-brain.ts (6 windows). brain/store.ts is a class-bearing store, so probe the leaf test with a scratch import + check:web before committing to the shape.

The reviews record tree was hand-copied three times: apps/server/src/agents/
reviews.ts declares it, apps/web/src/hooks/use-agent-reviews.ts restated all
four types field-for-field, and apps/server/src/shared/mcp/server.ts restated
the feedback-item tree inline in the listReviewFeedback callback signature.
Both copies now derive from the server declarations. No field-level drift was
found — all four web types were byte-equivalent to their server counterparts.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@selfcontained
selfcontained merged commit 5874959 into mainAug 17, 2026
1 check passed
@selfcontained
selfcontained deleted the debt/reviews-wire-types branch August 17, 2026 09:14
Sign up for freeto 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.

1 participant

@selfcontained