Skip to content

fix(desktop): crash on duplicate ids in task/apps/chat data (#6506) - #9288

Merged
kodjima33 merged 2 commits into
mainfrom
watchdog/issue-6506-duplicate-id-crash
Jul 9, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
watchdog/issue-6506-duplicate-id-crash

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

Issue #6506 reported a hard crash (EXC_BREAKPOINT / assertion failure) when opening the Plan and Usage settings pane. The crash report bottoms out in _NativeDictionary.merge(uniquingKeysWith:) from SettingsContentView.mergePlanCatalog — i.e. building a dictionary with Dictionary(uniqueKeysWithValues:) / merge(...) that traps when a key appears twice.

That specific pane was already refactored to a safe merger (SubscriptionPlanCatalogMerger, with a regression test). But the same crash class — a trapping Dictionary(uniqueKeysWithValues:) over an ($0.id, $0) map of server/collection data — still exists in three sibling desktop paths, any of which crashes the app if the source contains a duplicate id:

  • TasksStore.mergeWithoutAdding — task reconciliation (local sync/reconciliation races can produce duplicate task ids)
  • AppProvider — v1/apps ratings/enabled enrichment (marketplace apps list)
  • ChatProvider — agent-run artifact projections

The codebase already acknowledges the API returns duplicate ids and uses the safe uniquingKeysWith: { _, latest in latest } variant in TasksPage, TaskDeduplicationService, AppState, and ConversationDetailView — these three sites simply missed it.

Fix

Switch all three to the established last-write-wins pattern (Dictionary(_, uniquingKeysWith:)). No behavior change for the normal (unique-id) case; duplicates now dedupe instead of crashing.

TasksStore.mergeWithoutAdding is extracted as a pure static func so it is unit-testable.

Verification

  • xcrun swift build -c debug --package-path Desktop → Build complete! (only pre-existing warnings)
  • New regression test TasksStoreMergeWithoutAddingTests (duplicate-id source → no crash, last-write-wins) → passed. This test traps/crashes against the old code.
  • Unit-level verification only (mirrors the existing Desktop: Crash when accessing Plan and Usage settings pane. #6506 SubscriptionPlanCatalogMergerTests approach); I did not reproduce a duplicate-id server response through the live UI.

🤖 automated by hourly watchdog; opened for review, not merged.

Review in cubic

kodjima33 added 2 commits July 8, 2026 19:09
TasksStore.mergeWithoutAdding built its lookup with
Dictionary(uniqueKeysWithValues:), which traps and crashes the app when
the source list contains a duplicate task id (local sync/reconciliation
races). Switch to last-write-wins, matching the safe pattern already used
in TasksPage/TaskDeduplicationService. Extract the pure merge as a static
so it is unit-testable, and add a regression test.

Same crash class as #6506 (SettingsContentView plan-catalog merge).
…icate ids

Same crash class as #6506: AppProvider (v1/apps ratings enrichment) and
ChatProvider (agent-run artifact projections) built id-keyed lookups with
Dictionary(uniqueKeysWithValues:), which traps on a duplicate key returned
by the API/coordinator. Use last-write-wins instead.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You’re at about 92% 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].

Re-trigger cubic

@kodjima33
kodjima33 merged commit 3e4305b into main Jul 9, 2026
16 of 17 checks passed
@kodjima33
kodjima33 deleted the watchdog/issue-6506-duplicate-id-crash branch July 9, 2026 04:06
Git-on-my-level added a commit that referenced this pull request Jul 11, 2026
## What changed and why

Recent macOS and backend bug-fix PRs were clustering around the same
missing contracts: re-entrant desktop state publication, duplicate
external IDs, hidden blocking work, runtime/deploy drift,
released-client schema breaks, and selective CI that could silently miss
tests. This replaces those one-off repairs with shared policies,
behavioral harnesses, compatibility checks, and fail-closed CI
selection.

The main durable changes are:

- FIFO/non-reentrant voice-turn dispatch, explicit last-write-wins
collection construction, duplicate-input tests, and a desktop
test-quality ratchet for trapping dictionaries, source-inspection debt,
and wall-clock waits.
- A pure prerecorded-STT provider contract shared by runtime selection
and deploy validation, lazy/thread-safe Deepgram construction,
controlled configuration failures, and complete dev/prod desired-state
bindings.
- Directional app-client OpenAPI compatibility checking against the
merge base, plus transitive module-local async-blocker analysis.
- One rename/delete/type-aware changed-path primitive, conservative
backend test selection, dedicated import-isolation gates, and complete
desktop agent Vitest discovery.
- Agent/PR guidance that requires a bug fix to close the failure class,
not only its current symptom. The evidence and guard hierarchy are
recorded in `docs/operational/systemic_bug_hardening.md`.

## Product invariants affected

- `INV-CHAT-1`: floating-control-bar, PTT, task-chat, and `ChatProvider`
paths are touched. The shared-transcript/session ownership model is
unchanged; the PTT coordinator now publishes transitions atomically
under nested callbacks.
- `INV-AUTH-1`: `ChatProvider.swift` is touched only to adopt
deterministic duplicate-key handling. Session invalidation and auth
recovery behavior are unchanged.
- `INV-INT-1`: `MemoryExportService.swift` is touched only to replace a
trapping dictionary constructor with the shared duplicate-key policy.
Integration ownership and capability behavior are unchanged.
- `INV-MEM-1`: the same `MemoryExportService.swift` mechanical migration
does not change memory tiers, canonical storage, or read/write routing.

## How it was verified

- `cd desktop/macos && OMI_SWIFT_TEST_SUITE_WORKERS=4
./scripts/swift-test-suites.sh` — all 219 Swift suites passed; the
desktop quality checker and its 11 fixture tests passed. Its
source-inspection ratchet is pinned to current-main debt (62 files / 171
sites) and permits no increase from this PR.
- `cd desktop/macos && rm -rf Desktop/.build && xcrun swift build -c
release --package-path Desktop --triple arm64-apple-macosx` — clean
arm64 release build passed.
- Built and launched `/Applications/omi-systemic-guards.app` with ad-hoc
signing. Exercised the real PTT semantic actions through idle →
recording → terminal-too-short; automation state reported zero invalid
and zero stale transitions.
- `cd backend && bash test.sh` — the complete selector-discovered suite
of 525 backend test files passed under file isolation and the strict
local CPU guard.
- `cd backend && PATH=/tmp/omi-python-bin:$PATH bash
scripts/pre-deploy-check.sh` — dev/prod runtime contracts and 50
deploy-safety tests passed.
- Import-purity scan: 637 production files, zero violations. Module-stub
pollution scan: 580 test files, zero violations. All-category async diff
scan: zero selected findings.
- App-client OpenAPI compatibility passed against current `origin/main`
(`2a14a9ee78153ac353afc2d5e43ffa328650a6f6`); all 19 checker tests
passed.
- `bash backend/scripts/typecheck.sh` — zero type errors.
- `scripts/pre-push` — all commit-aware local gates passed, including
OpenAPI/model freshness, actionlint, desktop suites, and the complete
desktop agent tool surface.
- Independent agent review found four test/wiring gaps; each was fixed
and the final review approved the updated tree.

No production deploy was performed. `backend/deploy/runtime_env.yaml`
changes checked-in desired state and will take effect only through the
normal deployment workflows.

## Tests

- `VoiceTurnCoordinatorTests` now reproduces nested effect/snapshot
callbacks and proves FIFO publication without recursion.
- `DictionaryDeduplicationTests` proves the shared collision policy; the
static checker rejects future trapping initializers and unreasoned
escapes.
- `test_prerecorded_stt_config.py`, provider tests, and
runtime-validator tests cover dynamic selectors, missing dependencies,
BYOK, fallback requirements, and dev/prod surfaces.
- `test_app_client_openapi_compatibility.py` covers request/response
directionality, status/media/security changes, enums, arrays, maps,
unions, constraints, and recursive references.
- `test_scan_async_blockers.py` covers transitive helpers, cycles, diff
scope, and safe executor offload.
- Workflow/path tests cover unknown sources, mixed direct+unmapped
changes, deleted tests, both rename sides, file-to-symlink type changes,
hook fallback, and full agent test discovery.

## Root cause and durable guard (bug fixes)

- Desktop lifecycle chain (`#9402`, `#9411`, `#9420`, `#9424`, `#9428`):
synchronous callbacks could advance a half-published transition. The
coordinator now owns a non-reentrant event queue, backed by
reducer-level behavior tests.
- Duplicate-ID crash class (`#9288` and adjacent sites): boundary data
was incorrectly assumed unique. A named collision policy replaces every
trapping production constructor, and CI rejects recurrence.
- Runtime/provider drift (`#9296`, `#9308`, `#9358`, `#9385`, `#9421`,
`#9422`): runtime choice and deploy dependencies had separate owners.
One pure provider contract now drives both, with lazy client
construction preserving import purity.
- Released-client break (`#9425`): schema freshness alone did not prove
compatibility. CI now compares contracts in the direction requests and
responses actually flow.
- False-green test selection: rename/deletion/type changes and unknown
production sources could escape intended gates, while the desktop agent
harness ran only a hand-picked subset. Selection now fails toward
broader coverage and discovers the complete suite.

## Scoped cleanups (optional)

- The backend test runner now caps nested BLAS/OpenMP pools per isolated
pytest worker, preventing oversubscription from corrupting per-test CPU
attribution while preserving explicit overrides.
- Runtime workflow validation reuses the already-parsed manifest instead
of reparsing it once per workflow.
Git-on-my-level added a commit that referenced this pull request Jul 16, 2026
## Summary\n\n- add a semantic, JSON failure-class registry plus an
offline scripts/failure-class CLI for agent-oriented preparation,
explanation, validation, and advisory reporting\n- surface the same
failure-class guidance with product-invariant suggestions through
scripts/pr-preflight --suggest, before a PR exists\n- keep PR-body
checks in local/PR preflight while excluding them from metadata-less
post-merge main pushes\n- enforce PR-body declarations for reactive fix:
commits through the existing preflight manifest, while distinguishing
proactive harden: work\n- add manifest-backed recurrence ratchets for
naive Python datetime sort sentinels and unsafe macOS Swift dictionary
construction\n- replace repetitive existing-class narratives with a
validated declaration, require real-incident citations for new guards,
and defer locked invariants until seven stable days\n- extract the X
connector transport and DTOs from APIClient.swift into its connector
feature, reducing the client from 6,502 to 6,430 lines without changing
endpoint behavior\n\nCloses #9822\n\n## Failure class
(fixes)\n\nFailure-Class: none\n\n## New guards\n\nThe datetime ratchet
cites #9571 and #9600; the desktop dictionary ratchet cites #6506 and
#9288. These are static checks because the canonical safe primitives
already exist, while the prohibited patterns can be reintroduced
independently at multiple call sites.\n\n## Product invariants
affected\n\n- INV-AUTH-1 — the authenticated transport implementation is
unchanged; this moves its X connector extension only.\n- INV-INT-1 — the
X connector endpoints and DTOs are now co-located with their
connector-import feature; behavior is unchanged.\n\n## Verification\n\n-
python3 scripts/test_failure_class.py — 13 passed\n- python3
.github/scripts/test_pr_preflight.py — 10 passed\n- python3
.github/scripts/test_run_checks.py — 13 passed\n- focused backend
ratchet tests — 6 passed\n-
BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-backend-unit-failures.txt bash
backend/test.sh — 9 passed\n- bash backend/test.sh — 631-file
CI-equivalent suite passed\n- xcrun swift test --package-path Desktop
--filter ConnectorImportOperationsTests — 13 passed\n- xcrun swift build
-c debug --package-path Desktop — passed\n- python3
desktop/macos/scripts/check_desktop_test_quality.py — passed\n-
desktop-core-harness self-check — passed with the repository virtualenv
and Node 22 runtime\n- scripts/pr-preflight — passed (26 checks)\n- make
preflight — passed\n\n
@undivisible undivisible added the AI label Aug 10, 2026
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…ware#9841)

## Summary\n\n- add a semantic, JSON failure-class registry plus an
offline scripts/failure-class CLI for agent-oriented preparation,
explanation, validation, and advisory reporting\n- surface the same
failure-class guidance with product-invariant suggestions through
scripts/pr-preflight --suggest, before a PR exists\n- keep PR-body
checks in local/PR preflight while excluding them from metadata-less
post-merge main pushes\n- enforce PR-body declarations for reactive fix:
commits through the existing preflight manifest, while distinguishing
proactive harden: work\n- add manifest-backed recurrence ratchets for
naive Python datetime sort sentinels and unsafe macOS Swift dictionary
construction\n- replace repetitive existing-class narratives with a
validated declaration, require real-incident citations for new guards,
and defer locked invariants until seven stable days\n- extract the X
connector transport and DTOs from APIClient.swift into its connector
feature, reducing the client from 6,502 to 6,430 lines without changing
endpoint behavior\n\nCloses BasedHardware#9822\n\n## Failure class
(fixes)\n\nFailure-Class: none\n\n## New guards\n\nThe datetime ratchet
cites BasedHardware#9571 and BasedHardware#9600; the desktop dictionary ratchet cites BasedHardware#6506 and
BasedHardware#9288. These are static checks because the canonical safe primitives
already exist, while the prohibited patterns can be reintroduced
independently at multiple call sites.\n\n## Product invariants
affected\n\n- INV-AUTH-1 — the authenticated transport implementation is
unchanged; this moves its X connector extension only.\n- INV-INT-1 — the
X connector endpoints and DTOs are now co-located with their
connector-import feature; behavior is unchanged.\n\n## Verification\n\n-
python3 scripts/test_failure_class.py — 13 passed\n- python3
.github/scripts/test_pr_preflight.py — 10 passed\n- python3
.github/scripts/test_run_checks.py — 13 passed\n- focused backend
ratchet tests — 6 passed\n-
BACKEND_UNIT_TEST_FILE_LIST=/tmp/omi-backend-unit-failures.txt bash
backend/test.sh — 9 passed\n- bash backend/test.sh — 631-file
CI-equivalent suite passed\n- xcrun swift test --package-path Desktop
--filter ConnectorImportOperationsTests — 13 passed\n- xcrun swift build
-c debug --package-path Desktop — passed\n- python3
desktop/macos/scripts/check_desktop_test_quality.py — passed\n-
desktop-core-harness self-check — passed with the repository virtualenv
and Node 22 runtime\n- scripts/pr-preflight — passed (26 checks)\n- make
preflight — passed\n\n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants