Skip to content

feat(diagnostics): read diagnostics capabilities from v2 - #396

Merged
Quick104 merged 1 commit into
mainfrom
apiv2-stack/48-diagnostics-capabilities-v2
Sep 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
apiv2-stack/48-diagnostics-capabilities-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Self-hosted diagnostics now read upload availability and limits from GET /api/v2/diagnostics/capabilities, bound to the request owner.

Problem

Self-hosted diagnostics read upload availability and limits from GET /api/v1/diagnostics/status (inventory row 121). The call went straight through HTTPClient with no owner fence, and it is one of the last v1 reads in the diagnostics path.

Solution

  • Add APIv2Client.diagnosticsCapabilities() in Networking/APIv2/APIv2Client+Diagnostics.swift. It reads GET /api/v2/diagnostics/capabilities (getDiagnosticsCapabilities) through requestGet, which binds the read to the owner captured before the request, sends the account scope, and requires a 200.
  • Add the APIv2DiagnosticsCapabilities wire model in APIv2DiagnosticsModels.swift. It projects onto the existing DiagnosticsStatusResponse, so the coordinator, prompt policy and persisted last-known snapshots are unchanged and older snapshots still decode.
  • Availability follows invariant I9: .available only when allowed is true and state == "available". not_configured maps to storage unavailable, which is how the server reports missing storage. Every other state maps to disabled. The free-form status string is not read.
  • DiagnosticsCoordinator.refreshStatus calls the method through siloAPI.apiV2Client, so tests that inject a SiloAPI also cover the v2 read.
  • isTransientCaptureFallbackFailure recognizes APIv2Error: a 5xx problem or status still lets a persistent capture fall back to the last-known snapshot. Every other v2 answer fails closed, including serverUpdateRequired.
  • The diagnostics screen hides itself on APIv2Error.serverUpdateRequired, a v1-only server. This replaces the old plain-404 check, which only the v1 route could trigger.
  • Delete DiagnosticsAPI.getDiagnosticsStatus() and the v1 status routes and fixtures in the tests.

Android reads the same operation (DiagnosticsApi.kt getStatus).

Validation

  • iOS, tvOS and macOS builds pass on this branch. The code compiles only under #if os(iOS) || os(tvOS), so the macOS build does not exercise it.
  • Focused tests pass: 110 on iOS and 108 on tvOS, 0 failures, covering DiagnosticsCapabilitiesV2Tests (new), HostedDiagnosticsAPITests, DiagnosticsContractTests, DiagnosticsChunkedUploadTests, DiagnosticsReviewFixesTests and DiagnosticsViewModelTests.
  • The new StubURLProtocol tests check:
    • the v2 path and the bearer credential
    • the full projection
    • the allowed/state table for allowed:false, disabled, not_configured and unsupported
    • that upload_chunk_bytes: 0 means no chunked upload
    • that a 503 problem permits the capture fallback and a 403 problem does not
    • that the legacy listener's plain 404 becomes serverUpdateRequired
  • scripts/ci/check-no-api-v1.sh passes.
  • The final stack passed the full suites (iOS 1981 tests, tvOS 1792 tests, 0 failures), the macOS build and the v1 path guard, and every branch in the stack builds on its own.

Risks and follow-ups

  • This PR wires no mutations, so it has no failure-outcome table.
  • A v1-only server now hides the diagnostics screen, as a server without the diagnostics route did before. The connection-level update-required state (F5) explains the cause.
  • Uploads still use the v1 routes until W5-W2, the next PR.
  • The ETag and If-None-Match conditional read is not used. Each refresh does a full read, as before.

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 48 of 50 in the Apple API v2 stack. Base: apiv2-stack/47-notification-sync-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: cb975236-acda-4a94-b5d7-02d02868e9c8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

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

@greptile-apps greptile-apps 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.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:24:48.542136Z e8860c8 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: 022c1a85 (apiv2-stack/48-diagnostics-capabilities-v2).

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: none.

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 /api/v1 request from the new builds except the retained health probe.

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 (claude-opus-5-5) agents in Claude Code (T3 Code).

@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: e8860c8c4f

ℹ️ 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 on lines +451 to 452
let status = try await siloAPI.apiV2Client.diagnosticsCapabilities()
let user = try await siloAPI.currentUser()

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 Bind both diagnostics reads to one account owner

When credentials are replaced on the same registered server between these two awaits, each v2 request can succeed under a different owner: capabilities come from account A, while currentUser() returns account B. The final guard checks only the unchanged server ID and that some token exists, so A's account-scoped allowed value and limits are persisted under B's diagnostics binding and may enable capture despite B being denied. Capture one request owner before both reads and verify/reuse it for both responses.

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/47-notification-sync-v2 branch from 576679a to 5452dc7 Compare September 23, 2026 13:45
Self-hosted diagnostics still read upload availability and limits from
GET /api/v1/diagnostics/status through a plain HTTPClient call with no
owner fence.

The coordinator now reads GET /api/v2/diagnostics/capabilities through the
shared APIv2Client, bound to the owner captured before the request. The v2
document is projected onto the existing DiagnosticsStatusResponse, so
persisted last-known snapshots still decode. Uploads count as available
only when allowed is true and state is available; not_configured maps to
storage unavailable and every other state to disabled. A v2 5xx still
lets a persistent capture fall back to the last-known snapshot, other
answers fail closed, and a v1-only server hides the diagnostics screen as
the old 404 did. The v1 method and v1 test routes are gone.

Stack-PR: W5-W1
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Base automatically changed from apiv2-stack/47-notification-sync-v2 to main September 23, 2026 13:46
@Quick104
Quick104 force-pushed the apiv2-stack/48-diagnostics-capabilities-v2 branch from e8860c8 to d529fa5 Compare September 23, 2026 13:46
@Quick104
Quick104 merged commit 65a6c74 into main Sep 23, 2026
1 check passed
@Quick104
Quick104 deleted the apiv2-stack/48-diagnostics-capabilities-v2 branch September 23, 2026 13:46
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Sign up for free to 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