Repository navigation
fix(diagnostics): post-merge review follow-ups for #445 - #450
Conversation
- 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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughDiagnostics uploads now avoid draining unexpected multipart bodies. Report queries expose ChangesDiagnostics behavior and report projections
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (9)
internal/api/handlers/diagnostics.gointernal/api/handlers/diagnostics_test.gointernal/diagnostics/repo.gointernal/diagnostics/service.gointernal/diagnostics/service_test.gointernal/diagnostics/types.goweb/src/api/types.tsweb/src/hooks/queries/admin/diagnostics.tsweb/src/pages/AdminDiagnostics.tsx
There was a problem hiding this comment.
💡 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".
| // 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() { |
There was a problem hiding this comment.
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', '') |
There was a problem hiding this comment.
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
|
Addressed review findings in 31e6f1e:
🤖 Generated with Claude Code |
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 projectingCOALESCE(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 newReport.AppBuild. On the web side the type is split intoDiagnosticReportSummary(list; no manifest) andDiagnosticReport extends …Summary { manifest }(detail viaGetByID), so list rows can no longer dereference the manifest at compile time. Rows and the detail pane readreport.app_build; the detail pane still renders the full manifest.Preserve JSON numbers when comparing manifests (P2).
embeddedManifestMatchesdecoded viajson.Unmarshalintomap[string]any, collapsing every number tofloat64; 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 withjson.Decoder+UseNumber()on both sides so numbers keep their exact decimal text, plus a re-asserted no-trailing-data check to matchjson.Unmarshalstrictness.Quota reservation from claimed bytes (P2) — SKIP with rationale. Reserving the client-claimed
manifest.archive.bytesis sound: a report only reachesMarkReady(which rewritesblob_bytesto the measured size) afterarchiveMatchesconfirms 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_useris 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).
nextDiagnosticsPartcalledpart.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 400invalid_bundle).Tests / checks
go build ./...clean;go test ./internal/diagnostics/... ./internal/api/... -count=1all pass. New tests:TestEmbeddedManifestMatchesPreservesLargeIntegersandTestDiagnosticsUploadWrongFirstPartNotDrained(verified the latter fails when draining is restored — reads the full 1 MiB body — and passes with the fix).pnpm run lint0 errors,npx tsc --noEmitclean,vitest diagnostics.test.ts2 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
app_build) directly in both report lists and report details.Bug Fixes