Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve unconfirmed FaceTime action outcomes
Adam Eivy5fca69322be0
diff --git a/server/native/facetime-ax/main.swift b/server/native/facetime-ax/main.swiftindex 950059d0a0..3cfd92f425 100644--- a/server/native/facetime-ax/main.swift+++ b/server/native/facetime-ax/main.swift@@ -40,6 +40,15 @@ func emit(_ result: Result, exit: Int32 = 0) -> Never {Foundation.exit(exit)}+// Sending AXPress does not prove that the requested state was reached.+// Preserve a confirmation timeout instead of inventing a successful state.+func completeAction(command: String, confirmedState: State?, action: String, message: String) -> Never {+ guard let state = confirmedState else {+ emit(Result(ok: false, command: command, state: .unknown, authorized: true, action: action, message: "FaceTime action was sent, but its resulting state could not be confirmed", errorCode: "state-unconfirmed"), exit: 1)+ }+ emit(Result(ok: true, command: command, state: state, authorized: true, action: action, message: message, errorCode: nil))+}+// AX trees are process-owned and can change between any two reads. Keep a// bounded, value-only snapshot so classification never follows a stale element// except for the final, semantically verified AXPress.@@ -298,8 +307,8 @@ if command == "answer" {guard AXUIElementPerformAction(incoming.controls[0].element, kAXPressAction as CFString) == .success else {emit(Result(ok: false, command: command, state: .dialing, authorized: true, action: "none", message: "The matching answer control could not be pressed", errorCode: "action-failed"), exit: 1)}- let state = waitForState([.connected], matcher: matcher, timeout: 5) ?? .connected- emit(Result(ok: true, command: command, state: state, authorized: true, action: "press-notification-action", message: "Answered the incoming call", errorCode: nil))+ let state = waitForState([.connected], matcher: matcher, timeout: 5)+ completeAction(command: command, confirmedState: state, action: "press-notification-action", message: "Answered the incoming call")}let applications = faceTimeApplications()@@ -311,5 +320,5 @@ guard controls.count == 1 else { ambiguous(command, state: faceTimeState(matcherguard AXUIElementPerformAction(controls[0].element, kAXPressAction as CFString) == .success else {emit(Result(ok: false, command: command, state: .connected, authorized: true, action: "none", message: "The matching hang-up control could not be pressed", errorCode: "action-failed"), exit: 1)}-let ended = waitForState([.ended, .idle], matcher: matcher, timeout: 5) ?? .ended-emit(Result(ok: true, command: command, state: ended, authorized: true, action: "press-call-action", message: "FaceTime call ended", errorCode: nil))+let ended = waitForState([.ended, .idle], matcher: matcher, timeout: 5)+completeAction(command: command, confirmedState: ended, action: "press-call-action", message: "FaceTime call ended")diff --git a/server/services/voice/facetimeBridge.test.js b/server/services/voice/facetimeBridge.test.jsindex c5dd857cd1..d662bb0c85 100644--- a/server/services/voice/facetimeBridge.test.js+++ b/server/services/voice/facetimeBridge.test.js@@ -1,4 +1,4 @@-import { mkdtempSync, rmSync, writeFileSync } from 'fs';+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';import { tmpdir } from 'os';import { join } from 'path';import { spawnSync } from 'child_process';@@ -54,7 +54,7 @@ const device = (overrides = {}) => ({describe('FaceTime Audio control protocol', () => {// swiftc compiles are runner-budgeted, not product behavior: a cold/contended- // full-suite worker can take >10s on the default testTimeout, so these two+ // full-suite worker can take >10s on the default testTimeout, so these// compile tests carry their own budget (same reasoning as vitest.config.js).it.runIf(process.platform === 'darwin')('compiles the native helper and preserves its strict JSON boundary', () => {const sourceDir = join(import.meta.dirname, '..', '..', 'native', 'facetime-ax');@@ -95,6 +95,39 @@ guard !matcher.matches(["Incoming call from +44 1555 123 4567"]) else { exit(4)}}, 60_000);+ it.runIf(process.platform === 'darwin')('reports unconfirmed native actions as failures and preserves observed states', () => {+ const sourceDir = join(import.meta.dirname, '..', '..', 'native', 'facetime-ax');+ const tempDir = mkdtempSync(join(process.env.PORTOS_TEST_TMPDIR || tmpdir(), 'portos-facetime-confirmation-'));+ const runner = join(tempDir, 'main.swift');+ const binary = join(tempDir, 'confirmation-test');+ try {+ // Exercise the native serialization/exit boundary without reading AX+ // surfaces, pressing controls, or waiting on a real call.+ const source = readFileSync(join(sourceDir, 'main.swift'), 'utf8');+ const declarations = source.slice(0, source.indexOf('let arguments = CommandLine.arguments'));+ writeFileSync(runner, `${declarations}+let state = CommandLine.arguments[2] == "unconfirmed"+ ? waitForState([], matcher: IdentityMatcher(handle: "+15551234567", identity: "Example Caller"), timeout: 0)+ : State(rawValue: CommandLine.arguments[2])+completeAction(command: CommandLine.arguments[1], confirmedState: state, action: "test-action", message: "confirmed")+`);+ const compiled = spawnSync('swiftc', ['-warnings-as-errors', join(sourceDir, 'identityMatcher.swift'), runner, '-o', binary], { encoding: 'utf8' });+ expect(compiled.status, compiled.stderr).toBe(0);+ for (const [command, state] of [['answer', 'unconfirmed'], ['hangup', 'unconfirmed'], ['answer', 'connected'], ['hangup', 'ended'], ['hangup', 'idle']]) {+ const result = spawnSync(binary, [command, state], { encoding: 'utf8' });+ const confirmed = state !== 'unconfirmed';+ expect(result.status, result.stderr).toBe(confirmed ? 0 : 1);+ const parsed = facetimeControlResultSchema.parse(JSON.parse(result.stdout));+ expect(parsed).toMatchObject({+ ok: confirmed, command, state: confirmed ? state : 'unknown',+ action: 'test-action', errorCode: confirmed ? null : 'state-unconfirmed',+ });+ }+ } finally {+ rmSync(tempDir, { recursive: true, force: true });+ }+ }, 60_000);+it('accepts only the strict helper result contract', () => {const result = facetimeControlResultSchema.safeParse({ok: true, command: 'probe', state: 'idle', authorized: true,@@ -284,5 +317,19 @@ guard !matcher.matches(["Incoming call from +44 1555 123 4567"]) else { exit(4)},);});++ it('preserves a native confirmation failure at the bridge boundary', async () => {+ const unconfirmed = {+ ...validResult, ok: false, command: 'hangup', state: 'unknown',+ action: 'press-call-action', message: 'FaceTime action was sent, but its resulting state could not be confirmed',+ errorCode: 'state-unconfirmed',+ };+ await withReadyHelper(+ { success: false, code: 1, signal: null, stdout: JSON.stringify(unconfirmed), stderr: '', timedOut: false },+ async () => {+ await expect(run('hangup', readyConfig)).rejects.toMatchObject({ status: 502, code: 'state-unconfirmed' });+ },+ );+ });});});