Skip to content

feat(apiv2): add the v2 contract harness, probe, and pilot operations [api-v2 phase 3] - #294

Merged
Quick104 merged 33 commits into
apiv2from
api-v2/phase-3-pilot
Sep 5, 2026
Merged

Quick104 merged 33 commits into
apiv2from
api-v2/phase-3-pilot

Conversation

@Quick104

@Quick104 Quick104 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The server's API v2 pilot (silo-server [api-v2 phase 3], branch api-v2/phase-3-pilot) publishes five operations with deterministic contract fixtures. The Android client had no offline proof that SiloJson and its handwritten models decode that contract, no v2 discovery probe, and no explicit state for a server that only speaks v1.

Solution

  • Sync script scripts/sync-apiv2-fixtures.sh <server checkout> vendors only the fixtures this client consumes (four pilot operations, the system-info probe body, the generic problem bodies; 14 files) plus fixtures.schema.json and a filtered index.json into shared/src/commonTest/resources/api/v2/fixtures/, and writes SOURCE in the existing key=value convention with commit=17380cbca59dff44d8e1454fd07ece37efc26afe. The OpenAPI document is never vendored.
  • Models under network/apiv2/ (new @Serializable types, never the v1 data classes) for getSetupStatus, getCurrentUser, listProgress, updateProfile, plus Problem and SystemInfo. Enums carry an explicit unknown fallback that is observable, not silently coerced to a default.
  • Conformance tests (ApiV2ContractTest, ApiV2ProbeTest, ApiV2NoFallbackTest, ApiV2NoV1TransportSourceTest, AuthRepositoryContractTest): every vendored fixture decodes with the production SiloJson; the fields each UI flow consumes are asserted with explicit null/absence semantics; unknown fields and unknown enum values are injected; the PATCH encoder distinguishes omitted from literal null under explicitNulls = false; a source scan asserts no /api/v1 literal under network/apiv2/; a failed v2 updateProfile is never retried against v1.
  • Probe and update-server state. ApiV2Probe GETs /api/v2/system/info and maps only the legacy listener's plain 404 to UpdateServer; timeout, TLS failure, HTML with 200, malformed JSON, 401, 429, and 5xx each remain their own failure. ServerContract.UPDATE_REQUIRED is stored per registry entry and ApiV2Gate blocks the pilot v2 calls with one user-visible message. The probe runs on connect (ServerSetupViewModel), on launch restore (MainActivity, MainTvActivity), on every server switch through the new AuthRepository.switchToServer, on refreshActiveServerName, and after a pairing rollback restores the previous server. A stale verdict for a previous server id is dropped; failures never overwrite a stored state.
  • Migration. AuthApi setup status and current user, ProfileApi profile update, and PersonalDataApi progress listing use v2. Non-pilot operations stay on v1 during the bridge, as the server contract specifies.

Validation

On 97315e86: ./scripts/test-check-build-supply-chain.sh, ./scripts/check-build-supply-chain.sh, ./gradlew testDebugUnitTest, ./gradlew :android-shared:lintDebug :androidApp:lintDebug :androidTvApp:lintDebug :androidApp:lintVitalRelease :androidTvApp:lintVitalRelease (no baseline regenerated), ./gradlew :androidApp:assembleDebug :androidTvApp:assembleDebug, clean tree. All passed. Server side: make verify-apiv2-fixtures-siblings against this branch reports the vendored copies current.

Review history

A 3-lens blind review found one Android major: the probe ran only inside setServerUrl, so servers saved before this build never reached the update-server state. Fixed by probing on launch, on every switch path, and on identity refresh; the re-verify lens then asked for coverage of the pairing rollback path, added in RegistryPairingAuthPortTest with a real AuthRepository over Ktor MockEngine.

Risks and follow-up

  • Whether the update-server state should block the whole session UI is out of the pilot; the state exists, is tested, and gates the pilot v2 calls.
  • ServerListViewModel now takes an AuthRepository; Koin wiring updated in AndroidModule and AndroidTvModule.

Companion PRs: Silo-Server/silo-server#941 (fixtures source), Silo-Server/silo-apple#253.

Related issue: Silo-Server/silo-server#135

Recovery validation

Commit c2ec861e refreshes the server contract after shared and TV sign-in commits a session. Queued refreshes check the active server, and the refresh survives cancellation of the sign-in caller once scheduled.

Focused validation: 31 shared contract tests and the TV sign-in race test passed; TV production and test sources compiled. The strengthened cancellation regression passed on a subsequent shared-suite run. Independent review of this fix found no additional actionable defects. No live-device validation or full-suite rerun was performed for this follow-up.

AI Disclosure

  • Recovery tooling: Codex with gpt-6-astra at low effort for implementation and medium effort for independent orchestration/review; earlier Claude contributions remain described below.
  • Harness: Claude Code
  • Tool(s): Claude Code (orchestrator session driving implementation and review subagents through the Workflow tool and the Agent tool)
  • Model(s): claude-fable-5-1 (claude-fable-5-1[1m]) for orchestration, all implementers, and all review agents
  • Involvement: Fully AI-generated; maintainer review pending (opened by the orchestrating agent under the maintainer's program instruction)
  • Adversarial review: see "Review history" above; the finding was arbitrated by the orchestrator against the plan's compatibility rule before the fix was briefed.

🤖 Generated with Claude Code

Quick104 and others added 7 commits September 4, 2026 17:05
Adds scripts/sync-apiv2-fixtures.sh, which copies the pilot-operation and
generic problem fixtures plus fixtures.schema.json and a filtered index.json
from a silo-server checkout into shared/src/commonTest/resources/api/v2/fixtures,
recording the exact server commit in SOURCE (key=value convention).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
New lenient @serializable models under network/apiv2 for the four Android
pilot operations plus Problem and SystemInfo. Enums are string-backed value
classes whose unknown values stay observable (known == null) instead of
collapsing to a default under coerceInputValues. PATCH bodies use a Patch
wrapper so omitted members are absent and cleared members are literal null
despite explicitNulls=false. ApiV2ContractTest decodes every vendored fixture
with the production SiloJson and pins null/absence semantics, defaults,
unknown fields and enum values, and the encoded PATCH shape.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ApiV2Probe GETs /api/v2/system/info once per established connection and
returns V2(info) / UpdateServer / Failure(kind). Only a 404 with a text/plain
Content-Type (the legacy listener's http.NotFound) is UpdateServer; HTML or
problem+json 404s, HTML 200s, malformed JSON, 401/403, 429, 5xx, timeouts and
connect/TLS exceptions each stay their own failure kind. ServerEntry gains a
ServerContract state (UNKNOWN / V2 / UPDATE_REQUIRED) persisted through the
registry; both server-setup view models probe the candidate on connect and
show the update-server message. ApiV2Gate blocks pilot v2 calls in the
UPDATE_REQUIRED state without ever redirecting to a v1 path.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… to v2

getSetupStatus, getMe, listProgress, and updateProfile now call the v2
endpoints only (GET /api/v2/system/setup, GET /api/v2/account/me,
GET /api/v2/progress walked by cursor, PATCH /api/v2/profiles/{id}) with no
v1 fallback and no replay of a failed mutation. The API layer adapts the v2
models back to the v1-shaped User/Profile/ProgressListResponse so repositories
and screens keep compiling; User.id and impersonator_user_id become opaque
strings. DI wires ApiV2Gate and ApiV2Probe. ApiV2NoFallbackTest proves a failed
PATCH is not retried against /api/v1 and that UPDATE_REQUIRED blocks the call
before any request.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… refresh

The v2 contract probe only ran inside AuthRepository.setServerUrl, so servers
saved before this build stayed ServerContract.UNKNOWN forever: nothing probed
when the app restored its active server on launch, when the user picked a
server from the server list, when device pairing switched servers, or when the
server identity was refreshed. A v1-only server could never reach the
update-server state on those paths (F5).

AuthRepository now mirrors Apple's AuthService: refreshActiveServerName()
(re)establishes the contract verdict before reading the branding name, with an
optional knownContract so the connect path records the verdict it already has
instead of probing twice. A new switchToServer(id) is the single entry point
for activating a registered server (registry switch + token scope + refresh);
ServerListViewModel, TvServerListViewModel, and the pairing wrong-server screen
in AppNavigation use it. RegistryPairingAuthPort cannot reach the repository
during its restore-on-failure switch, so it calls refreshServerContract()
after the switch. Both MainActivity variants refresh once when the launch
path restores an active server.

Recording is guarded against a switch racing the probe: the active server id
is captured before the request and the verdict is dropped if it changed, so a
slow answer never overwrites the newer server's state. Failures still record
nothing (UNKNOWN is non-blocking).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
RegistryPairingAuthPort re-probes the v2 contract after restoring the
previous server on a failed account replacement, but every rollback test
built the port without an AuthRepository, so that line never ran.

Fail the token manager's post-commit hook so the registry has already
switched to the new server when the error surfaces, then assert that a
supplied AuthRepository issues exactly one GET /api/v2/system/info and
records the verdict against the restored server. A second test pins the
no-repository path: rollback still restores the old identity and leaves
the contract UNKNOWN.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The server pilot branch gained schema examples, which changed the
contract digest carried in get_system_info_ok.json. Re-run the sync script
against that commit; SOURCE now pins 17380cbca59dff44d8e1454fd07ece37efc26afe.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Quick104 Quick104 added api-v2 API v2 / Huma program (epic silo-server#135) stacked Stacked on another open PR or branch labels Sep 4, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-05T16:57:44.867856Z c2ec861 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.

@coderabbitai

coderabbitai Bot commented Sep 4, 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: Team

Run ID: b24f6b91-a755-438d-b9e6-86bf505c31fe

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

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

@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: 97315e86e4

ℹ️ 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".

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed 97315e86e4746447a6ef0b536ed58e3fe9bdc6a0. Five actionable findings: one additional profile-enum mismatch and independent confirmation of the four existing automated review findings.

Validation: 42 focused v2 and repository contract tests passed. Findings were verified against production callers and the exact companion server revision; device flows were not exercised.

@Quick104
Quick104 changed the base branch from main to apiv2 September 4, 2026 23:59
Quick104 and others added 5 commits September 4, 2026 20:48
…rver

AuthApi.getSetupStatus(serverUrl) targets a candidate server the app is
not connected to, but it was wrapped in the ACTIVE entry's ApiV2Gate. A
user whose active server is UPDATE_REQUIRED therefore could not add a
different, supported server (both Add Server flows probe the candidate
first), and could not reconnect to the same server after upgrading it.

Explicit-server (absolute URL) v2 overloads now use ApiV2Gate.Unrestricted;
the candidate's own gate is the contract probe ServerSetupViewModel runs
before switching. The relative form still targets the active server and
stays gated. getSetupStatus(serverUrl) is the only explicit-server v2
overload today; the other absolute-URL calls in network/api are v1.

Test: ApiV2NoFallbackTest.explicitServerSetupStatusBypassesTheActiveServersUpdateRequiredVerdict

Co-Authored-By: Claude Fable 5.1 <[email protected]>
RegistryPairingAuthPort refreshed the contract verdict only in the
rollback branch. After a successful replaceAccountSession the newly
paired server stayed at UNKNOWN (or a stale UPDATE_REQUIRED saved by an
older build), so gated startup consumers acted on a verdict that was
never established for it.

Pairing is a server switch like every other path: after the session
commits and before the port reports SignedIn, run refreshServerContract()
for the now-active server. The rollback call is kept. The probe never
throws on a failed request, so this cannot undo a committed session.
The override now declares `: Unit` so the added tail expression does not
change the port's return type.

Test: RegistryPairingAuthPortTest.successfulPairingProbesTheNewServerExactlyOnce

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…aunch

The launch probe in resolveStartDestination was fire-and-forget, so gated
startup consumers (ProfileSelectionViewModel's admin lookup, and anything
else behind ApiV2Gate) could run against a stale UPDATE_REQUIRED verdict
saved before the server was upgraded, and fail without a request.

Only UPDATE_REQUIRED is harmful: UNKNOWN and V2 both pass the gate. So
resolveStartDestination (already a suspend fun inside a LaunchedEffect on
both phone and TV) now calls the new
AuthRepository.awaitContractRefreshIfUpdateRequired(), which probes and
waits at most 3 s only when the stored verdict is UPDATE_REQUIRED, and
passes the result to refreshActiveServerName(knownContract) so the
background identity refresh does not probe twice. No runBlocking on the
main thread; the wait runs under Dispatchers.IO.

Consumers are made robust as well: AuthRepository exposes
activeServerContractFlow (from registry.activeEntry), and
ProfileSelectionViewModel collects it once in init and re-runs
loadProfiles() when the contract moves from UPDATE_REQUIRED to V2.

Tests:
- AuthRepositoryContractTest: awaitContractRefreshIfUpdateRequired
  replaces a stale UPDATE_REQUIRED verdict / does not probe when the gate
  would pass
- ProfileSelectionViewModelContractTest.v2VerdictArrivingAfterUpdateRequiredRetriggersTheGatedLoad

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Removing the ACTIVE server makes the registry promote the next-MRU entry,
but neither server-list view model probed it: TV only called
tokenManager.switchActiveServer(promotedId), and the phone did nothing
after remove(). The promoted server kept whatever contract verdict an
older build had stored (or UNKNOWN), and its fetched name was never
refreshed.

TV: replace the bare token switch with authRepository.switchToServer
(registry switch + token switch + refreshActiveServerName). It is
idempotent when the registry already points at promotedId —
AndroidServerRegistry.switchTo just bumps lastUsedAt and re-applies the
same active id — and the navigation logic after it is unchanged.

Phone: mirror the TV wasActive/promoted logic and call
authRepository.refreshActiveServerName() when the active server was
removed and another one was promoted.

Test: AuthRepositoryContractTest `switchToServer on the already-active id
still probes` (no ServerList view-model tests exist).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…test

ProfileSelectionViewModelContractTest asserted on a plain list the mock
engine appended to from its own thread, so under the full unit-test run
the first assertion could observe an empty list before the v1 request
had landed. Requests now go through a channel and each expected request
is awaited on a real clock (bounded), so the test observes network
arrivals instead of assuming them.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 025c0fb4d3

ℹ️ 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".

The server pilot branch documented updateProfile's real statuses and media
type (contract digest moved) and switched listProgress to keyset cursors
(list_progress_ok.json next_cursor changed). SOURCE now pins
74fe2b4ac97349167d1bb85892d7f0566bd43d49.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 14b2a8ec1d

ℹ️ 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".

Quick104 and others added 5 commits September 4, 2026 21:32
The probe mapped any 404 with a text/plain Content-Type to UpdateServer,
so a reverse proxy's own plain-text "Not Found" would tell the user to
update a server that may not be a Silo at all.

Decide on the body instead: only Go's http.NotFound text
("404 page not found", tolerating the single trailing newline it writes)
is UpdateServer. Leading whitespace, extra newlines, or any other body
stays Failure(UNEXPECTED_STATUS, 404). This matches the Apple client's
isLegacyNotFound rule so both clients reach the same verdict.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…efresh

Both server-list view models await AuthRepository.switchToServer behind a
spinner. It ran refreshActiveServerName, which awaits the contract probe
plus the branding and health requests, so a saved server that accepts
the TCP connection but never answers held the spinner for the full
client timeouts (about 72 s).

switchToServer now switches the registry and token scope, awaits only
the contract probe bounded by the same 3 s used on the launch path
(recording V2/UPDATE_REQUIRED, leaving UNKNOWN alone), and launches the
display-name refresh on an injected process-lifetime backgroundScope
without awaiting it. The scope is optional; without one the name
refresh runs inline after the probe (single-server hosts, tests). The
active-id guard still drops a late name for a server that is no longer
active.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
listProgress promises the full progress list, but the cursor walk
stopped at PROGRESS_MAX_PAGES and returned ApiResult.Success with only
the prefix, so continue-watching consumers treated older entries as
absent without any signal.

The page size stays at the server maximum (200). PROGRESS_MAX_PAGES is
now a runaway guard only (100 pages, 20,000 entries): reaching it with
has_more still true returns ApiResult.Error(code = 0,
error = "progress_incomplete") instead of Success. The function now
documents that the result is complete or an error.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
185d1e0 made the probe accept only Go's exact "404 page not found" text, so
the two pairing tests that mocked a bare "not found" started recording
UNKNOWN instead of UPDATE_REQUIRED. Mock the real legacy body.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The server pilot branch constrained the profile PIN schema (contract digest
moved) and bound listProgress cursors to the viewer's access policy
(list_progress_ok.json carries a new next_cursor). SOURCE now pins
c9e5a4e376f919a90e76aa8408892ba925d5661e.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 909e509fda

ℹ️ 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".

Quick104 and others added 3 commits September 4, 2026 21:56
… lifts

When an upgraded server still holds a stored UPDATE_REQUIRED verdict and
the launch probe outlasts its 3 s bound, MainTvActivity routes on the
stale verdict and the background refresh records V2 afterwards. The TV
profile picker called getCurrentUser() exactly once in loadProfiles(),
so the gated admin lookup failed locally and the admin lost the
profile-management controls for the ViewModel's lifetime.

Mirror the phone ProfileSelectionViewModel: collect
activeServerContractFlow in init and re-run loadProfiles() only when the
verdict moves from UPDATE_REQUIRED to V2. The initial emission is
skipped, so a fresh V2 or UNKNOWN start does not double-load.

TvProfileSelectionViewModelContractTest proves a V2 verdict arriving
after an UPDATE_REQUIRED first load re-triggers the load and lets the
v2 admin lookup reach the network.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…time

After a successful replaceAccountSession the pairing port awaited
refreshServerContract() unbounded. The client request and socket
timeouts are ~60 s while the companion waits only 30 s for
PairingMessage.ServerResult, so a stalled /api/v2/system/info made the
phone report failure after the credentials were already committed.

Add AuthRepository.refreshServerContractBounded(timeoutMs = 3_000L) as
the single home for the probe bound, and route switchToServer,
awaitContractRefreshIfUpdateRequired, and both PairingAuthPort probe
sites (success and rollback) through it. A timeout leaves the verdict
UNKNOWN, which passes the gate and is re-probed on the next switch or
launch.

RegistryPairingAuthPortTest gains
successfulPairingReportsSignedInWhenTheProbeNeverAnswers: a MockEngine
that suspends until cancelled still lets the port return within the
bound on runTest's virtual clock, with the session intact and no verdict
recorded. The two existing probe-counting tests now run the port on a
real-clock dispatcher, because under the test scheduler the new
virtual-time bound fires before the engine thread can answer.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…imes out

switchToServer bounds the contract probe to SWITCH_PROBE_TIMEOUT_MS so the
switch spinner stays responsive. When the target entry held a stale
UPDATE_REQUIRED verdict and /api/v2/system/info answered after that bound,
withTimeoutOrNull cancelled the only contract refresh; the background task
afterwards refreshed just the display name, so the gate kept rejecting v2
calls for the switched session until the next launch even though the
upgraded server would have answered moments later.

Keep the switch bounded, but when the bounded probe returns null and a
backgroundScope is wired in, launch a replacement unbounded probe (the
client's own timeouts still apply) pinned to the target serverId. The
existing active-id guard in recordServerContract drops the result if the
user switched again meanwhile. Without a scope (tests, single-server
hosts) behavior is unchanged. The launch path in MainActivity and
MainTvActivity already follows awaitContractRefreshIfUpdateRequired with
a fire-and-forget refreshActiveServerName(knownContract = null) that runs
a full unbounded probe, so it needs no replacement.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

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

ℹ️ 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".

refreshServerContractBounded mapped a transient probe Failure (connection
error, 5xx) to the non-null ServerContract.UNKNOWN. refreshServerContract
correctly recorded nothing for it, but both callers read any non-null
result as "verdict obtained": the launch path passed knownContract =
UNKNOWN into refreshActiveServerName, which then skipped its own probe,
and switchToServer skipped its background replacement probe. With a
stored UPDATE_REQUIRED and a server briefly unreachable at launch or
switch, the gate kept rejecting pilot calls for the whole session.

Make "no verdict" uniform: the bounded probe now returns null unless the
probe produced a real V2 or UPDATE_REQUIRED verdict, so a failure is
handled exactly like a timeout. The launch path (MainActivity,
MainTvActivity) already falls back to refreshActiveServerName(null),
which re-probes unbounded on lifecycleScope; switchToServer now launches
its background replacement for failures too. recordServerContract keeps
ignoring UNKNOWN. PairingAuthPort discards the return value and needs no
change.

Tests cover a 503 answer returning null and switchToServer's replacement
recording V2 once the server recovers, a connection failure on the launch
guard returning null, and real V2 / UPDATE_REQUIRED answers still
returning their verdict without a replacement probe.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 4991683bf6

ℹ️ 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".

Quick104 and others added 3 commits September 4, 2026 22:44
…talls

Both pairing probe sites (the newly paired server and the rollback
restore) awaited refreshServerContractBounded() and discarded the
result, so a timeout or transient failure while re-pairing a server
that carried a stale UPDATE_REQUIRED left the session gated with no
replacement probe — unlike switchToServer, which already handed the
retry to the background scope.

Extract that "bounded probe, then background replacement on no
verdict" step into AuthRepository.refreshServerContractWithFallback
(serverId) and use it from switchToServer and both pairing sites, so
every path that activates a server shares one fallback.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…failed

The connect path mapped a transient candidate-probe Failure through
toServerContract() into a non-null UNKNOWN and passed that to
setServerUrl once /api/v2/system/setup succeeded. refreshActiveServerName
neither records UNKNOWN nor re-probes when handed a known contract, so a
stale UPDATE_REQUIRED on the registry entry survived a successful v2
connection and kept gating the session.

A successful v2 setup answer is proof of v2 on its own, so both setup
view models now pass CONTRACT_PROVEN_BY_V2_RESPONSE (ServerContract.V2)
on the success path and keep the probe only for the UpdateServer early
return. The shared value is documented in AuthRepository.kt so the
reasoning lives next to toServerContract().

Co-Authored-By: Claude Fable 5.1 <[email protected]>
probeServerContract ran the candidate probe unbounded, so a server that
accepted the socket but stalled held the setup spinner for the client's
~60 s timeout per candidate (HTTPS then HTTP for a bare host) before
the setup call waited again.

Bound it with withTimeoutOrNull(SWITCH_PROBE_TIMEOUT_MS) behind a
timeoutMs parameter. A timeout returns null, which the connect path
already treats as "no verdict"; getSetupStatus carries the client's own
timeout and decides reachability, so no second bound is added there.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 062739ff06

ℹ️ 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".

Quick104 and others added 3 commits September 4, 2026 23:03
On the first launch after upgrading the app, restored server entries
carry ServerContract.UNKNOWN, which passes ApiV2Gate. Authenticated
startup consumers (getCurrentUser and friends) then raced the background
probe and could receive raw v2 404s from a saved v1-only server before
UPDATE_REQUIRED was recorded; those one-shot loads do not retry.

Generalize awaitContractRefreshIfUpdateRequired into
awaitContractRefreshIfUnsettled: only a stored V2 skips the bounded
wait; UNKNOWN and UPDATE_REQUIRED both probe before routing. Both
activities keep passing the result as knownContract to the
fire-and-forget refreshActiveServerName, so a null (V2, timeout, or
failure) still re-probes off the critical path. No other callers used
the old name, so it is renamed rather than aliased.

Tests: UNKNOWN awaits and records UPDATE_REQUIRED from a v1-only
server; UNKNOWN awaits and records V2; V2 returns null with zero
requests; existing UPDATE_REQUIRED cases unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Removing the ACTIVE server on the phone promotes the next-MRU entry
inside the registry, and ServerListViewModel.onRemove re-probed it via
refreshActiveServerName in viewModelScope. Popping the server list
cancels that scope, so the promoted entry could keep UNKNOWN or a stale
UPDATE_REQUIRED for the rest of the session.

Route the promotion through AuthRepository.switchToServer(promotedId)
like the TV client already does. The registry already points at the
promoted id, so the switch is idempotent there:
EncryptedTokenManagerImpl.switchActiveServer returns early when the id
is unchanged (no credential-epoch bump, no cache reload), and the
bounded probe hands its replacement to the repository's process-lifetime
backgroundScope with the display-name refresh off the critical path.

Test: promoted server re-probe survives cancellation of the calling
scope (AuthRepositoryContractTest).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The server pilot branch paginated listAdminUsers, declared the statuses the
listener really emits, relaxed the profile quality/subtitle enums, and bound
listProgress cursors to the library-restriction flag (contract digest and
list_progress_ok.json next_cursor moved). SOURCE now pins
7bd3af1430962a8b6662510caffe49e2954c4055.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

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

ℹ️ 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".

listProgress let every page's client.get resolve the active auth scope
afresh, so a server or profile switch mid-walk sent later pages under a
different identity while `entries` kept the earlier pages. The server
binds the cursor to user + profile and answers 400 invalid_cursor, so
mixed results could not surface today, but the walk relied on that
server behavior and reported a confusing cursor error.

The walk now captures one AuthScopeSnapshot up front (or takes an
explicit `scope`, mirroring addFavorite/syncProgress) and pins every
page request with authScope(), so SiloAuthPlugin sends the same server,
profile, and credential slot on each page. Before each later page the
captured scope is compared with the live one via the new
AuthScopeSnapshot.isSameIdentityAs (extracted from
ProfileRepository.identityScopeUnchanged); a generation or epoch change
aborts with ApiResult.Error(error = "identity_changed") instead of
continuing. PersonalDataApi now takes the TokenManager from Koin; the
default null keeps single-scope test constructions unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

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

ℹ️ 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".

…ncel it

refreshServerContractWithFallback awaited the bounded probe in the caller's
coroutine and only then launched the unbounded replacement on
backgroundScope. A server-list viewModelScope cancelled by Back during the
bound propagated CancellationException out of the bounded call, so the
replacement never started and the switched-to server stayed UNKNOWN or a
stale UPDATE_REQUIRED for the session.

With a backgroundScope and probe wired in, the whole bounded-then-unbounded
sequence now runs in a job launched on backgroundScope before the caller
waits; the caller only awaits the bounded verdict through a
CompletableDeferred under its own withTimeoutOrNull. Cancelling the caller
cancels that await, not the probe. The active-id guard stays inside the
background job, and recordServerContract still drops verdicts for a server
that is no longer active. Without a scope the inline behavior is unchanged.

Tests cover a caller cancelled mid-bound whose late answer is still
recorded, and a caller cancelled with the server switched meanwhile that
records nothing. Three existing tests moved their background scope to a
real-clock dispatcher because the probe no longer runs in the caller.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 51fea49e09

ℹ️ 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".

Quick104 and others added 2 commits September 5, 2026 00:00
CI run 33942933256 failed `switchToServer re-probes in the background
when the bounded probe fails` at the runTest line. 51fea49 moved the
bounded probe and its fallback onto backgroundScope before the caller
awaits, but this test still built the background scope on a
StandardTestDispatcher(testScheduler) while the caller waited under
Dispatchers.Default. runTest kept advancing the shared scheduler while
the body was suspended, so the 503 -> null -> replacement-probe chain
raced the caller's real-clock 3 s bound and the later joinChildren() and
request-count assertions; it passed locally and failed in CI.

Put the background scope on Dispatchers.Default, matching the three
sibling switch tests already converted in 51fea49, and keep the
CompletableDeferred gate so only the background replacement can record
V2. The remaining StandardTestDispatcher tests (timeout re-probe, the
cancellation tests, stale-result drop) run the caller on the virtual
clock too and need it to elapse the bound deterministically, so they
stay as they are.

Verified: 10 consecutive `:shared:testDebugUnitTest --tests
"*AuthRepositoryContractTest*" --rerun` runs pass; full
`:shared:testDebugUnitTest` and `*RegistryPairingAuthPort*` pass.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
switchToServer ran registry.switchTo and tokenManager.switchActiveServer
in the caller's coroutine and only handed the probe to backgroundScope
afterwards. A server-list viewModelScope cancelled while either
persistence call was in flight could leave the new server persisted as
active with no probe handoff, so its entry stayed UNKNOWN or stale
UPDATE_REQUIRED for the session.

With a backgroundScope wired in, the whole activation (registry switch,
token switch, bounded probe, replacement probe, display-name refresh)
now runs as one job there, started before the caller waits. The caller
awaits a CompletableDeferred completed after the bounded verdict, so it
still returns within SWITCH_PROBE_TIMEOUT_MS when the probe hangs and
never awaits the display-name refresh; cancelling the caller cancels
only that await, and a scope torn down mid-activation releases it. The
no-scope path is unchanged. The probe-then-fallback sequence moves into
probeContractWithFallback so switchToServer and the pairing path's
refreshServerContractWithFallback share it.

Adds a real-clock test that gates the registry fake's switchTo, cancels
the caller while suspended there, releases the gate, and asserts the
token switch, probe, and V2 record still complete.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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: 29515e00db

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma program (epic silo-server#135) stacked Stacked on another open PR or branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant