Repository navigation
feat(diagnostics): upload diagnostics reports through v2 - #397
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code review summaryReviewed head: Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration. Verified findings, all fixed on this branch:
Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no Remaining: no open verified findings. Merge in stack order. Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack. Review by Claude Opus 5.5 ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a8f1763b08
ℹ️ 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".
| APIv2Client.neverConnected.contains(urlError.code) { | ||
| return .retryable(HTTPDiagnosticsErrorCode.classify(transport: urlError)) | ||
| } | ||
| return .deliveryUncertain |
There was a problem hiding this comment.
Release the claim when preflight refresh prevents dispatch
When the bearer enters the proactive-refresh window while the bundle is being built and the refresh endpoint returns an UpdateRequirement, HTTPClient throws before perform marks the request as dispatched. ownedRequest only converts pre-dispatch owner-change errors, so this fallback classifies the unsent upload as .deliveryUncertain; the coordinator then retains the delivery claim permanently and tells the user the server may already have the report. Use the dispatch state for other pre-dispatch failures as well, or explicitly classify UpdateRequirement as a definite/not-sent failure so the report can be retried after the required update.
Useful? React with 👍 / 👎.
022c1a8 to
e8860c8
Compare
a8f1763 to
844efc1
Compare
e8860c8 to
d529fa5
Compare
Self-hosted diagnostics reports still went to POST /api/v1/diagnostics/reports and the v1 chunked upload routes through plain HTTPClient calls. The chunked sequence was fenced by a hand-written server/profile check, and every failure without an answer counted as retryable, so a report whose upload had reached the server could be sent again. v2 also folds unsupported schema, stale consent, destination and archive mismatches into one 400 problem, which the v1 error-code mapping would have turned into endless retries. The report upload and the chunked create, chunk, complete and abort calls now go through the shared APIv2Client under one owner captured before the bundle is built. A new owner-bound raw request keeps the manifest splice verbatim and refuses requests after a server, account or profile switch. Answers map by problem type where the server sends a distinct one (capability_disabled, capability_not_configured, and the domain codes if a server adds them) and by status otherwise: 400 and 422 keep the report with no retry and no delete, 413 without a problem document still triggers the chunked fallback, and 413, 429 and 503 keep their existing handling. Before the first request leaves the device the report records a delivery claim; a definite answer releases it, while an unanswered upload, create or complete (or a process that dies mid-upload) leaves the report held and never sent again. The v1 methods, the destinationUnchanged closure and the v1 test routes are gone. Stack-PR: W5-W2 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…est before it is sent A server, account or profile switch that landed after DiagnosticsAPI's owner check could still stop a report upload, chunked create or complete before it left the device: ownedRequest's own guard, the fence's entry check and HTTPClient's dispatch gate all refuse with requestIdentityChanged or authorityChanged. Those are the same errors a sent request gets when its answer is discarded, so the refusal was classified as delivery uncertain and the report was held for good although nothing reached the server. HTTPClient.requestData now takes an optional HTTPDispatchRecord that perform marks just before session.data. ownedRequest turns an owner-change error with an unmarked record into APIv2OwnerChangedBeforeDispatch, which DiagnosticsAPI maps to a retryable destination change: the claim is released and a complete refused this way skips the abort. An owner change after sending stays uncertain. Tests cover the refusal inside HTTPClient, at the dispatch gate during an identity transition, on complete, and the discard after sending. Stack-PR: W5-W2 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
DiagnosticsAPI kept a private copy of the URLError codes raised before a connection. It now uses APIv2Client.neverConnected, the one list every v2 lane classifies with. Stack-PR: W5-W2 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
844efc1 to
2cd4e12
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Self-hosted diagnostics reports now upload through the v2 report and chunked-upload routes under one captured owner, and a report whose upload may have reached the server is held instead of sent again.
Problem
Self-hosted diagnostics reports still upload through
POST /api/v1/diagnostics/reportsand the v1 chunked upload routes (inventory rows 122-126), using plainHTTPClientcalls. Three things were wrong with carrying that path to v2:non_retryablein openapi, so a report whose upload reached the server could be sent again.unsupported_schema,stale_consent,destination_mismatch,archive_mismatchandinvalid_bundleinto one 400 problem (diagnostics_ingress.go:61-80, claim X1). A path-only switch would turn those into endless retries.Solution
APIv2Client+Diagnostics.swiftaddsuploadDiagnosticsReport,createDiagnosticsUpload,putDiagnosticsUploadChunk,completeDiagnosticsUploadandabortDiagnosticsUpload. Each one asserts its documented status (201, 201, 200, 201, 204).APIv2Clientgains one owner-bound raw request (ownedRequest), pluscaptureRequestOwnerandisCurrentOwner. The raw request keeps the verbatim manifest splice in the create body and sends the multipart and octet-stream bodies. Upload IDs are percent-encoded. The wire models live inAPIv2DiagnosticsModels.swift.withOwnerFenceandexpectedAuth. This replaces thedestinationUnchangedclosure. A switch mid-sequence stops the chunked upload without an abort, as before.ownedRequestreports an owner change caught before the request reached the URL session (its own check, the fence's entry check, orHTTPClient's dispatch gate and owner checks) asAPIv2OwnerChangedBeforeDispatch.HTTPClient.requestDatatakes an optionalHTTPDispatchRecordthat is marked just beforesession.data, which is how it tells the two apart. A refusal before dispatch releases the claim and stays retryable. An owner change after sending stays uncertain. The selected profile goes out asX-Profile-Id, which v2 reads as report attribution. The existing captured-vs-active profile checks stay in place.capability_disabledmaps to disabled,capability_not_configuredto storage unavailable, and the five domain codes are honored if a server starts sending them as problem types. Otherwise the status decides:server_rejectedand the user sees "Report kept; it can't be uploaded to this server."delivery_uncertainclaim in itsstate.json. A definite answer releases the claim. An unanswered upload, create or complete keeps it, and so does a process that dies mid-upload. A report holding the claim is never auto-uploaded, prompted or sent again. The user can delete it. A transport failure before any connection (offline, DNS, TLS) counts as definite;DiagnosticsAPIuses the sharedAPIv2Client.neverConnectedlist for this. After an uncertaincompletethe upload session is not aborted.HTTPErrorcode mapping,DiagnosticsChunkedUploadSession,EmptyDiagnosticsResponse, thedestinationUnchangedclosure and the v1 test routes are gone.HTTPClientDiagnosticsClassificationTestspath vectors now use v2 routes (34 v1 matches removed).DiagnosticsChunkedUploadTestsbecameDiagnosticsUploadV2Tests.Failure outcomes
POST /api/v2/diagnostics/reports(non_retryable)report_id/short_id: report deleted locally, "Sent as …"delivery_uncertain) and never sent again. The user can delete it.POST /api/v2/diagnostics/reports/uploads(non_retryable)PUT …/uploads/{upload_id}/chunks/{chunk_index}(natural_idempotent)complete: the session is aborted best-effort and the report kept per the error table. An owner change stops without an abort.POST …/uploads/{upload_id}/complete(non_retryable)delivery_uncertain). The session is not aborted, because the report may already be ingested.DELETE …/uploads/{upload_id}(natural_idempotent)Validation
DiagnosticsUploadV2Tests,HTTPClientDiagnosticsClassificationTests,HostedDiagnosticsAPITests,DiagnosticsCapabilitiesV2Tests,DiagnosticsReviewFixesTests,DiagnosticsViewModelTestsandDiagnosticsContractTests.scripts/ci/check-no-api-v1.shpasses.DiagnosticsAPI.swift,HTTPClientDiagnosticsClassificationTests.swiftandHostedDiagnosticsAPITests.swiftno longer contain v1 paths, andDiagnosticsChunkedUploadTests.swiftis replaced byDiagnosticsUploadV2Tests.swift.StubURLProtocolcoverage:X-Profile-Idattribution.DiagnosticsAPI, insideHTTPClientafterDiagnosticsAPI's check passed, and at the dispatch gate during an identity transition. All three are retryable and send nothing.server_rejectedwith the claim released.Risks and follow-ups
DiagnosticsAPI.mapUploadErrorneeds updating.complete. This follows thenon_retryablerule literally. Relaxing it would need an owner decision.AI disclosure
Code and description written by Claude Opus 5.5 (
claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.Part 49 of 50 in the Apple API v2 stack. Base:
apiv2-stack/48-diagnostics-capabilities-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code