Skip to content

Epic: agent runtime contract convergence — kernel-truth Swift bridge, adapter conformance, cross-surface context (parent of #9658, #9342, #8461, #9033, #9680) #9688

Closed

Description

@Git-on-my-level

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)

  1. 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.
  2. 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.
  3. Extraction means hermetic testability. An extracted type's tests must not construct ChatProvider or AgentRuntimeProcess; if it needs closures mutating provider state, it has been relocated, not extracted. Decision cores extract as pure functions; I/O stays put.
  4. Behavior changes and code moves never share a commit.
  5. 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.sh and 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).
  6. 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.
  7. Invariant citations are path-based. This PR touches ChatProvider.swift → cite INV-AUTH-1; it strengthens the agent control plane → cite that invariant and update its guard test if behavior changes. Run scripts/pr-preflight --suggest for 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)

  1. Shadow-state census of ChatProvider.swift and AgentRuntimeProcess.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.
  2. 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.
  3. 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.
  4. 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)

  1. 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/tools all derive from; a conformance test that fails when any surface advertises a tool another lacks. Delete the per-path declarations.
  2. Hermetic provider detection (per LocalAgentProviderDetector not hermetic — ignores injected PATH/home (OpenClaw discovery) #9033): LocalAgentProviderDetector honors injected PATH/home fully; the existing failing test becomes the regression proof. Missing-adapter surfaces as the existing setupNeededStatus, never an opaque spawn failure.
  3. 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)

  1. 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.
  2. 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)

  1. 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-smoke after each phase.
  2. make preflight with the new manifest checks green; scripts/pr-preflight --suggest output cited in full.
  3. 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.
  4. Changelog fragment in desktop/macos/changelog/unreleased/ (user-visible: bridge failure recovery UX).
  5. 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

Explicitly out of scope

Related

Parent of: #9658, #9342, #8461, #9033, #9680. Depends on: PTT stability PR (post-#9660). Playbook precedent: #9515, #9516.

Activity

  1. added 2 commits that reference this issue on Jul 14, 2026
    fff4eef
    7c8e66f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions