Skip to content

fix(diagnostics): post-merge review follow-ups for #445 - #450

Merged
Quick104 merged 2 commits into
mainfrom
feat/client-diagnostics-server
Jul 21, 2026
Merged

Quick104 merged 2 commits into
mainfrom
feat/client-diagnostics-server

Conversation

@Quick104

@Quick104 Quick104 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

These changes address the four review comments posted on #445 at 2026-07-21T17:55Z — roughly 20 minutes before #445 was merged, so they never landed in that PR. This is the post-merge follow-up.

Findings addressed

  • Stop dereferencing omitted list manifests (P2). The admin list projection omits the manifest, but list rows dereferenced report.manifest.report.app_build, throwing as soon as any report rendered. Fixed server-side by projecting COALESCE(manifest->'report'->>'app_build','') into both the list and detail queries (a cheap JSONB text extraction — no manifest shipped in list responses) and scanning it into a new Report.AppBuild. On the web side the type is split into DiagnosticReportSummary (list; no manifest) and DiagnosticReport extends …Summary { manifest } (detail via GetByID), so list rows can no longer dereference the manifest at compile time. Rows and the detail pane read report.app_build; the detail pane still renders the full manifest.

  • Preserve JSON numbers when comparing manifests (P2). embeddedManifestMatches decoded via json.Unmarshal into map[string]any, collapsing every number to float64; two manifests differing only in a large integer above 2^53 (e.g. log_summary.lines) rounded to the same float and compared equal, letting a tampered bundle through. Now decoded with json.Decoder + UseNumber() on both sides so numbers keep their exact decimal text, plus a re-asserted no-trailing-data check to match json.Unmarshal strictness.

  • Quota reservation from claimed bytes (P2) — SKIP with rationale. Reserving the client-claimed manifest.archive.bytes is sound: a report only reaches MarkReady (which rewrites blob_bytes to the measured size) after archiveMatches confirms the claimed bytes/sha/entries exactly equal the streamed bundle, so no stored report can ever occupy more bytes than it reserved — under-claiming to exceed the storage quota is impossible, and a lying upload is rejected and compensated (blob deleted, row marked failed) before it counts. The residual cost of such rejected churn is bandwidth, bounded by the per-account single in-flight upload cap; max_bytes_per_user is a storage cap enforced oldest-first by retention (per the design doc), not a bandwidth limit. Documented at the reservation site; no code change beyond the comment.

  • Reject bad multipart parts without draining (P2). nextDiagnosticsPart called part.Close() on a wrong-name/wrong-content-type part, which drains the unread body first — letting a max-size wrongly-named first part stream up to the bundle limit while holding the in-flight slot before returning 400. It now abandons the mismatched part and returns immediately, so malformed uploads fail promptly under load. Error semantics are unchanged (still 400 invalid_bundle).

Tests / checks

  • Go: go build ./... clean; go test ./internal/diagnostics/... ./internal/api/... -count=1 all pass. New tests: TestEmbeddedManifestMatchesPreservesLargeIntegers and TestDiagnosticsUploadWrongFirstPartNotDrained (verified the latter fails when draining is restored — reads the full 1 MiB body — and passes with the fix).
  • Web: pnpm run lint 0 errors, npx tsc --noEmit clean, vitest diagnostics.test.ts 2 passed, prettier + gofmt clean.

Part of the client diagnostics capability — spec: #430.

AI-use disclosure: authored by Claude Code (Claude Opus 4.8) under human direction; all build/test/lint checks above were run and pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_012e3QjbPo96ed9Mn2qRiUkh

Summary by CodeRabbit

  • New Features

    • Diagnostic reports now include and display the application build (app_build) directly in both report lists and report details.
    • Report data is presented using distinct “summary” (list) vs “full detail” (view) shapes for more consistent UI behavior.
  • Bug Fixes

    • Invalid diagnostic uploads are rejected without unnecessarily processing large request bodies.
    • Manifest JSON validation now preserves large integers correctly and rejects trailing non-whitespace/extra JSON to improve report integrity.

- AdminDiagnostics list: fix regression where rows dereferenced the
  now-omitted manifest for app_build. Project app_build server-side out
  of manifest JSONB into both list and detail responses (cheap
  COALESCE(manifest->'report'->>'app_build','')), split the TS type into
  DiagnosticReportSummary (list, no manifest) and DiagnosticReport
  (detail, with manifest), and read report.app_build in the row/detail.
- embeddedManifestMatches: decode with json.Decoder + UseNumber so large
  integers above 2^53 (e.g. log_summary.lines) can't collapse to the same
  float and falsely match; re-assert no-trailing-data strictness.
- Quota reservation (SKIP): reserving the client-claimed archive.bytes is
  sound because archiveMatches requires claimed==actual before MarkReady,
  so no stored report exceeds its reservation; documented in a code comment.
- Multipart parts: reject a wrong-name/wrong-content-type part without
  calling part.Close(), which would drain up to the bundle limit while
  holding the in-flight slot; abandon it so malformed uploads fail promptly.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012e3QjbPo96ed9Mn2qRiUkh
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d6af92ba-a0ab-4c60-b3ad-e4e85788ec80

📥 Commits

Reviewing files that changed from the base of the PR and between 9fad08a and 31e6f1e.

📒 Files selected for processing (3)
  • internal/diagnostics/repo.go
  • internal/diagnostics/service.go
  • internal/diagnostics/service_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/diagnostics/service.go

📝 Walkthrough

Walkthrough

Diagnostics uploads now avoid draining unexpected multipart bodies. Report queries expose app_build, JSON manifest comparison preserves large integers, and the admin UI uses separate summary and detail report types.

Changes

Diagnostics behavior and report projections

Layer / File(s) Summary
Multipart rejection without draining
internal/api/handlers/diagnostics.go, internal/api/handlers/diagnostics_test.go
Unexpected first multipart parts are rejected without draining their full bodies, with coverage for large invalid uploads.
Report projection and manifest matching
internal/diagnostics/types.go, internal/diagnostics/repo.go, internal/diagnostics/service.go, internal/diagnostics/service_test.go
Reports expose projected app_build values across report and cleanup projections, while manifest decoding preserves large integers and rejects trailing data.
Admin report summary contract
web/src/api/types.ts, web/src/hooks/queries/admin/diagnostics.ts, web/src/pages/AdminDiagnostics.tsx
Admin list responses use DiagnosticReportSummary, while detail responses retain the parsed manifest and page rendering reads app_build directly.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested labels: v1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to the diagnostics follow-up changes, though it is broad and doesn’t name the main fix.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/client-diagnostics-server

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/diagnostics/service.go`:
- Around line 564-565: Update the JSON validation flow in the manifest decoding
logic around dec.More() to perform one additional decode after the manifest
object and require io.EOF, rejecting any trailing JSON including an extra
closing delimiter. Add a regression test covering an input such as
{"log_summary":{}}} and assert it is rejected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 63a671f9-0e33-4ac7-b31b-3fc5d31cfca1

📥 Commits

Reviewing files that changed from the base of the PR and between 8b3bff1 and 9fad08a.

📒 Files selected for processing (9)
  • internal/api/handlers/diagnostics.go
  • internal/api/handlers/diagnostics_test.go
  • internal/diagnostics/repo.go
  • internal/diagnostics/service.go
  • internal/diagnostics/service_test.go
  • internal/diagnostics/types.go
  • web/src/api/types.ts
  • web/src/hooks/queries/admin/diagnostics.ts
  • web/src/pages/AdminDiagnostics.tsx

Comment thread internal/diagnostics/service.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9fad08a6fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/diagnostics/service.go Outdated
// json.Unmarshal rejects trailing bytes after the value; Decoder.Decode does
// not, so re-assert that strictness — a manifest with trailing junk is not a
// clean single object and must not compare equal.
if dec.More() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject trailing delimiters after decoded manifests

When the embedded manifest.json is a valid object followed by a stray ] or }, dec.Decode(&obj) succeeds and dec.More() returns false because More is meant for array/object iteration, so decodeJSONObject accepts data that json.Unmarshal used to reject. Since ValidateBundle only captures the first entry and relies on embeddedManifestMatches for strict comparison, a bundle can store an embedded manifest whose bytes are not a single clean JSON object while still comparing equal to the accepted part-1 manifest; use a second Decode and require io.EOF instead of More().

Useful? React with 👍 / 👎.

report_type, platform, app_version, crash_summary, playback_session_ids,
blob_bucket, blob_key, blob_bytes, uncompressed_bytes, blob_sha256
blob_bucket, blob_key, blob_bytes, uncompressed_bytes, blob_sha256,
COALESCE(manifest->'report'->>'app_build', '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split cleanup projections away from app_build

Because reportListSelectSQL now always selects COALESCE(manifest->'report'->>'app_build', ''), the retention and stale-cleanup queries that reuse this projection have to read and evaluate each candidate report's JSONB manifest even though cleanup only uses the id/state/blob fields for deletion. On installations with many expired or stale reports and 64 KiB manifests this turns scheduled cleanup into unnecessary manifest I/O; keep the app-build projection in the admin list/detail path or add a cleanup-only projection that omits it.

AGENTS.md reference: AGENTS.md:L11-L17

Useful? React with 👍 / 👎.

- service.go: reject trailing data after the decoded manifest object.
  Decoder.More() only reports array/object iteration, so a stray closing
  delimiter (e.g. {...}}) slipped through where json.Unmarshal used to
  reject it. Require the stream to reach io.EOF after decoding on both
  the received and embedded sides; add a regression test.
- repo.go: split the list projection from cleanup. reportListSelectSQL
  keeps the app_build JSONB extraction for the admin list; new
  reportCleanupSelectSQL omits it so retention/stale batches don't touch
  each candidate's manifest JSONB just to delete a row.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012e3QjbPo96ed9Mn2qRiUkh
@Quick104

Copy link
Copy Markdown
Contributor Author

Addressed review findings in 31e6f1e:

  • service.go (trailing data after decoded manifest) — Fixed. Decoder.More() only reports array/object iteration, so a stray closing delimiter like {"log_summary":{}}} slipped through where json.Unmarshal used to reject it. decodeJSONObject now requires the stream to reach io.EOF after decoding (a second Decode must return io.EOF), which rejects any trailing token — junk or an extra }/] — while still allowing trailing whitespace, and applies to both the received and embedded sides. Added TestEmbeddedManifestMatchesRejectsTrailingData covering }, ], trailing garbage, a second object, and trailing whitespace.
  • repo.go (cleanup paying for app_build JSONB extraction) — Fixed. Split the projection: reportListSelectSQL keeps COALESCE(manifest->'report'->>'app_build','') for the admin list, and a new reportCleanupSelectSQL omits it so retention/stale batches never read the manifest JSONB just to delete a row. Added scanReportCleanup (via a shared summaryScanTargets helper) and switched RetentionCandidates/StaleReceiving to the cleanup projection.

go build ./... and go test ./internal/diagnostics/... ./internal/api/... -count=1 both pass.

🤖 Generated with Claude Code

@Quick104
Quick104 merged commit 0a91444 into main Jul 21, 2026
1 check passed
@Quick104
Quick104 deleted the feat/client-diagnostics-server branch July 21, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant