Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions config/reliability-gates.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,83 @@
}
},
"gates": [
{
"id": "mobile-push.headless-startup-and-policy",
"title": "Headless push lifecycle and mobile delivery policy",
"maturity": "experimental",
"protection": "partial",
"owner": "runtime",
"layer": "service-integration",
"surfaces": ["headless startup", "push registration", "native push delivery policy"],
"platforms": ["macos", "linux", "windows"],
"providers": ["local", "remote-runtime"],
"coveredPlatforms": ["macos"],
"coveredProviders": ["local", "remote-runtime"],
"coverageNotes": "Actual startOrcad entry with mocked daemon/RPC startup boundaries; real controller, push service, and persisted device registry. Gateway send is stubbed.",
"motivatingLinks": ["https://github.com/stablyai/orca/pull/19204"],
"invariant": "Headless startup installs and disposes push delivery; desktop notification categories remain authoritative, the three-minute away policy is preserved, and host activity cannot extend the seven-day mobile lease.",
"oracle": "Require registration after RPC identity initialization and shutdown cleanup; idle 179/180/0 yields false/true/false in retained event metadata and exactly one gateway push. Legacy socket subscriptions preserve notification filtering, while opted-in push clients can request dismissal reconciliation. Desktop categories remain authoritative. Persisted lease expires exactly at seven days and only explicit registration renews it.",
"commands": [
"ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/mobile-notification-dismissal-store.test.ts src/renderer/src/hooks/useAutoAckViewedAgent.away.test.ts",
"ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/orcad/orcad-push-startup.test.ts src/main/runtime/push/push-policy-pipeline.integration.test.ts"
],
"testFiles": [
"src/main/orcad/orcad-push-startup.test.ts",
"src/main/runtime/push/push-policy-pipeline.integration.test.ts",
"src/main/runtime/mobile-notification-dismissal-store.test.ts",
"src/renderer/src/hooks/useAutoAckViewedAgent.away.test.ts"
],
"assertionRefs": [
{
"file": "src/main/orcad/orcad-push-startup.test.ts",
"assertions": [
"starts push after RPC identity is available and stops dispatch on shutdown"
]
},
{
"file": "src/main/runtime/push/push-policy-pipeline.integration.test.ts",
"assertions": [
"carries the native idle boundary through replay and push dispatch",
"expires persisted registration at seven days despite host activity and renews explicitly"
]
}
],
"evidenceRuns": [
{
"date": "2026-09-07",
"runner": "local",
"platform": "macos",
"command": "ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/orcad/orcad-push-startup.test.ts src/main/runtime/push/push-policy-pipeline.integration.test.ts",
"result": "passed",
"summary": "Four tests passed across two files.",
"durationSeconds": 0.407
}
],
"runtimeBudget": {
"p95Seconds": 10,
"scope": "Target budget; measured p95 not established"
},
"flakeHistory": {
"status": "soaking",
"evidence": "Focused local run passed; repeated CI history not established."
},
"redGreenEvidence": {
"status": "partial",
"evidence": "Headless startup oracle reproduced missing registrar before the startup fix and passed afterward. Policy tests cover candidate behavior."
},
"performanceBudget": {
"required": false,
"evidence": "Lifecycle and policy coverage; asserts exact gateway send counts and zero remaining dispatch listeners after shutdown."
},
"promotionCriteria": ["Collect repeated CI runs without unexplained failures."],
"knownGaps": [
"Does not prove APNs silent background wakeup or actual operating-system idle transitions.",
"Rendererless agent/bell event generation remains outside the documented feature contract.",
"No live Windows or Linux policy evidence.",
"Mobile native presentation and dismissal integration belongs to the subsequent mobile PR."
],
"demotionRule": "Keep experimental if lifecycle or policy assertions fail; do not weaken them to bypass platform delivery gaps."
},
{
"id": "agent-session.completed-turn-duration",
"title": "Completed turn duration survives client recovery and history pagination",
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/headless-linux-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ its own `orca`.
`ws://` through an HTTPS-only endpoint.
- Hostnames, IPv4, bracketed IPv6, and raw IPv6 literals are supported. IPv6
still requires an IPv6-reachable listener/network path.
- Background push notifications to a paired phone do not fire from a headless
server: agent-completion detection runs in the desktop renderer, which is not started in serve
mode, so nothing reaches the push gateway even though the phone
registers successfully.
- `xvfb-run` and `dbus-run-session -- xvfb-run` remain valid diagnostic launch
shapes, but neither should be needed when `Xvfb` is installed and no display
is configured. Repeated D-Bus messages without a ready block indicate startup
Expand Down
1 change: 1 addition & 0 deletions src/main/global-fetch-call-site-audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const AUDITED_GLOBAL_FETCH_LINES = new Map<string, number>([
['main/orca-profiles/profile-cloud-client.ts', 1],
['main/orca-profiles/profile-cloud-org-members-client.ts', 1],
['main/rate-limits/codex-fetcher.ts', 3],
['main/runtime/push/push-gateway-client.ts', 1],
['main/runtime/relay/relay-http-client.ts', 2],
['main/runtime/relay/relay-region-catalog-fetch.ts', 1],
['main/runtime/relay/relay-region-preference.ts', 2],
Expand Down
4 changes: 3 additions & 1 deletion src/main/host/electron-runtime-desktop-surface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BrowserWindow, ipcMain, Notification } from 'electron'
import { BrowserWindow, ipcMain, Notification, powerMonitor } from 'electron'
import { readDesktopAwayState } from '../notifications/desktop-away-state'
import type { RuntimeDesktopSurface } from '../runtime/runtime-desktop-surface'

/** The desktop implementation of the runtime's optional desktop facilities. */
export const electronRuntimeDesktopSurface: RuntimeDesktopSurface = {
isAwayForMobileNotifications: () => readDesktopAwayState(powerMonitor),
showNotification: ({ title, body }) => {
if (!Notification.isSupported()) {
return false
Expand Down
38 changes: 1 addition & 37 deletions src/main/ipc/notification-burst-cooldown.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
const NOTIFICATION_COOLDOWN_MS = 5000
const MAX_RECENT_NOTIFICATION_KEYS = 50

function pruneRecentNotifications(recentNotifications: Map<string, number>, now: number): void {
if (recentNotifications.size <= MAX_RECENT_NOTIFICATION_KEYS) {
return
}

for (const [key, ts] of recentNotifications) {
if (now - ts >= NOTIFICATION_COOLDOWN_MS) {
recentNotifications.delete(key)
}
}

while (recentNotifications.size > MAX_RECENT_NOTIFICATION_KEYS) {
const oldest = recentNotifications.keys().next()
if (oldest.done) {
break
}
recentNotifications.delete(oldest.value)
}
}

export function reserveNotificationCooldown(
recentNotifications: Map<string, number>,
dedupeKey: string,
now: number
): boolean {
const lastSentAt = recentNotifications.get(dedupeKey) ?? 0
if (now - lastSentAt < NOTIFICATION_COOLDOWN_MS) {
return false
}
recentNotifications.delete(dedupeKey)
recentNotifications.set(dedupeKey, now)
pruneRecentNotifications(recentNotifications, now)
return true
}
export { reserveNotificationCooldown } from '../../shared/notification-burst-cooldown'
23 changes: 17 additions & 6 deletions src/main/ipc/notification-options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { translateMain } from '../i18n/main-i18n'
import type { NotificationDispatchRequest } from '../../shared/notification-settings-types'

const NOTIFICATION_AGENT_LABEL_MAX_LENGTH = 40
Expand Down Expand Up @@ -57,19 +58,29 @@ function buildAgentTaskCompleteNotificationOptions(

const agentLabel = formatNotificationAgentLabel(args.agentType)
const worktreeContext = formatNotificationWorktreeContext(args)
const statusText =
args.agentState === 'blocked' || args.agentState === 'waiting'
? 'needs input'
: args.agentState === 'done' && args.agentInterrupted
? 'stopped'
: 'finished'
const statusText = formatAgentNotificationStatusText(args)

return {
title: `${worktreeContext} - ${agentLabel} ${statusText}`,
body: buildAgentTaskCompleteRichBody(args) ?? `${agentLabel} ${statusText}.`
}
}

// Why (#4375): a still-working agent must never be announced as finished. Only an
// explicit terminal state, or no state at all (the hook snapshot expired and the
// notification itself is the completion signal), may say "finished".
function formatAgentNotificationStatusText(args: NotificationDispatchRequest): string {
if (args.agentState === 'blocked' || args.agentState === 'waiting') {
return translateMain('notifications.agentStatus.needsInput', 'needs input')
}
if (args.agentState === 'working') {
return translateMain('notifications.agentStatus.working', 'working')
}
return args.agentState === 'done' && args.agentInterrupted
? translateMain('notifications.agentStatus.stopped', 'stopped')
: translateMain('notifications.agentStatus.finished', 'finished')
}

function formatNotificationWorktreeContext(args: NotificationDispatchRequest): string {
const worktreeLabel = normalizeNotificationText(
args.worktreeLabel,
Expand Down
69 changes: 68 additions & 1 deletion src/main/ipc/notifications-message-formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,73 @@ describe('registerNotificationHandlers', () => {
expect(options.body.length).toBeLessThanOrEqual(180)
})

it.each([
{ agentState: 'working', expected: 'feat/notis - Claude working' },
{ agentState: 'blocked', expected: 'feat/notis - Claude needs input' },
{ agentState: 'waiting', expected: 'feat/notis - Claude needs input' },
{ agentState: 'done', expected: 'feat/notis - Claude finished' },
{ agentState: undefined, expected: 'feat/notis - Claude finished' }
])('titles agentState $agentState without claiming a false finish', async (scenario) => {
registerNotificationHandlers({
getSettings: () => ({
notifications: {
enabled: true,
agentTaskComplete: true,
terminalBell: false,
suppressWhenFocused: true
}
})
} as never)

const handler = getDispatchHandler()
await handler(
{},
{
source: 'agent-task-complete',
worktreeLabel: 'feat/notis',
agentType: 'claude',
...(scenario.agentState ? { agentState: scenario.agentState } : {}),
agentLastAssistantMessage: 'Ran the suite.'
}
)

expect(notificationCtorMock).toHaveBeenCalledWith(
expectedNativeNotificationOptions({ title: scenario.expected, body: 'Ran the suite.' })
)
})

it('reports an interrupted finish as stopped', async () => {
registerNotificationHandlers({
getSettings: () => ({
notifications: {
enabled: true,
agentTaskComplete: true,
terminalBell: false,
suppressWhenFocused: true
}
})
} as never)

const handler = getDispatchHandler()
await handler(
{},
{
source: 'agent-task-complete',
worktreeLabel: 'feat/notis',
agentType: 'claude',
agentState: 'done',
agentInterrupted: true
}
)

expect(notificationCtorMock).toHaveBeenCalledWith(
expectedNativeNotificationOptions({
title: 'feat/notis - Claude stopped',
body: 'Claude stopped.'
})
)
})

it('uses tool context before falling back when no prompt or assistant preview exists', async () => {
registerNotificationHandlers({
getSettings: () => ({
Expand Down Expand Up @@ -308,7 +375,7 @@ describe('registerNotificationHandlers', () => {

expect(notificationCtorMock).toHaveBeenCalledWith(
expectedNativeNotificationOptions({
title: 'feat/notis - Agent finished',
title: 'feat/notis - Agent working',
body: 'Using Bash: pnpm test'
})
)
Expand Down
20 changes: 13 additions & 7 deletions src/main/ipc/notifications-mobile-fanout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ describe('registerNotificationHandlers', () => {

expect(dispatchMobileNotification).toHaveBeenCalledWith({
type: 'notification',
emittedAt: expect.any(Number),
source: 'agent-task-complete',
title: 'feat/notis - Hermes finished',
body: 'The diff updates notification formatting.',
worktreeId: 'repo::wt1'
worktreeId: 'repo::wt1',
agentState: 'done'
})
expect(notificationCtorMock).not.toHaveBeenCalled()
})

it('does not dispatch mobile notifications when notifications are disabled', async () => {
it('offers disabled desktop events to independently configured phones', async () => {
const dispatchMobileNotification = vi.fn()
registerNotificationHandlers(
{
Expand All @@ -101,10 +103,12 @@ describe('registerNotificationHandlers', () => {
reason: 'disabled'
})

expect(dispatchMobileNotification).not.toHaveBeenCalled()
expect(dispatchMobileNotification).toHaveBeenCalledWith(
expect.objectContaining({ desktopAllowed: false })
)
})

it('does not dispatch mobile notifications when the source is disabled', async () => {
it('marks a disabled desktop source for phones following desktop settings', async () => {
const dispatchMobileNotification = vi.fn()
registerNotificationHandlers(
{
Expand All @@ -126,7 +130,9 @@ describe('registerNotificationHandlers', () => {
reason: 'source-disabled'
})

expect(dispatchMobileNotification).not.toHaveBeenCalled()
expect(dispatchMobileNotification).toHaveBeenCalledWith(
expect.objectContaining({ desktopAllowed: false })
)
})

it('dispatches one mobile notification when the active worktree is focused on desktop', async () => {
Expand Down Expand Up @@ -173,7 +179,7 @@ describe('registerNotificationHandlers', () => {
expect(notificationCtorMock).not.toHaveBeenCalled()
})

it('does not dispatch mobile notifications for cooldown-suppressed bursts', async () => {
it('preserves different mobile event categories before per-phone burst suppression', async () => {
const dispatchMobileNotification = vi.fn()
registerNotificationHandlers(
{
Expand All @@ -198,7 +204,7 @@ describe('registerNotificationHandlers', () => {
reason: 'cooldown'
})

expect(dispatchMobileNotification).toHaveBeenCalledTimes(1)
expect(dispatchMobileNotification).toHaveBeenCalledTimes(2)
expect(dispatchMobileNotification).toHaveBeenCalledWith(
expect.objectContaining({ source: 'agent-task-complete', worktreeId: 'repo::wt1' })
)
Expand Down
Loading