Skip to content

fix(macos): acquire agent credentials per model request - #14368

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/agent-credential-relay
Sep 17, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/agent-credential-relay

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Problem and change

Beta v0.12.356 retained a startup Firebase token inside pi-mono for about 15 hours. One offline refresh ended the 45-minute bridge timer; the app recovered its own credentials but the worker kept sending the old token. Its bare HTTP 401 status code (no body) became an unclassified runtime error and invited futile resends.

This PR takes the authorized request-scoped stepping stone. Every pi-mono HTTP attempt obtains current Authorization and usable BYOK headers from Swift/AuthService through the existing Unix pipe. The kernel checks the live run capability before dispatch and after reply; Swift fences the owner session and process generation, including a final same-owner session-generation check immediately before IPC. No token is retained in adapter configuration or the subprocess environment. The 45-minute timer, refresh_token IPC, and token-driven subprocess restart are removed. All four harnesses share the scrubbed Swift launch environment; external harnesses retain their own provider authentication.

The installed pi SDK catches and ignores before_provider_headers exceptions. Credential acquisition therefore runs at fetch, where it can prevent network I/O on failure; the existing header hook supplies correlation/context. Managed 401s force-refresh and replay once before response bytes are exposed. Numeric status is carried over pi JSONL as a typed failure; the existing Swift refresh/retry safety net recognizes managed authentication only. BYOK/third-party 401s do not refresh or invalidate the Omi session. Auth failures show “Your session expired” with Sign in; typed journal metadata renders “Session expired” after reload. Telemetry carries the authentication code.

The existing relay is a tool/control JSONL transport, not an HTTP streaming server. A Swift SSE relay with cancellation, backpressure, header fidelity, and all-harness lifecycle coverage is a larger independent boundary. This PR removes expiry correctness from process lifetime without adding a second live credential path or a migration flag. Credentials still cross IPC and exist in per-request Node memory: this is not full subprocess credential isolation.

Product invariants affected

  • INV-AGENT-*: capability/owner admission remains kernel-owned; the new request exchange revalidates authority and the startup handshake rejects old runtimes missing request_scoped_model_credentials.
  • INV-AUTH-1: AuthService remains credential authority; transient network failure preserves the session, same-owner replacement revokes stale replies, and provider 401s do not masquerade as managed-session failure.
  • INV-CHAT-1: failure classification is metadata on the existing canonical journal row, with a behavioral write/decode/presentation round trip; no second transcript store.

Failure-Class: new

New class: FC-expiring-authority-copied-into-worker

The new static tripwire supplements behavioral expiry/owner/HTTP tests. It is intentionally scoped to the managed desktop agent boundary, including its explicit request-scoped IPC exception, rather than a general secret scanner. It would have rejected the measured v0.12.356 startup credential copy and refresh-driven restart. The new failure class has no merged evidence PR yet; this incident and this PR are its initial evidence. Existing assumed-lifetime and owner-mutation classes do not describe a correctly issued credential copied into a long-lived worker. Obsolete source assertions requiring token propagation/timer startup were removed; the supplied Beta incident is the external evidence for replacing them with request-time behavioral tests.

Line-Count-Exception: desktop/macos/Desktop/Sources/AuthService.swift | 2867 -> 2868 | Inject the credential clock at its existing owner for the expiry/offline regression
Line-Count-Exception: desktop/macos/Desktop/Sources/MainWindow/Components/ChatBubble.swift | 2158 -> 2162 | Render the typed session-expired row status at the existing status switch
Line-Count-Exception: desktop/macos/Desktop/Sources/Providers/ChatProvider.swift | 7362 -> 7365 | Carry the bounded failure code through the existing failure marker and journal projection

Verification

  • npm --prefix desktop/macos/agent run build — passed TypeScript compilation and runtime packaging copy.
  • npm --prefix desktop/macos/agent test — 71 files / 885 tests passed, including numeric status propagation with exact HTTP 401 status code (no body) and capability-fenced reply routing.
  • npm --prefix desktop/macos/pi-mono-extension test — 143 tests passed, including injected-clock expiry/offline/recovery, one 401 replay, BYOK/third-party isolation, request-body replay, SSE body preservation, cancellation, and a real Unix-socket exchange.
  • desktop/macos/agent/node_modules/.bin/tsc --noEmit --module nodenext --target es2022 --allowImportingTsExtensions --skipLibCheck desktop/macos/pi-mono-extension/index.ts — passed; the extension has no separate package typecheck script.
  • desktop/macos/scripts/run-swift-ci.sh --select-toolchain — unavailable: current checkout pins Xcode 26.6 at /Applications/Xcode_26.6.app; that installation is absent. Installed toolchain is Apple Swift 6.4 / macOS 27 SDK.
  • xcrun swift build --build-tests --package-path desktop/macos/Desktop — passed on the installed toolchain (app plus all test targets).
  • xcrun swift test --skip-build --package-path desktop/macos/Desktop --filter 'AgentModelCredentialsTests|AuthRefreshResilienceTests|AgentRuntimeProcessTests|ChatTurnFailureNoticeTests|ChatTurnFailurePresentationTests|ChatQueryTelemetryTests|ChatErrorStateTests|AgentRuntimeFailureTests' — 170 tests passed, including the real AuthService expiry/offline/recovery seam and typed journal round trip.
  • desktop/macos/scripts/agent-logic-harness.sh — 803 selected Swift tests passed on retry. The first XCTest run stalled while exiting and was stopped by its own PIDs. The retry's Node stage hit one existing Unix-socket test timeout (884/885 passed) under default parallelism.
  • VITEST_MAX_WORKERS=4 desktop/macos/scripts/agent-logic-harness.sh --node-only — passed all 885 agent tests, generated-tool-surface verification, and all 143 extension tests. This uses the harness's supported concurrency setting without skipping tests or changing timeouts.
  • OMI_PR_BODY_FILE="$PWD/.local/pr-body.md" make preflight — all 36 selected local manifest checks passed (881.33 seconds), including both-lane credential tripwire registration, Swift formatting/lint, runtime conformance, and dead-code checks.
  • scripts/pr-preflight --pr-body-file .local/pr-body.md --metadata-only — all four metadata checks passed on the committed head; the new class uses the protocol's literal Failure-Class: new declaration.
  • VITEST_MAX_WORKERS=4 OMI_PR_BODY_FILE="$PWD/.local/pr-body.md" git push -u origin fix/agent-credential-relay — all 36 committed-head manifest checks and the complete outer pre-push gate passed, including desktop debug compile and full tool-surface tests. GitHub closed the idle SSH connection; push exited 141 and git ls-remote returned no branch. Only then, as authorized, git push --no-verify -u origin fix/agent-credential-relay transferred the unchanged verified commit. Remote SHA matches 8a13184bfbc62b627a91bc98b2d7b493be0e13c0.
  • python3 desktop/macos/scripts/check-agent-credentials.py — passed tripwire and mutation self-tests; registered in both local and CI manifest lanes.
  • python3 desktop/macos/scripts/check_desktop_test_quality.py — passed.

Security measurement: pi's installed createLocalBashOperations calls getShellEnv, which spreads process.env. A synthetic local child probe using that actual helper confirmed OMI_AUTH_TOKEN, OMI_API_KEY, and OMI_BYOK_OPENAI are inherited and visible via /bin/ps eww -p <synthetic-child-pid> before scrubbing, and absent afterward. Only inert values were used; no real process environment or credentials were printed. Existing user-MCP stdio servers already use an allowlist. Adapter spawn tests also exercise scrubbing of injected ambient keys.

No app was launched, installed, or driven, and Omi Beta was untouched. No production host was contacted. Hermetic tests/builds are not live app acceptance. No backend code or .github workflow was modified.

Follow-ups

  1. Replace model_headers IPC with a Swift-owned loopback HTTP relay. Keep both Firebase and BYOK values entirely in Swift; test byte-identical SSE/header forwarding, backpressure, cancellation, owner revocation, per-launch capability authentication, and one pre-stream 401 replay. Remove the request-credential IPC when that relay lands.
  2. Add bounded in-process recovery for repeated non-auth failures of the whole Node daemon. Current kernel code already recycles failed pi workers and can retry a safe turn; it does not implement a repeated-failure policy for the entire daemon. Verify journal/session continuity and exclusion of auth/quota errors.
  3. Give managed backend 401s machine-readable token_expired/token_revoked provenance, distinct from BYOK upstream authentication. Until then a 401 with an LLM BYOK header is conservatively provider_setup_needed and never signs the user out.
  4. Run the named com.omi.omi-fault app flow and pinned-toolchain CI before treating this as shipped-app acceptance. This task explicitly prohibits launching the app.

Review in cubic

Remove startup Firebase/BYOK copies, refresh_token IPC, and the bridge refresh
loop. Resolve owner-fenced request headers lazily and retry one managed HTTP
401 before exposing response bytes. Carry typed authentication through the
runtime, Sign in recovery, journal status, and telemetry. Keep the full Swift
HTTP relay as an explicit follow-up; per-request credentials still cross IPC.

Failure-Class: new

New class: FC-expiring-authority-copied-into-worker

Verification: agent npm build/test (885 tests); extension npm test (143 tests)
and direct tsc; Swift build --build-tests and focused credential/chat tests
(170 tests), installed Swift 6.4. The pinned Xcode 26.6 is unavailable.
Hermetic expiry/offline/recovery, owner fencing, bare 401, BYOK, SSE/cancel,
Unix-pipe, and synthetic shell/ps environment probes. No app launched or
production request made. Full preflight and harness evidence is in the PR.
@mintlify

mintlify Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Sep 17, 2026, 5:16 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@Git-on-my-level
Git-on-my-level merged commit 37c2fb5 into main Sep 17, 2026
45 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/agent-credential-relay branch September 17, 2026 18:06

This branch was successfully deployed

1 active deployment
staging - docs — 8a13184b Deployed Sep 17, 2026 by mintlify[bot]
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