Skip to content

feat(app): add typed ApiResult and migrate the conversation list and detail - #14600

Merged
Git-on-my-level merged 43 commits into
mainfrom
task/msd-core-c3-typed-result
Sep 18, 2026
Merged

Git-on-my-level merged 43 commits into
mainfrom
task/msd-core-c3-typed-result

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Summary

C3 PR1: typed ApiResult<T> never null, one shared uncaught send, conversation list/detail as the first migrated file, old and new coexisting. Stacked on task/msd-spine-a-api-result (#14328). Branch task/msd-core-c3-typed-result. Not pushed.

This closes the HTTP subset where makeApiCall returning null made an outage indistinguishable from an empty account, and where getConversationById returned null identically for transport failure, 403, 503, and a missing row. 402 and 422 now have terminal kinds with no retry loop.

What changed and why

  1. ApiResult<T> — ApiSuccess(data, rejectedRows) or ApiFailure(ApiProblem), never null. Taxonomy matches app/lib/backend/http/API_RESULTS.md. Programming errors (StateError, NoSuchMethodError) propagate from executeApi; only FormatException inside decoding becomes decode.
  2. Shared send extraction. sendUncaughtApiCall is the old makeApiCall try-body (headers, pool, timeouts, clock skew, 401 replay). makeApiCall is now the null-wrapping catch only. executeApi defaults to that uncaught path. It does not wrap nullable makeApiCall and guess why it failed. The send seam is already-authenticated I/O; execution injects transport + header builder + AuthService into the same production request path with no global defaults.
  3. Auth preserved, not reinvented. refreshAndReplayAfter401 gained onAuthRefresh so executeApi can see the observed AuthTokenResult. A transient refresh that returns the original 401 is authTransient, not collapsed into authTerminal.
  4. One API file. ConversationApi.list / byId live in app/lib/backend/http/api/conversations.dart next to the legacy functions. Why this file: the note's evidence is conversation-detail conflation (getConversationById → null for 403, 503, and missing) plus list empty-vs-outage (cfaaaf2fb9db, 06597a0757cb). All 28 existing makeApiCall call sites in that file stay. getConversationById / getConversations stay. Production ConversationProvider() without conversationApi is unchanged.
  5. Consumers the contract required. composeTypedConversationProvider returns the real ConversationProvider. apiViewState, ConversationApiStatus (keys omi.conversations.error/.locked/.terminal/.auth/.empty, retry only when retryable, error is a Semantics liveRegion) precedes the empty hero on ConversationsPage. 402/422 on typed detail leave Processing and do not poll.

Widget tests drive getInitialConversations inside runAsync (as the spine test already does). ConversationsPage(requestInitialLoad: false) is a test-harness-only constructor defaulting to true in production, so initState does not queue failNext on the fake-async clock where loopback I/O never completes. The page still mounts for real, and still uses the production status-before-hero branch.

Product invariants affected

none (scripts/pr-preflight --suggest)

How it was verified

  • TZ=UTC bash app/test.sh then TZ=UTC flutter test: 2137 tests, all passed.
  • python3 scripts/check_spine_contracts.py: pass. One remaining C3 marker (see below). 29 pending markers repo-wide (rest are V1).
  • make preflight: 21 checks passed in 62.45s. No harness-port flake this run.
  • dart format --line-length 120 on the production/test files we own. Spine tests were restored to contract-branch originals then had markers removed only.
  • make lane-bootstrap (this worktree had no venv) then make mobile-verify ARGS="fast --paths …": outcome passed, 20/20.

Could not run: physical device. Production ConversationProvider() without conversationApi still uses makeApiCall (intentional coexistence).

Tests

  • Spine app/test/spine/c3_*: markers retired except one (below). Assertions untouched.
  • app/test/unit/backend/http/api_send_extraction_test.dart: sendUncaughtApiCall throws; makeApiCall returns null on the same failure. 402/422: one send, retryable == false, decode not called.
  • Widget acceptance mounts the real ConversationsPage via buildTypedConversationScreen. Outage is ApiViewPhase.error + omi.conversations.error, not EmptyConversationsWidget. Recovery after outage=false is empty. 402/422 leave Processing with one GET and no retry on a 2-minute pump.

Self-check: 28 makeApiCall callers

rg -c makeApiCall app/lib/backend/http/api/conversations.dart → 28. None of those sites were migrated. git diff of shared.dart: the uncaught body is the previous makeApiCall try-block; makeApiCall now only calls sendUncaughtApiCall and applies the same AuthTokenUnavailableException / catch → null policy. makeApiCall never passes execution or onAuthRefresh, so those seams cannot change legacy behavior. Extraction test proves throw vs null wrap, not a source-string assertion. TZ=UTC flutter test includes the existing conversation provider/HTTP suites that still go through makeApiCall.

Self-check: 402 / 422 terminal, no retry, never uploaded

executeApi maps 402 → paymentRequired, 422 → unprocessable, both retryable == false, one send, decode not invoked (api_send_extraction_test throws if decode runs). Typed detail refreshTypedDetail removes the row from processingConversations and does not schedule a timer. Spine pumps 2 minutes and asserts still one GET. WAL upload is not on this file; we did not add a 402/422 success path that could mark a recording uploaded.

Self-check: injected outage renders error, not empty list

Spine c3_conversation_test uses JourneyFixtureBackend.failNext(..., status: 503) (the journeys' fixture_backend.dart). Status widget and the real ConversationsPage both show omi.conversations.error and not EmptyConversationsWidget / omi.conversations.empty. Retry / forceRefresh after the fault is cleared renders empty.

Pending marker kept on purpose

C3 fallback emitter uses shared closed fields and one event still has pendingContract('C3'). The implementation emits the exact closed fields (component/area=other, from/to=none, reason=other, outcome=degraded, event fallback_triggered). Dart Record.== uses Map.==, which is identity, so expect(emitted, [(name, map)]) cannot pass even when the maps are key-for-key equal. I did not rewrite the spine assertion (markers only). Architect: changing that expect to expect(emitted.single.$1, 'fallback_triggered'); expect(emitted.single.$2, map); would let DeepCollectionEquality apply to the map and we can retire the marker.

Failure class (fixes)

Not declared. This commit is feat(app): (new typed surface + first exemplar). scripts/pr-preflight --suggest said no fix: commit was detected. Ask before defining a failure class — if you want this labelled as a fix: instance of outage-as-empty / detail-null-conflation, say which FC-* (or new) to use and I will add the declaration in a follow-up commit.

Scoped notes

  • Did not redesign HTTP client, auth, or caching. Streaming/multipart makeApiCall siblings in shared.dart are untouched.
  • Did not touch contracts/**.
  • Did not migrate the other 27 makeApiCall sites in conversations.dart. C4 can batch those.
  • Dead-code ratchet noted the four HTTP skeleton files are now reachable; allowlist cleanup is a separate follow-up if desired.

🤖 Generated with Claude Code

Failure class (fixes)

Failure-Class: none

This is a new typed surface plus its first exemplar migration rather than a fix of a specific
instance, so the commit is feat(app): and scripts/pr-preflight --suggest detected no fix:
commit. The defect class it exists to close — an outage rendering as an empty account, and
getConversationById returning null identically for transport failure, 403, 503 and a missing
row — is the contract C3 itself records.

🤖 Generated with Claude Code

Review in cubic

Line-Count-Exception: app/lib/providers/conversation_provider.dart | 1750 -> 1858 | typed ApiResult migration: the conversation detail/list state machine moves from ad-hoc http calls to the typed executeApi/decodeApiRows pipeline with explicit error and retry states; the +108 lines are the migration itself. Split deferred until the C3 chain completes.

Product invariants affected

INV-DATA-1 — the typed ApiResult migration keeps production-family routing continuity: the conversation list/detail still resolve through the same production data plane, now with explicit error/retry states instead of ad-hoc calls.

Git-on-my-level and others added 30 commits September 17, 2026 13:42
Add strict Python/Dart pending contracts and introducing-commit protection.
Reserve the live-session CLI, wire, ownership/attachment seams and failing
builder acceptance tests. Add live attribution before freezing evidence v1.

Verification:
- bash scripts/dev-harness/run-tests.sh: 287 passed, 7 existing skips,
  40 strict xfailed (24 pending V1 markers), Python 3.11.15.
- make preflight: 16 checks passed, using supported PYTHON selection.
- make mobile-verify fast --paths harness/session contract inputs with an
  absolute evidence directory: 20 executed, 20 passed, no failures/skips.
- bash app/test.sh: 2014 passed, 5 skipped, one unchanged UTC+7
  search_rank_grouping_test failure; affected baseline inputs match main.
- Real module CLI refusals exit 2 without traceback; regression covered.
- Dart SDK probe proves ext. prefix required; marker-removal formatter
  probe proves no incidental Dart diff.

Runtime is intentionally unimplemented. App UI must repair current invalid
VM extension names before live acceptance; unsupported journeys block.
Simulator/emulator latency and detached-process acceptance remain V1 work.
make setup installed hooks but full backend wheel sync stalled; isolated
Python 3.11 harness dependencies ran the owner checks without any skip flag.

Failure-Class: none
The check protects files under the spine roots and their registry, so it only
needs to run when those change. A repo-wide trigger would run it, and its
full-history requirement, on every unrelated contributor PR.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
V1 must refuse live journey execution until a shared executable adapter exists;
B1 addressability alone cannot attach Dart integration tests. Pure admission
contracts remain valid with injected supported IDs.

Verification: harness 287 passed, 7 skipped, 40 strict xfailed;
make preflight passed 20 checks.
Preserve auth results and existing endpoint protections while defining typed failures, partial row decoding, terminal locked/rejected states and bounded fallback telemetry. Verified UTC app (2058 passed), harness (287 passed, 7 skipped, 40 strict xfailed), 20 hermetic journeys and 21 preflight checks. Skeletons remain unreachable.
…lities

Coordinator turn-4 review authorizes the V1 fixture correction. Exact before/after digests pin the revised oracle; immutable revision records do not permit builder assertion edits. Active tests reject missing/tampered records and prove the fake machine response. Verification: full harness 289 passed, 7 skipped, 40 strict xfailed; UTC app 2020 passed; spine 24 pending/7 protected; make preflight 16 passed. No live device acceptance claimed.
Track retained marker occurrences rather than counts so retiring a second test cannot restore the first test's retired marker. The active regression covers this swap and legitimate continued retirement. Verification: full harness 290 passed, 7 skipped, 40 strict xfailed; spine 24 pending/7 protected; make preflight 16 passed. Dart sources unchanged after the earlier UTC app 2020-pass run.
…rges

A squash can introduce a corrected contract and its review records in the same commit. Absorb only the revision prefix ending at that introducing file's exact digest, preserving immutable records and later marker-only edits. Active temp-repo regression covers multiple corrections in one squash and rejects restoring old or altered assertions. Verification: harness 291 passed, 7 skipped, 40 strict xfailed; B1 make preflight 20 passed; final B1 journeys 20/20. Dart unchanged after UTC app 41 opt-in and 2051 ordinary passed.
…i-result

# Conflicts:
#	scripts/dev-harness/PENDING_CONTRACTS.md
Use the actual PR base and immutable exact scaffolding snapshots to reject mixed revision/implementation diffs. Exercise a real squash and child merge. Correct local_dev wire spelling from the simulator RPC and add adversarial V1 conformance oracles after reviewing the first broker.

Verification: UTC app 2064 passed; full harness 303 passed, 7 skipped, 55 strict xfailed; spine 37 pending/9 protected; preflight 16 checks passed. Isolated reviewed-broker probes failed 9/9 as documented in the conformance report. No real app/device launch.
Resolve spine registry and checks manifest as a union without changing owners or assertions. Keep the widget-contract guidance and main's hermetic runner guards. UTC app: 2135 passed. Harness: 308 passed, 7 skipped, 44 xfailed. Spine: 43 pending, 14 protected; final PR-scoped preflight follows the merge.
…ge orders

Keep exact oracle digests and immutable revision records. Traverse full reachable history and match revision payloads by digest. Shared runner metadata requires direct fail-fast suite invocation instead of pinning shared file bytes. Both new regressions fail on the old checker. UTC app 2064 passed; final harness 306 passed, 7 skipped, 59 strict xfailed; spine 39 pending/10 protected; preflight 16 passed. No protected oracle bytes or legacy scope pins changed.
makeApiCall still returns null for the 28 existing conversations.dart callers;
ConversationApi is the first path where 403, 503, and a missing row are distinct,
and an injected outage renders error instead of the empty hero.

Co-authored-by: Cursor <[email protected]>
…istory

Rejected mixed proposals can be reverted without losing exact oracle protection. Scope is checked over the whole proposal; exact retired renderings require an immutable reviewed digest.\n\nVerified: full harness 309 passed, 7 skipped, 59 strict xfailed; Dart 2064 passed; spine check clean; make preflight 16 checks passed. Real chat tree 9f5548474f passes against its addressability contract target.
Preserve all eleven pending markers and the executable AST. Exact retired digests cover the builder's already-introduced unused-import cleanup without granting general edit permission. Full harness and preflight pass; AST evidence is recorded in .local/t11-v1-format-evidence.json.
Retain every generator instruction beside the existing table and free 180 bytes for the queued contract pointers. Do not change the guide budget. make preflight passed all 16 checks.
Resolve the registry as an owner-preserving union and retain widget runner guidance alongside the collection equality rule. Verified with C3 correction in the working tree: Dart 2135 passed; harness 316 passed, 7 skipped, 59 strict xfailed; preflight 21 checks passed.
Dart Record equality compares Map identity. Revision 017 keeps the pending marker and exact closed fields while checking cardinality, event name and Map separately. Flutter matcher reproduction: 3 passed; Dart owner suite: 2135 passed; harness: 316 passed, 7 skipped, 59 strict xfailed; preflight: 21 passed.
…d-result

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	contracts/spine/files.json
#	scripts/dev-harness/PENDING_CONTRACTS.md
The remote tip carried a merge of an older origin/main; this branch already
contains current origin/main plus 20 commits. Merged to restore a
fast-forward path without rewriting published history.

Co-Authored-By: Claude Opus 5 <[email protected]>
Retain both main's singleton testing guidance and C3's HTTP contract pointer; preserve widget and record-equality guidance. app/AGENTS.md measures 11316 bytes against the unchanged 11411 budget. Harness: 335 passed, 7 skipped, 59 strict xfailed.
Git-on-my-level and others added 11 commits September 18, 2026 09:50
Take the spine PENDING_CONTRACTS wording from #14328, including the
Map-identity expect rule, and retire the C3 fallback-map pending marker
now that recordFallback is implemented.

Co-authored-by: Cursor <[email protected]>
…ook like an empty account

main.dart and hermetic boot now call createProductionConversationProvider, which always constructs ConversationApi. An unused import would satisfy the dead-code ratchet; the new test asserts the live call site and that a 503 on that factory-built provider renders the error surface on ConversationsPage.

Co-authored-by: Cursor <[email protected]>
Six conflicts. Resolutions, and why each side rather than the other:

- .github/checks-manifest.yaml: rebuilt from MAIN's text, then re-inserted this
  branch's api-result-boundaries block, so no edit of main's can be lost by
  construction. Two shared ids differed: product-invariants took main's, which is
  #14465's three-dot-from-base fix, and mobile-boundary-check-tests took the
  UNION of triggers, since main watches app/contracts/capture/** and this branch
  watches app/contracts/**/boundary-baseline.json and both are wanted. 226 unique
  ids.
- contracts/spine/files.json: union to 33. Main has 17 C1 oracle entries, this
  branch 6 C3 ones, no key claimed by both with different content.
- .github/scripts/dead_code/flutter.allowlist.json: union to 11 entries — this
  branch's four api_* files plus main's three capture_* files.
- scripts/test_check_mobile_boundaries.py (add/add): took ours, verified a strict
  superset of main's (zero lines present only on main's side).
- app/AGENTS.md: union of the pointer rows. Each side deliberately deleted one
  base line; honoured both deletions and both additions. 11309 of 11411.
- docs/doc/developer/Contribution.mdx: aligned with main. This branch carries
  four spine revision records, and check_spine_contracts.py refuses a revision
  record riding with non-oracle paths, so the contributor-docs hunk cannot travel
  on it. Same call as on #14371.

Co-Authored-By: Claude Opus 5 <[email protected]>
Split the four C3 revision records and the oracles they pin off #14328
so a revision no longer travels with flutter.allowlist.json.

Co-authored-by: Cursor <[email protected]>
The contract PR must not introduce a revision record of its own.
These records now come from task/msd-spine-c3-revisions.
Bring the C3 oracle-only revision split and the origin/main conflict resolutions forward so this published child still fast-forwards from the contract branch.
These four api_* files are unreachable from main.dart until the first consumer is wired, so the dead-code allowlist entries travel with the skeleton. No revision records, no spine tests.

Co-authored-by: Cursor <[email protected]>
Base the C3 oracle tests on the compiling skeleton so the revision records stay oracle-only against this parent.
Bring the compiling skeleton and oracle-only revision records in as the new base so this published contract branch no longer introduces either.
Forward the three-way C3 split so this published child still fast-forwards from the contract branch.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Merge-forward complete against main a1b379037. Registry files resolved via scripts/resolve-registry-conflict; app/AGENTS.md keeps main's C7 pointer row (superseded generic row dropped, ≤11411 bytes); lib files take this branch's evolved typed-ApiResult implementation; the 4 C3 spine files are main's versions with the 15 now-satisfied pendingContract('C3') markers retired (41 spine c3 tests green; api-result unit tests green). Audit: diff vs main is exactly this PR's 20 owned files. INV-DATA-1 cited in the body; Line-Count-Exception declared for conversation_provider (+108, the migration itself). New head: e99b7efa67.

1 similar comment
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Merge-forward complete against main a1b379037. Registry files resolved via scripts/resolve-registry-conflict; app/AGENTS.md keeps main's C7 pointer row (superseded generic row dropped, ≤11411 bytes); lib files take this branch's evolved typed-ApiResult implementation; the 4 C3 spine files are main's versions with the 15 now-satisfied pendingContract('C3') markers retired (41 spine c3 tests green; api-result unit tests green). Audit: diff vs main is exactly this PR's 20 owned files. INV-DATA-1 cited in the body; Line-Count-Exception declared for conversation_provider (+108, the migration itself). New head: e99b7efa67.

Add library directives to the two new doc-commented files, const the ApiFailure returns, and un-hide sendUncaughtApiCall from @VisibleForTesting — executeApi is a production entry point that must preserve the thrown cause, which the annotation wrongly flagged as test-only.
@Git-on-my-level
Git-on-my-level merged commit 93ca9d0 into main Sep 18, 2026
39 checks passed
@Git-on-my-level
Git-on-my-level deleted the task/msd-core-c3-typed-result branch September 18, 2026 20:31
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