Skip to content

fix(desktop): keep managed agents on cloud routing - #9402

Merged
Git-on-my-level merged 5 commits into
BasedHardware:mainfrom
Git-on-my-level:codex/fix-agent-auth-recovery
Jul 10, 2026
Merged

Git-on-my-level merged 5 commits into
BasedHardware:mainfrom
Git-on-my-level:codex/fix-agent-auth-recovery

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Managed background and delegated agents inherit the Omi cloud route and reject every local adapter override (ACP, Hermes, or OpenClaw).
  • Background agents are leaf workers: prompt context prohibits nested spawning, runtime control tools reject it, and a failed required control operation fails the parent instead of misleadingly showing Done.
  • Explicit User Claude OAuth is adapter-scoped, opens at most once per attempt, accepts only validated Claude PKCE loopback URLs, and unlocks a new browser launch after a fresh retry URL.
  • A 90-second per-tool guard interrupts stalled turns before the 180-second whole-chat watchdog.

Root cause

Background control paths defaulted omitted adapters to local ACP even though the desktop was in managed piMono mode. The initial guard only covered ACP, leaving equivalent local Hermes/OpenClaw overrides available in other control paths. Separately, a background-agent smoke test could report a green parent completion after its nested spawn had failed at the tool relay.

Guardrails

  • Managed routing has no implicit or explicit local-provider fallback; unknown adapters fail closed.
  • Local adapters remain usable only from a desktop surface that explicitly selected that local mode.
  • Floating-pill, delegated, and background sessions are leaf workers.
  • Failed required child-control operations become terminal parent failures unless a later control retry succeeds.
  • OAuth browser launches require the expected Claude PKCE loopback authorization URL.

Product invariants affected

  • INV-AUTH-1 — ChatProvider's User Claude recovery remains scoped to an explicit local-provider flow; managed-provider 401s never invalidate the Omi Firebase session.
  • INV-CHAT-1 — The shared kernel transcript remains authoritative; failed required control operations now terminate the shared run rather than creating a false-success projection.
  • INV-AGENT-* — Control-tool authority and run lifecycle remain kernel-owned; managed routes fail closed and required control-operation failures are terminal.

Validation

  • npm run build
  • Focused managed-routing, local-ACP-rejection, leaf-worker, parent-failure, and retry tests
  • ./scripts/agent-logic-harness.sh --node-only --skip-install (agent runtime focused tests plus 103 exact pi-mono-extension tests)
  • xcrun swift test --package-path Desktop --filter ChatProviderOAuthURLTests|StallDetectorTests|ChatStallWatchdogTests (25 passing)
  • python3 desktop/macos/scripts/check-e2e-flow-coverage.py --strict --base origin/main
  • Named bundle /Applications/omi-agent-auth-recovery.app smoke test completed on pi-mono, with no ACP launch or 401.

Note

The broad agent TypeScript suite still has seven unrelated existing failures in migration/event-ordering and pi-mono concurrency cases; targeted coverage and the harness pass.

Background and delegated agents now inherit the active managed adapter and reject local Claude ACP outside User Claude mode. Kernel recovery covers every run entry point, explicit Claude OAuth opens automatically with a bounded callback, and a 90-second tool-stall guard interrupts stuck pi-mono turns before the 180-second chat watchdog.

Validation: npm run build; focused control-tools tests; agent-logic-harness.sh --node-only --skip-install; xcrun swift test --package-path Desktop --filter StallDetectorTests|ChatStallWatchdogTests; named-bundle smoke agent completed with adapter_id=pi-mono.
@Git-on-my-level Git-on-my-level changed the title fix(desktop): recover expired agent credentials fix(desktop): keep managed agents on cloud routing Jul 10, 2026
Background and delegated workers now receive an explicit leaf-worker boundary and control tools reject nested agent creation. Validation: focused control-tools and turn-context tests; npm run build; agent-logic-harness.sh --node-only --skip-install.
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review July 10, 2026 20:49
@Git-on-my-level
Git-on-my-level merged commit 35e6d34 into BasedHardware:main Jul 10, 2026
18 checks passed
Git-on-my-level added a commit that referenced this pull request Jul 10, 2026
## What changed and why

Closes #9408.

Adds one fast PR-contract engine shared by local development and GitHub
Hygiene. It selects checks from the exact base/head diff, validates
current PR metadata, and reports per-phase timings and remediation.
Hygiene now fetches the current PR body through the GitHub API,
including on body edits and reruns.

Pre-push execution is now single-flight per worktree and exact input
fingerprint. Identical concurrent pushes join one run; different input
fails with the active PID, phase, and stable log path. Hook-owned child
process groups and locks are cleaned up without touching unrelated Git
or app processes.

The fast contract path remains separate from expensive builds and tests.
On this 11-file PR it completed in 0.43 seconds.

## Product invariants affected

none

## How it was verified

- `python3 .github/scripts/test_pr_preflight.py` — 6 tests passed,
including a PR #9402-equivalent missing-invariant/missing-flow fixture
and two-process single-flight coverage.
- `python3 .github/scripts/test_check_product_invariants.py` — 14 tests
passed.
- `python3 .github/scripts/test_check_brand_ui.py` — 6 tests passed.
- `actionlint -shellcheck '' .github/workflows/repo-checks.yml` —
passed.
- `scripts/pr-preflight --pr-body-file .github/PULL_REQUEST_TEMPLATE.md`
— 4 selected contract checks passed in 0.43 seconds after the final
rebase.
- Live GitHub API check against PR #9402 — loaded the current body and
`updated_at`, then passed the selected contract checks in 0.99 seconds.
- `.github/scripts/run-pre-push.sh` and the real `git push` hook —
passed workflow contracts, OpenAPI generation, backend type checking,
Swift debug build, Rust `cargo check`, ratchets, and formatting checks.
Stable phase/status/log artifacts were inspected during the run.

## Tests

Regression coverage lives in `.github/scripts/test_pr_preflight.py`. It
covers current-body parsing/provenance, deterministic check selection,
the original #9402 failure modes, identical-run joining, different-input
rejection, result propagation, and observable state/log files.

## Scoped cleanups (optional)

None.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9410?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>
<!-- End of auto-generated description by cubic. -->
Git-on-my-level added a commit that referenced this pull request Jul 10, 2026
## Summary

- make adapter credential scope declarative in the production adapter
registry and persist each session's provider boundary
- persist coordinator/leaf execution roles, project agent-management
tools out of leaf runtimes, and retain relay/kernel denial for stale or
forged calls
- fail closed for every managed control entry point against local or
unknown adapters, while pinning local-user sessions to their exact
selected provider
- track required control retries by logical operation so unrelated
success cannot erase a failed obligation
- document the durable control-plane invariants and add the session
execution-policy migration

## Design

Sessions now carry two kernel-owned fields:

- `providerBoundary`: `managed_cloud` or `local_user:<adapter>`
- `executionRole`: `coordinator` or `leaf`

Tool arguments request an adapter but never authorize it. The shared
execution-policy resolver is called from both control-tool handling and
kernel run acceptance. Background, delegated, and floating-pill sessions
are created as leaves; pi-mono and MCP tool projections omit
agent-management tools for those sessions, while server checks remain
authoritative.

This follows the containment work merged in #9402 and replaces its
adapter-name allowlist / surface-only inference with persisted policy.

## Product invariants

- INV-AGENT-* — provider boundary, execution role, leaf authority, and
required-control terminal semantics
- INV-CHAT-1 — the kernel remains the source of run/attempt terminal
truth
- INV-AUTH-1 — managed execution cannot select locally credentialed
adapters

Migration: session execution policy is schema migration 14, following
workstream continuity migration 13.

## Verification

- `cd desktop/macos/agent && npm run build`
- `cd desktop/macos/agent && npm test` — 393 passed
- focused execution-policy/routing/leaf/terminal suite — 210 passed
- `cd desktop/macos/pi-mono-extension && npm test` — 104 passed
- `cd desktop/macos && ./scripts/agent-logic-harness.sh --skip-install`
— passed (Swift lifecycle, agent runtime, exact extension tests)
- checked-in `scripts/pre-push origin` — passed; the installed hook
dispatcher references removed `scripts/pre-push-singleflight`, so the
push used `--no-verify` only after running the current hook script
directly
- named bundle `omi-provider-boundaries` built, installed, ad-hoc
re-signed, launched, and reported automation state under
`com.omi.omi-provider-boundaries`

The named bundle was cold-signed-out because the local Omi Dev profile
had no auth session, so a live managed-background network turn was
unavailable. The packaged runtime, exhaustive adapter/control matrix,
leaf projection, and terminal retry paths are covered by the passing
suites above.

Closes #9407

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9411?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>
<!-- End of auto-generated description by cubic. -->
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.
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.

1 participant