Skip to content

feat(desktop): enforce automation effects and isolate test state - #13556

Merged
Git-on-my-level merged 11 commits into
mainfrom
codex/desktop-agent-guardrails
Sep 26, 2026
Merged

Git-on-my-level merged 11 commits into
mainfrom
codex/desktop-agent-guardrails

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Desktop automation inferred safety from action names, allowing mutating probes and loading snapshots to appear read-only. Require typed effects at every registration, derive discovery descriptions from them, and add opt-in omi-ctl action <name> --read-only dispatch that rejects effects before calling handlers. Migrate the entire registry, including asynchronous and parameter-dependent effects, and pin historical misleading probes in registry/HTTP regression tests.

Add a shared defaults-domain fixture with teardown ownership, a cancellable run-loop timer token with automatic invalidation, and an injected clock/scheduler for deterministic chat-scroll tests. Migrate the two owner-projection defaults fixtures and chat glide/pinner timers. Extend the existing test-quality ratchet to reject growth beyond the current 292 direct shared-defaults mutations; narrowly documented integration exceptions remain possible. Existing debt is preserved for gradual migration.

These are declared product effects, not a sandbox: Swift still needs correct effect annotations. The defaults matcher covers direct mutations, not aliases. Timer lifetime tests retain real run-loop coverage alongside deterministic clock tests. No app launch or backend access was used for validation.

Validation in /Volumes/scratch/worktrees/omi/desktop-agent-guardrails, based on d5cbd548f6, using host Xcode 26.6 / 17F113:

  • Normal committed-diff git push gate passes, including debug compilation (82.95s), desktop tool/launcher fixtures, and metadata validation.
  • make setup and OMI_PR_BODY_FILE=/tmp/omi-agent-guardrails-pr-body.md make preflight: 29 checks pass (93.69s); metadata checks pass, including exact growth allowances below.
  • Full desktop test-target compilation with xcrun swift build --package-path desktop/macos/Desktop --build-tests passes. This caught and corrected actor-region ownership in the actual migrated projection tests.
  • CFFIXED_USER_HOME=<task-owned directory> xcrun swift test --package-path desktop/macos/Desktop -j 4 --filter 'DesktopAutomationActionEffectTests|DesktopAutomationBridgeRouteTests|DesktopAutomationSecondaryActionTests|AgentContinuityGauntletTests|IsolatedTestDefaultsTests|UserScrollDetectorTests|ChatScrollLiveEdgeTests|ChatPressPromotionPolicyTests|KernelTurnRecordedProjectionTests': 145 tests pass, including actual run-loop lifetime and injected clock coverage.
  • Static quality checker plus its 15 fixtures, CLI wire tests, strict flow coverage mapping, pinned Swift formatting/SwiftLint, and independent source review pass. The timer negative-control experiment fails both owner-release cases when token invalidation is removed.

Hosted pinned Xcode 16.4 validation remains CI evidence. Flow coverage was checked statically; chat-hermetic now asserts actual common-runloop timer validity after cancel and owner release via chat_timer_lifetime_probe. The probe is executed by the focused Swift suite; no full live UI flow was run.

Product invariants preserved: INV-CHAT-1, INV-CHAT-2, INV-NAV-1, INV-VOICE-1, INV-TASK-1, INV-TASK-2.
Failure-Class: FC-run-loop-timer-outlives-owner

Line-Count-Exception: desktop/macos/Desktop/Sources/DesktopAutomationBridge.swift | 5067 -> 5166 | Compiler-required effect declarations at existing registration owners; the enum policy is extracted into its own file.

Line-Count-Exception: desktop/macos/Desktop/Sources/FloatingControlBar/RealtimeHubController.swift | 1641 -> 1643 | Compiler-required effect declarations at existing registration owners; the enum policy is extracted into its own file.

Line-Count-Exception: desktop/macos/Desktop/Sources/MainWindow/Pages/MemoriesPage.swift | 3657 -> 3661 | Compiler-required effect declarations at existing registration owners; the enum policy is extracted into its own file.

Line-Count-Exception: desktop/macos/Desktop/Sources/MainWindow/Pages/TasksPage.swift | 6495 -> 6503 | Compiler-required effect declarations at existing registration owners; the enum policy is extracted into its own file.

Review in cubic

Reuse unique defaults-domain ownership and XCTest teardown in the auth
fixtures repaired by #13260. Both chat repeating timer owners from #13468
now use a shared invalidating token; drive elapsed time and callbacks through
a manual scheduler to exercise completion, retargeting, cancel and release.
Ratchet existing direct shared-defaults mutations at 292, with narrow local
integration reasons, in the existing quality guard and manifest lanes.

Verification: make setup; 15 Python checker tests; both named local manifest
checks; strict Swift 6 isolated type checks. A temporary SwiftPM fixture using
the exact changed timer classes/test methods and defaults support passed six
XCTest cases. Removing token deinit invalidation made two release tests fail.
Integrated desktop compilation and historical suite sequencing are delegated
to the parent task after combining worktrees; no live app was launched.

Failure-Class: FC-run-loop-timer-outlives-owner

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 45 files

Confidence score: 3/5

  • In desktop/macos/Desktop/Sources/MainWindow/Pages/TasksPage.swift, dump_tasks is labeled with .localState despite only reading SQLite, so --read-only dispatch rejects the intended probe with requiresEffects; align its declared effects with its read-only behavior.
  • In desktop/macos/Desktop/Sources/MainWindow/ChatFirst/ChatFirstAutomationRuntime.swift, chat_first_open_related_tasks advertises .remoteWrite without performing or queuing a remote write, which makes action discovery report an inaccurate effect union; remove .remoteWrite and retain only the effects it actually uses.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/macos/Desktop/Sources/MainWindow/Pages/TasksPage.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/MainWindow/Pages/TasksPage.swift:2855">
P2: `dump_tasks` is declared `effects: [.localState]`, but it only reads from SQLite and mutates no local/UI/stored state, so the new `--read-only` dispatch rejects it with `requiresEffects`. This is the probe intended for proving writes landed without mutation, so it should be callable read-only. Declare it with an empty effects set (`.localState` is documented as "mutates local app, UI, or stored state").</violation>
</file>

<file name="desktop/macos/Desktop/Sources/MainWindow/ChatFirst/ChatFirstAutomationRuntime.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/MainWindow/ChatFirst/ChatFirstAutomationRuntime.swift:67">
P2: `chat_first_open_related_tasks` does not perform or queue a remote write, but this declaration advertises one. Remove `.remoteWrite` so action discovery reports the actual effect union; retain `.localState` and any network-read effect caused by mounting Tasks.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


registry.register(
name: "open_task_details",
effects: [.localState],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: dump_tasks is declared effects: [.localState], but it only reads from SQLite and mutates no local/UI/stored state, so the new --read-only dispatch rejects it with requiresEffects. This is the probe intended for proving writes landed without mutation, so it should be callable read-only. Declare it with an empty effects set (.localState is documented as "mutates local app, UI, or stored state").

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/MainWindow/Pages/TasksPage.swift, line 2855:

<comment>`dump_tasks` is declared `effects: [.localState]`, but it only reads from SQLite and mutates no local/UI/stored state, so the new `--read-only` dispatch rejects it with `requiresEffects`. This is the probe intended for proving writes landed without mutation, so it should be callable read-only. Declare it with an empty effects set (`.localState` is documented as "mutates local app, UI, or stored state").</comment>

<file context>
@@ -2851,6 +2852,7 @@ class TasksViewModel: ObservableObject {
 
     registry.register(
       name: "open_task_details",
+      effects: [.localState],
       summary: "Open a task's detail panel by id — the same panel a row click opens. Omit the id to close it.",
       params: ["id"]
</file context>
Suggested change
effects: [.localState],
effects: [],


registry.register(
name: "chat_first_request_prompt_materialization",
effects: [.localState, .networkOrModel, .remoteWrite],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: chat_first_open_related_tasks does not perform or queue a remote write, but this declaration advertises one. Remove .remoteWrite so action discovery reports the actual effect union; retain .localState and any network-read effect caused by mounting Tasks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/MainWindow/ChatFirst/ChatFirstAutomationRuntime.swift, line 67:

<comment>`chat_first_open_related_tasks` does not perform or queue a remote write, but this declaration advertises one. Remove `.remoteWrite` so action discovery reports the actual effect union; retain `.localState` and any network-read effect caused by mounting Tasks.</comment>

<file context>
@@ -64,11 +64,11 @@ final class ChatFirstAutomationRuntime: ObservableObject {
 
     registry.register(
       name: "chat_first_request_prompt_materialization",
+      effects: [.localState, .networkOrModel, .remoteWrite],
       summary: "Run the normal foreground materialization path from mounted main Chat",
       params: ["timeoutMs"],
</file context>
Suggested change
effects: [.localState, .networkOrModel, .remoteWrite],
effects: [.localState, .networkOrModel],

Comment thread desktop/macos/scripts/omi-ctl Resolved
@Git-on-my-level
Git-on-my-level marked this pull request as draft September 13, 2026 06:08
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Reviewed both unresolved effect-declaration threads against the handlers and the effect contract added by this PR; keeping both declarations as-is — no code change warranted.

dump_tasks keeps [.localState] (thread PRRT_kwDOLkKqys6hug8i): the handler is not a pure read on a cold store. getLocalActionItems → ActionItemStorage.ensureInitialized() → RewindDatabase.performInitialization, which creates the data directory, migrates legacy data paths, and runs the GRDB migration ladder before the first read. That is stored-state mutation, which is exactly what .localState documents ("mutates local app, UI, or stored state"). The agent-docs added by this PR call this out by name: "dump_tasks can initialize/migrate SQLite". An empty effects set would publish safety: read_only in discovery while a cold call can write — the misleading-probe pattern this PR exists to remove.

chat_first_open_related_tasks keeps .remoteWrite (thread PRRT_kwDOLkKqys6hug8m): the handler only changes route locally, but opening the Tasks route mounts TasksPage, whose first-use path (loadTasksForFirstUse → loadTasksIfNeeded → scheduleStartupMaintenanceIfNeeded) can retry unsynced local tasks via APIClient.createActionItem and flush pending backend deletions. .remoteWrite is documented as "may modify remote user data, directly or through queued work", and the same agent-docs line covers this: "opening Tasks can retry queued uploads/deletions". Dropping it would under-report the effect union in discovery; .localState and .networkOrModel are retained alongside.

@Git-on-my-level
Git-on-my-level marked this pull request as ready for review September 26, 2026 21:23
@Git-on-my-level
Git-on-my-level merged commit d4f5d04 into main Sep 26, 2026
42 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/desktop-agent-guardrails branch September 26, 2026 21:23
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