Repository navigation
fix(app): handle 409 canonical state gracefully on knowledge graph rebuild (#20481) - #20744
Conversation
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 4/5
- In
knowledge_graph_api.dart, the 409 conflict message is never shown because the rebuild path returnscanonical_up_to_dateand onboarding exits silently. Wire the conflict message into the user-facing path.
You’re at about 99% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/backend/http/api/knowledge_graph_api.dart">
<violation number="1" location="app/lib/backend/http/api/knowledge_graph_api.dart:21">
P2: This new user-facing message is never surfaced for the 409 conflict it describes. The rebuild path returns `canonical_up_to_date` and onboarding silently exits, so the string is reachable only from the unit test; wire the message into the 409/UI path or remove the claimed user-facing behavior.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| final _ = (statusCode, body); | ||
| final _ = (body); | ||
| if (statusCode == 409) { | ||
| return 'Knowledge graph is up to date'; |
There was a problem hiding this comment.
P2: This new user-facing message is never surfaced for the 409 conflict it describes. The rebuild path returns canonical_up_to_date and onboarding silently exits, so the string is reachable only from the unit test; wire the message into the 409/UI path or remove the claimed user-facing behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At app/lib/backend/http/api/knowledge_graph_api.dart, line 21:
<comment>This new user-facing message is never surfaced for the 409 conflict it describes. The rebuild path returns `canonical_up_to_date` and onboarding silently exits, so the string is reachable only from the unit test; wire the message into the 409/UI path or remove the claimed user-facing behavior.</comment>
<file context>
@@ -16,7 +16,10 @@ class KnowledgeGraphApi {
- final _ = (statusCode, body);
+ final _ = (body);
+ if (statusCode == 409) {
+ return 'Knowledge graph is up to date';
+ }
return "Couldn't $action knowledge graph";
</file context>
There was a problem hiding this comment.
Resolved: removed the dead 409 user-facing branch in knowledgeGraphHttpUserMessage so all HTTP failures consistently share the sanitized generic error message without leaking response bodies. Also added hermetic unit test coverage asserting that rebuildKnowledgeGraph intercepts HTTP 409 and returns the canonical_up_to_date status.
|
Verified against the backend: POST /v1/knowledge-graph/rebuild raises 409 with CANONICAL_GRAPH_MUTATION_CONFLICT for accounts with established canonical graph state (backend/routers/knowledge_graph.py, _require_legacy_graph_mutation), and the success path returns status="rebuilding" — so treating 409 as a benign terminal state on the client is the right shape of fix for #20481. File-by-file:
Optional nit: the status == 'canonical' fallback in the onboarding early-return has no producer today (the backend returns "rebuilding" or 409) — harmless defensive check, but a comment or removal would help future readers. Clean, minimal, well-tested fix — thanks! The UX copy (presenting a protection conflict as "up to date") and the silent catch-all in onboarding are user-facing behavior choices worth a maintainer's eyes before merge, so leaving this for human maintainer review. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…build Handle HTTP 409 canonical graph conflict in rebuildKnowledgeGraph by returning an up to date status response. Prevent onboarding prebuild from stalling or throwing when an account has canonical memory assertions. Provide clean user-facing copy without exposing backend traces or error bodies. Include unit test coverage in knowledge_graph_error_message_test.dart. Failure-Class: none
…ging Document synthetic canonical_up_to_date client response on 409 conflict in rebuildKnowledgeGraph. Remove dead 409 branch in knowledgeGraphHttpUserMessage so all HTTP failures consistently use generic copy without leaking bodies. Simplify early return in onboarding wrapper by removing redundant status check. Update unit test to assert clean generic error message on 409 conflict. Failure-Class: none
…rebuild - Add hermetic unit test verifying rebuildKnowledgeGraph converts HTTP 409 to canonical_up_to_date. - Remove redundant inner try-catch in onboarding _prebuildKnowledgeGraph. - Update changelog fragment to accurately reflect onboarding rebuild behavior. Failure-Class: none
b57ee97 to
60c7dd1
Compare
|
Thanks for merging @kodjima33 @josancamon19! Following up on the resolution of P1 issue #20481 (handling the canonical 409 conflict gracefully during knowledge graph rebuild across mobile and backend): proposing a 00 bounty for this fix as per Omi contribution guidelines. PayPal: [email protected] |
…mmand capture for Windows/macOS (#20890) ## What changed and why UI-change PRs now require at least one tracked screenshot, enforced by the standard checks-manifest so it runs in both the local pre-push gate and CI Hygiene. Screenshots are siloed under `.agent-artifacts/ui-evidence/<pr-or-branch>/` with a strict contract (`<NNN>-<platform>-<slug>.png` + `evidence.json`), and two new one-command capture tools produce contract-compliant evidence for the Windows (Playwright E2E) and macOS (`screencapture`) desktop apps. Motivation: agents (and humans) landing UI changes had no enforced way to attach visual evidence, so reviewers reviewed rendered behavior blind. Requiring the artifact — without inspecting its content — makes visual review cheap and gives future agents in-repo context for the screens they touch. Contract (frozen across all three pieces): - Silo: `.agent-artifacts/ui-evidence/<pr-number-or-branch-slug>/` - Filename: `<NNN>-<platform>-<slug>.png` — NNN zero-padded 3-digit ordinal from `001`; platform ∈ `mobile-android|mobile-ios|desktop-macos|desktop-windows|web`; slug lowercase-kebab ≤40 chars - `evidence.json` beside the images: `{"version":1,"images":[{"file","platform","description","captured_by","source"}]}` (2-space indent, trailing newline) - Gate passes when the PR body references ≥1 tracked silo image, or carries the exact line `UI-Evidence: none` (optional ` -- reason`) - Pre-PR bootstrap works like the Failure-Class gate: `OMI_PR_BODY_FILE=/tmp/pr-body.md git push` Pieces: 1. `.github/scripts/check_ui_evidence.py` + 17 hermetic tests + `checks-manifest.yaml` entries (`ui-evidence` with `requires_pr_body: true` in both lanes, `ui-evidence-tests`) + PR-template section. Trigger globs: `app/lib/**/*.dart`, `desktop/macos/Desktop/Sources/**/*.swift`, `desktop/windows/src/**/*.{ts,tsx}`, `web/frontend/src/**`, `web/admin/app/**`. Deleted-only UI diffs don't trigger; added images under the silo are validated against the contract and their `evidence.json`. 2. `desktop/windows/scripts/capture-evidence.mjs` (+ `pnpm capture:evidence`, shared `e2e/helpers/capture-helpers.mjs`, 17 vitest tests): launches the built app exactly like `e2e/bar.spec.mjs`, writes the PNG and merges `evidence.json`. 3. `desktop/macos/scripts/capture-ui-evidence.sh` (+ hermetic `tests/test-capture-ui-evidence.sh`): `screencapture` full-screen or window-targeted via `ctypes` CGWindowList, Screen-Recording TCC remediation on failure, same contract write. ## Product invariants affected - none ## How it was verified All commands run on this branch (and re-run independently by the reviewer and coordinator): - `python3 .github/scripts/test_check_ui_evidence.py` — 17 tests OK - `cd desktop/windows && npx pnpm@10 exec vitest run scripts/capture-evidence.test.mjs` — 17/17 passed (hermetic, no Electron launch) - `bash desktop/macos/tests/test-capture-ui-evidence.sh` — pass (hermetic; never calls `screencapture`); `bash -n` and `shellcheck` clean - `scripts/pr-preflight --pr-body-file <body>` — CI lane dry run: `PR preflight passed: 15 checks` with `ui-evidence` + `ui-evidence-tests` selected - `python3 .github/scripts/run_checks.py --manifest .github/checks-manifest.yaml --lane ci --list` selects both new entries; local lane likewise - CLI fixtures: referenced tracked image → `OK` (exit 0); missing evidence → `FAIL: UI evidence` with full contract + remediation (exit 1) Real-path caveat, stated plainly: the two capture tools were validated hermetically plus launch-env parity review; no Electron app launch or real screen capture was performed in this lane (no Windows host / TCC prompt here). First real capture exercises the remaining path. ## Tests - Gate: `.github/scripts/test_check_ui_evidence.py` (17 cases: trigger classification incl. deleted-only, escape-line negatives, tracked-at-HEAD incl. directory/symlink rejection, filename/manifest validation, glob parity) - Windows: `desktop/windows/scripts/capture-evidence.test.mjs` (17 cases: filename validator, ordinal allocation, evidence.json merge/replace/v1 enforcement) - macOS: `desktop/macos/tests/test-capture-ui-evidence.sh` (bad platform/slug, NNN padding, merge preserves entries, replace-by-filename, contract write from fake PNG) ## Failure class (fixes) Failure-Class: none ## New guards (only when adding a check or ratchet) This check would have forced visual evidence onto recent UI PRs that landed without any in-repo artifact for reviewers: #20802 (flag-gated "Setting up your Omi" onboarding page) and #20744 (knowledge-graph rebuild UI fix). Not-a-shared-primitive answer: the checker IS the shared primitive — one contract + one validator consumed by both capture tools and both lanes; per-platform capture scripts are thin producers over the same frozen contract rather than N independent guard implementations. ## UI evidence UI-Evidence: none -- tooling-only change; the diff touches no product UI source (check/tests/manifest/template/capture scripts only), so there is no product screen to screenshot. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/20890?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/20890?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F20890&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
…22078) Mobile Mind Map can show an empty screen because the compatibility graph omits saved-memory catalog records and later canonical pages. Read the canonical catalog when the compatibility view is empty or owner-only, keep memories without relationships readable, and provide Refresh / Show More without attempting the rejected canonical rebuild. Existing nonempty compatibility/shared graphs remain visible, including the projection proposed in #12878. Canonical pages remain revision-fenced and session-bound. Stale cursors restart at page one, late refresh responses cannot replace newer data, label changes render, backend/session changes and rejected authorization clear old data, and failed ordinary refreshes preserve same-session content. Expired cursors discard the invalidated revision before retry, including if that retry fails. The canvas keeps a 200-entity bound and fitted small maps retain readable labels. Catalog records remain separate from graph entities and never create relationships. Onboarding skips the legacy mutation after a successful canonical read. Initial compatibility failures stop without a second expensive graph read; each read retains zero transport retries. The loopback regression fixture uses a stable backend override and the existing token-I/O seam so session fencing remains enabled. The backend adds an absence-only response header so a genuinely new account can show an empty state while an unreadable canonical revision remains a retryable failure. The existing HTTP status/body stay compatible. Refs #20481, #20463. Complements #20744; this PR is independent of #12878's broader macOS/account-wide rebuild work. It does not assert that affected accounts have eligible Long-term memories or that missing assertions/data have been repaired. ## Validation - Canonical backend service/FastAPI route suite: 17 passed. - Final focused Flutter HTTP/error/widget/layout suites: 49 passed, including real loopback HTTP gateway retry bounds, authorization/backend changes, stale cursor restart failure, label refresh, viewport fitting and bounded large pages. - Visual audit passed: empty, saved-memory catalog, and later-page graph states. Inspected captures; recovered graphs now fit the viewport with readable, separated labels. - Focused analyzer reported no errors/warnings (pre-existing informational lints remain). - App-client schema inventory: 13 passed; explicit endpoint URLs retain contract discovery while requests stay pinned to their backend. - Normal pre-push gate passed without skip flags on `2d70dcd229`: all 41 shared preflight checks, backend typecheck (0 errors), runtime-image source closure, selected backend tests, OpenAPI compatibility, generated Dart/Swift/TypeScript models, Flutter build_runner and Dart formatting. The [final Mobile App Checks run](https://github.com/BasedHardware/omi/actions/runs/39102810940) passed, including the analyzer ratchet, regular Flutter suite, generated files and Mobile Release Eligibility. Native compile/emulator and seeded-journey jobs were not selected for this Dart-only diff; physical-device/store verification remains pending. Commands: `cd app && flutter test --no-pub test/unit/http_pool_manager_retry_test.dart test/unit/knowledge_graph_read_test.dart test/unit/knowledge_graph_error_message_test.dart test/widgets/memory_graph_empty_state_test.dart test/widgets/memory_graph_fit_to_bounds_test.dart`; `cd backend && .venv/bin/python -m pytest tests/unit/test_knowledge_graph_canonical_pagination.py -q` (includes the FastAPI request path) and separately `tests/unit/test_app_client_schema_inventory.py -q`. Focused `flutter analyze --no-pub --no-fatal-infos` covered the changed API, graph/catalog widgets, identity helper and tests. The [backend CI run](https://github.com/BasedHardware/omi/actions/runs/39102810914) passed five unit shards and the slow guardrails on its first attempt. Shard 1 passed its assertions but hit an unrelated CPU timing guard (`test_capture_evidence_admission.py`: 1.03s against 1.00s); all four tests in that file also passed locally under the unchanged 1.00s limit. Only failed jobs were retried on the same commit, with no budget or allowlist changes. ## Release and customer verification Merge, deploy the backend absence header first, then release iOS and Android. Retest on physical phones with affected accounts: open Mind Map, verify saved memories or relationships, load more, refresh/reopen, and confirm onboarding no longer attempts a canonical rebuild. If still empty, privately check memory eligibility, processing and assertion state. No customer account or production records were accessed. Public store release evidence checked 2026-10-18: [App Store iOS 1.0.558+ notes](https://apps.apple.com/us/app/omi-smart-meeting-notes/id6502156163) and [Google Play notes (updated October 15)](https://play.google.com/store/apps/details?id=com.friend.ios&hl=en_US) both explicitly list the canonical knowledge-graph 409 onboarding fix from #20744. This supports public release on both platforms. The exact Android binary/source SHA and rollout coverage have not been verified through Codemagic; the available login has no Omi workspace access. Release of that error handling does not establish that an affected account has a populated map. ## Product invariants affected - INV-MEM-1: existing memory tiers and eligibility remain unchanged. - INV-MEM-4: read-only client recovery; no new promotion or graph mutation authority. Failure-Class: FC-derived-state-gate-without-legacy-source-path The canonical presence/absence probe must preserve the compatibility path for unprovisioned accounts while rejecting unreadable state as empty. Backend route and mobile HTTP/widget tests guard both sides. ## UI evidence   
Onboarding still treated a failed Mind Map read as an empty legacy account and sent a rebuild POST. This could turn a canonical read outage, invalid response or replaced account session into an unnecessary/rejected mutation. The optional prebuild now stops on read failure; the normal map view retains its read/retry path. The orchestration moves from the widget to `KnowledgeGraphApi.prebuildForOnboarding`, which uses the existing production reader, rebuild and polling owners. Successful canonical reads and populated compatibility maps never rebuild. A positively absent canonical account can still use legacy rebuild; 409 remains terminal and a queued legacy rebuild retains bounded stability polling. No server guard, memory promotion, storage, auth policy or wire schema changes. Refs #20481. The issue discussion by julio23jaz-dotcom also identified this catch-and-rebuild path. Builds on merged #20744 and #22078; #12878 is closed unmerged and is not a dependency. This finishes the reproduced failed-read onboarding gap, not a claim about every affected account's current graph. ## Verification - Six regressions fail after a behavior-preserving extraction of the original catch-and-rebuild method; seven successful/legacy scenarios still pass. With the fix, all 13 pass through the real HTTP client against loopback (synthetic responses and the existing local auth gateway; no live identity provider). - Focused graph/API/widget/identity suite: 88 passed. - Analyzer ratchet: passed. Direct analysis reports only the existing `avoid_print` in unchanged stability polling; no new diagnostic. - Final diff reviewed; all 27 local manifest checks and the bounded pre-push gate passed. The local history-dependent 90-day class ratchet explicitly skipped on the shallow checkout; CI runs with full history. Exact-head CI remains pending; stays draft. - `make mobile-verify ARGS="fast --paths app/lib/backend/http/api/knowledge_graph_api.dart app/lib/pages/onboarding/wrapper.dart"`: both selected hermetic journeys passed (9 checks; source `43866f9f0032844e08902aa01f41ce390cc6ef14`, clean). The loopback flow exercises the entire changed orchestration boundary, including parsing, read failures, account replacement, no-write outcomes, terminal conflict and successful legacy polling. No UI layout, native or hardware behavior changes; no physical-device test is needed for this boundary. ## Failure class Failure-Class: new `FC-failed-probe-permits-mutating-recovery`: a failed probe was caught and reinterpreted as permission to mutate. Why isn't this a shared primitive instead? It is: the API owner now holds the prebuild flow, and its loopback contract tests are the reusable prevention artifact rather than a widget-specific source check. ## Release and customer follow-up Merge and release the mobile update on iOS/Android. No additional backend deployment is required for this incremental fix. Existing canonical-read backend support from #22078 remains required and was previously verified deployed. Keep support tracking open until the affected users confirm their map loads and remains available after refresh/reopen on the released build. No customer data, assignment, deployment or account mutation was performed. UI-Evidence: none The widget only delegates its existing optional background request; no visible control or layout changes. ## Product invariants affected none; canonical read/mutation and promotion authority are preserved (INV-MEM-1, INV-MEM-4).
Summary
Handle HTTP 409 Conflict (
CANONICAL_GRAPH_MUTATION_CONFLICT) gracefully inKnowledgeGraphApi.rebuildKnowledgeGraph().When an account has established canonical memory graph state, the backend rejects legacy graph mutations and returns HTTP 409. In the onboarding prebuild path (
wrapper.dart),rebuildKnowledgeGraph()is called when no graph exists.Changes
KnowledgeGraphApi.rebuildKnowledgeGraph(), intercept HTTP 409 and return a syntheticcanonical_up_to_datestatus response instead of throwing an unhandled exception._prebuildKnowledgeGraph(), recognizecanonical_up_to_dateand exit early so onboarding does not poll for a background job that was never queued.rebuildKnowledgeGraph()converts HTTP 409 tocanonical_up_to_date, parses HTTP 200, and throws sanitized error messages on HTTP 500 without leaking backend internals.Verification
flutter test test/unit/knowledge_graph_error_message_test.dart(5/5 passed)scripts/pr-preflight --pr-body-file draft_pr_body.mdFailure class (fixes)
Failure-Class: none
Product invariants affected
none