Skip to content

fix(session): loosen remaining stored numeric schemas to tolerate legacy data#26622

Merged
kitlangton merged 1 commit intodevfrom
kit/loosen-stored-numeric-schemas
May 10, 2026
Merged

fix(session): loosen remaining stored numeric schemas to tolerate legacy data#26622
kitlangton merged 1 commit intodevfrom
kit/loosen-stored-numeric-schemas

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #26620. The audit done after that PR flagged additional NonNegativeInt fields decoding stored DB JSON or external (git / HTTP) output where the same failure mode applies: a single nonsensical value (provider returns -1 for statusCode, git numstat emits - for binary files, an old client wrote a sentinel) makes the response Schema encoding fail and the endpoint returns empty-body 400 — taking out the entire list response.

The constraint was wrong, not the data: these fields are statistics/measurements crossing an HTTP boundary, not invariants. Loosening to Schema.Finite matches the pattern already adopted for Snapshot.FileDiff.{file,patch,status} in #26574 / #26579.

Changes

File Field Reason
src/v2/session-event.ts RetryError.statusCode Sourced from provider HTTP errors; some providers return 0/-1/non-int
src/v2/session-event.ts Retried.attempt Counter; legacy/imported rows can have nulls or out-of-range values
src/session/session.ts Summary.{additions,deletions,files} Aggregated from git numstat output; binary files yield -. Sibling Snapshot.FileDiff was already loosened
src/session/message-v2.ts FilePartSourceText.{start,end} Sourced from LSP / ripgrep, which occasionally return -1 for "unknown range"
src/project/vcs.ts FileDiff/FileStatus.{additions,deletions} Same git binary-file issue; mirrors the Snapshot.FileDiff loosening
src/snapshot/index.ts FileDiff.{additions,deletions} Same root cause; previous fix #26574 left these strict

Direct measurements that genuinely can't be negative (character offsets within a known buffer, ripgrep stats coming from a single tool we trust, retry counters we own) keep NonNegativeInt.

Verification

bun run typecheck

Test plan

  • Existing test suites pass
  • Manually verify /instance/vcs/diff and /session endpoints still return 200 with valid data

Related

…acy data

Follow-up to #26620. The audit there flagged several other strict
NonNegativeInt fields decoding stored DB JSON or external (git/HTTP)
output. Same failure mode: one nonsensical legacy value (provider 4xx
status reported as -1, git numstat dash-for-binary, etc.) makes the
endpoint 400 with empty body and breaks the whole list response.

Loosened to Schema.Finite (matching the pattern already used in
Snapshot.FileDiff after #26574/#26579):

- v2/session-event.ts: RetryError.statusCode, Retried.attempt
- session/session.ts: Summary.{additions,deletions,files}
- session/message-v2.ts: FilePartSourceText.{start,end}
- project/vcs.ts: FileDiff/FileStatus.{additions,deletions}
- snapshot/index.ts: FileDiff.{additions,deletions}

These are statistics/measurements crossing the HTTP boundary, not
invariants — negative values shouldn't crash the response. Direct
measurements that genuinely can't be negative (character offsets,
retry counters, ripgrep stats) keep NonNegativeInt.
@kitlangton kitlangton merged commit 29250a0 into dev May 10, 2026
11 checks passed
@kitlangton kitlangton deleted the kit/loosen-stored-numeric-schemas branch May 10, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant