Skip to content

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

Closed
Git-on-my-level wants to merge 8 commits into
task/msd-spine-a-api-resultfrom
task/msd-core-c3-typed-result
Closed

Git-on-my-level wants to merge 8 commits into
task/msd-spine-a-api-resultfrom
task/msd-core-c3-typed-result

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 17, 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

Git-on-my-level and others added 2 commits September 18, 2026 03:37
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]>
Git-on-my-level and others added 4 commits September 18, 2026 07:48
…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]>
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]>
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.
Forward the three-way C3 split so this published child still fast-forwards from the contract branch.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Typed ApiResult conversation list/detail migration, no abuse signal (mergeStateStatus UNKNOWN, not eligible to merge anyway); approve-only per standing account flag.

@Git-on-my-level
Git-on-my-level deleted the branch task/msd-spine-a-api-result September 18, 2026 16:43
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Auto-closed when base branch was deleted after the parent squash-merged. Head unchanged at 5fb1a835a; continued as #14600 targeting main.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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.

2 participants