Repository navigation
Description
What this is
Parent/executor issue for converging the desktop chat/agent runtime onto kernel truth. It binds together #9658 (agent runtime contracts, output handling, adapter conformance — the core architecture), #9342 (production symptom: AI not available: bridge failed to start), #8461 (Swift tool registration split-brain), #9033 (non-hermetic local agent provider detection), and #9680 (cross-surface context + prompt-cache contracts), and adds the Swift-side hardening none of them specifies: a shadow-state census of ChatProvider.swift / AgentRuntimeProcess.swift, a bridge-lifecycle sequence fuzzer, extraction gates, and anti-regrowth guards.
An agent should be able to execute from this issue alone: read the children for their locked designs, follow the phases here, and open one PR whose body contains Closes #9658, Closes #9342, Closes #8461, Closes #9033, Closes #9680, and Closes this issue.
Sequencing dependency: the PTT stability PR (branch sync/ptt-stability-ux, follow-up to #9660) lands first. This work reuses its rebuild-from-kernel restore seam, cross-language fixture pattern, and anti-regrowth guard conventions. Do not fork parallel variants of those mechanisms — extend them.
Why: the recurring failure classes
Churn since 2026-04-01: ChatProvider.swift 122 commits (5,960 lines), AgentRuntimeProcess.swift 71 commits (3,961 lines). The same classes recur; every work item maps to one — if you cut an item, name the class it leaves open.
| Class | Example evidence | What allowed it |
|---|---|---|
| A. Swift shadow state diverging from kernel truth | 3d5123c215 (fence convergence effects across owner transitions), 447a891cec (close convergence authority races), a3470ae480 (make restart journal recovery deterministic) |
ChatProvider/AgentRuntimeProcess keep local copies of run/turn/session facts the Node kernel owns; every owner transition needs hand-written fencing |
| B. Bridge process lifecycle orderings | 3f50c85a01 (post-crash restart path), dfc4b3f14c (mode-switch timeout lock, WAL stop frame retention), 607ff6a471 (bound mode-switch wait), #9342 (bridge fails to start — 122 events/19 users in 24h on beta) |
Crash/restart/mode-switch/WAL-replay interleavings are handled ad hoc; no stated lifecycle state machine, no fuzzing |
| C. Contract drift across language/adapter boundaries | #9658's 620 KB list_agent_sessions closing the Gemini voice socket; #8461's tool present in one adapter path and absent in another; #9033's detector ignoring injected environment |
Contracts implicit in call sites; no schemas, no shared fixtures, no conformance suite |
| D. Cross-surface divergence (typed chat vs PTT) | 85a58a29f4 (enforce cross-surface agent contracts), #9680's context truncation + divergent system guidance + unproduced cache sentinel |
Two surfaces independently derive context/policy from the same journal with no shared contract |
Rules of engagement (binding for the whole PR)
- A test that would not have caught one of the evidence items above is decoration. Name the commit/issue or class each new test would have caught.
- Never add a second copy of kernel truth. Swift remembers something the kernel knows → query it or extend the PTT plan's restore seam; never a new stored property that must be fenced.
- Extraction means hermetic testability. An extracted type's tests must not construct
ChatProviderorAgentRuntimeProcess; if it needs closures mutating provider state, it has been relocated, not extracted. Decision cores extract as pure functions; I/O stays put. - Behavior changes and code moves never share a commit.
- Contracts are schemas + fixtures, not prose. Per [P1] Standardize Omi agent runtime contracts, output handling, and adapter conformance #9658: language-neutral schema or shared versioned fixtures consumed by both Node and Swift tests, gated in
desktop/macos/scripts/agent-logic-harness.shand registered in.github/checks-manifest.yaml(both lanes). Follow the PTT plan's spawn-receipt fixture conventions (semantic JSON comparison, immutable versioned fixture dirs, malformed cases included). - No new sleeps; drive deadlines via injected events. Fallback/degraded branches call
DesktopDiagnosticsManager.shared.recordFallback(DesktopDiagnosticsManager.swift~line 380) — never a new emitter or PTT/chat-only event. - Invariant citations are path-based. This PR touches
ChatProvider.swift→ citeINV-AUTH-1; it strengthens the agent control plane → cite that invariant and update its guard test if behavior changes. Runscripts/pr-preflight --suggestfor the complete ID list; do not hand-pick.
Execution phases (one PR, commits strictly in this order)
Phase 1 — census + contracts lock (closes the discovery half of C)
- Shadow-state census of
ChatProvider.swiftandAgentRuntimeProcess.swift: every stored property recording run/turn/session/bridge facts, classified (a) pure cache rebuildable from kernel, (b) genuinely local (in-flight tasks, process handles), (c) shadow truth. Census table goes in the PR body. Bucket (c) members move behind the PTT restore seam or become write-through projections. - Bridge lifecycle state machine made explicit: name the states (stopped, starting, running, mode-switching, draining, crashed, restarting) and legal transitions currently implicit in
AgentRuntimeProcess. Pure decision core extracted; process I/O stays. - Bridge-lifecycle sequence fuzzer: seeded PRNG over the event alphabet {spawn, spawn-failure, crash, restart, mode-switch request, WAL frame, WAL stop frame, timeout, kill, kernel journal write}. Invariants: exactly one live bridge mode at a time; no frame applied after stop; restart never replays settled turns; a start failure always terminates in a user-visible failed state (this is the macOS beta chat errors: agent bridge fails to start #9342 class — "bridge failed to start" must be a typed terminal state with recovery, not a dead end). Failing sequences check in as named regression tests.
- Contract schemas + fixtures for the [P1] Standardize Omi agent runtime contracts, output handling, and adapter conformance #9658 contract list (
ContextSnapshot,ToolInvocation/ToolResultEnvelope,PermissionDecision, session/run/attempt/turn lifecycle, failure taxonomy) — shared fixtures consumed by Node and Swift test suites per rule 5. Include a size-budget test for session listings (the 620 KB regression class): responses carry references, not persisted run input.
Phase 2 — converge the split brains (closes C and #8461, #9033)
- One canonical tool manifest (per Unify Swift-backed Omi tool registration across agent runtimes #8461): single source of truth the Swift executor, stdio path, pi-mono extension, and
/v1/local/toolsall derive from; a conformance test that fails when any surface advertises a tool another lacks. Delete the per-path declarations. - Hermetic provider detection (per LocalAgentProviderDetector not hermetic — ignores injected PATH/home (OpenClaw discovery) #9033):
LocalAgentProviderDetectorhonors injectedPATH/home fully; the existing failing test becomes the regression proof. Missing-adapter surfaces as the existingsetupNeededStatus, never an opaque spawn failure. - Adapter conformance suite per [P1] Standardize Omi agent runtime contracts, output handling, and adapter conformance #9658: each adapter (pi/ACP/OpenClaw/Hermes, Gemini/OpenAI realtime) passes the same lifecycle/failure-taxonomy/output-budget fixtures.
Phase 3 — cross-surface context + root-cause #9342 (closes D, B symptoms)
- Execute Desktop: unify shared conversation context and prompt-cache contracts across PTT and chat #9680: declared truncation/older-history handoff contract for
context-snapshot.ts; one shared semantic-guidance path for typed chat and PTT; produce the<<<OMI_CACHE_SPLIT_V1>>>sentinel from the desktop client or delete it (decide; don't leave the dead contract); cache-plan identity + replacement-session cache telemetry. - Root-cause macOS beta chat errors: agent bridge fails to start #9342 with the Phase 1 state machine in hand: reproduce the beta start-failure path, fix the underlying cause, and verify the typed failed-start state renders with recovery guidance. Post the PostHog before/after query in the PR body.
Anti-regrowth guards (mandatory, registered in .github/checks-manifest.yaml)
Following the PTT plan's two-guard pattern (desktop/macos/scripts/check-hub-controller-ratchet.py conventions): (1) a boundary guard — extracted decision-core type names must not reappear in ChatProvider.swift/AgentRuntimeProcess.swift; (2) a line-count ratchet on both files, baseline = post-PR count + 10% headroom, with the raise-and-justify escape hatch. Both are static tripwires — label them as such, with self-test fixtures.
Phase gates
If Phase 1's census or fuzzer exposes a behavior change requiring ownership redesign beyond #9658's locked architecture, stop and surface it here before Phase 2. Phase 3 starts only after conformance suites are green.
Verification (cite evidence in the PR body)
cd desktop/macos && xcrun swift build -c debug --package-path Desktop, full suite via./scripts/swift-test-suites.sh; Node runtime tests for the kernel side;./scripts/agent-logic-harness.sh --cross-surface-smokeafter each phase.make preflightwith the new manifest checks green;scripts/pr-preflight --suggestoutput cited in full.- Named-bundle end-to-end pass (
OMI_APP_NAME="omi-agent-contracts" ./run.sh): typed chat turn, PTT turn sharing context, tool call through each adapter path, forced bridge crash → visible recovery, missing-adapter →setupNeededStatus. - Changelog fragment in
desktop/macos/changelog/unreleased/(user-visible: bridge failure recovery UX). - PR body: census table, fuzzer corpus + run counts, per-child closure checklist, failure-class table as recurrence evidence, root cause + durable guard per class.
Closure criteria
- [P1] Standardize Omi agent runtime contracts, output handling, and adapter conformance #9658: contracts exist as schemas/fixtures with conformance suites all adapters pass; kernel owns lifecycle/idempotency/failure taxonomy; Swift surfaces are projections (census bucket (c) emptied).
- macOS beta chat errors: agent bridge fails to start #9342: root cause fixed; start failure is a typed, recoverable, user-visible state; beta error rate verified down in PostHog.
- Unify Swift-backed Omi tool registration across agent runtimes #8461: one tool manifest, conformance test, per-path declarations deleted.
- LocalAgentProviderDetector not hermetic — ignores injected PATH/home (OpenClaw discovery) #9033: detector fully honors injected environment; the named test passes on a machine with OpenClaw installed.
- Desktop: unify shared conversation context and prompt-cache contracts across PTT and chat #9680: declared context/truncation contract, unified guidance path, cache sentinel produced or deleted, cache telemetry live.
- This issue: all five children closed by the single PR; census, fuzzer, guards, and manifest entries verified in CI.
Explicitly out of scope
- Voice-turn/PTT ownership internals — owned by the PTT stability PR; this work consumes its seams.
- Windows agent delegation (Windows desktop: delegate tasks to coding agents (Claude Code, OpenClaw, Hermes, Codex) via ACP #9302), agent coordinator expansion (Deferred agent coordinator expansion after Desktop paradigm lands #8652), Tasks epic (Epic: Rebuild Omi Tasks around quiet capture, focused goals, persistent workstreams, and contextual action #9352).
- APIClient/data-access-layer convergence (park(macOS): no-increase ratchet for direct APIClient call sites (~102 Source files) #9527, [desktop/macos] APIClient.swift is a 5,750-line god actor with hand-duplicated server models #8844) and global-state audit ([desktop/macos] Global state: 107 singletons, 476 raw UserDefaults accesses, 62 inline string keys #8845) — same disease, separate treatment.
Related
Parent of: #9658, #9342, #8461, #9033, #9680. Depends on: PTT stability PR (post-#9660). Playbook precedent: #9515, #9516.
Activity
fix(macos): converge agent runtime contracts (#9698)
fix(desktop): adapt spawn-receipt fixtures to tool-result envelopes
fix(desktop): give the runtime refusal its own owner, not the coordin…