Skip to content

fix(computer-use): converge provider ref lifecycles on the contract - #124374

Merged
steipete merged 4 commits into
mainfrom
steipete/cu-ref-convergence
Aug 16, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/cu-ref-convergence

Conversation

@steipete

@steipete steipete commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #124355

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

A model following the documented observe-then-act flow could reuse a window reference after list_windows with CUA, but the identical flow failed on native Peekaboo. Two separate defects caused that:

  1. Every discovery call cleared windowRefs, so any earlier window ref went stale.
  2. Ref identity included the whole WindowMutationIdentity, which embeds capturedBounds and isMinimized. Any move, resize, or minimize made the same live window look like a different one, so it got a new ref, the old ref was never evicted, and that old ref kept resolving to a stale ServiceWindowInfo. Its mutationIdentity and bounds were then passed as expectedWindowIdentity / expectedWindowBounds, so the operator got a downstream mismatch failure instead of the contract's COMPUTER_STALE_OBSERVATION.

A provider generation change during an action also surfaced different error vocabulary across the two providers.

Why This Change Was Made

The shared Computer Use contract is the authority: opaque refs belong to a provider generation, element refs additionally belong to the current observation, and stale refs report COMPUTER_STALE_OBSERVATION.

Native window refs now key on stable identity only — WindowServer id plus the owner process generation that guards pid reuse — and the stored WindowTarget is refreshed in place on every discovery. One live window keeps one ref for the whole lifecycle generation, the ref map is bounded by distinct windows rather than by movement, and the per-action identity and bounds checks always compare against current data. mutationIdentity keeps doing what it is for: the per-action expected-identity check, not ref identity. The in-flight lifecycle-change condition maps to the contract code. CUA production behavior is unchanged because it already matched those rules.

A single JSON case table drives both the Swift and TypeScript provider tests, and both run against real production code. The Swift side drives the real ComputerActionServiceV2 with real ServiceApplicationInfo / ServiceWindowInfo / WindowMutationIdentity values; its in-flight case runs a real perform() whose lifecycle is revoked mid-action rather than asserting an error it threw itself.

Shared cases: fresh_window, fresh_element, window_moved, generation_rotation, in_flight_generation_change, superseded_observation, unrelated_discovery, unknown_ref.

User Impact

Models can consistently call list_windows or get_window_state, then act on the returned refs across both providers, including after the user moves, resizes, or minimizes the window. When a ref really is stale, both providers return the same closed code and the model can take a fresh observation and retry.

Evidence

  • Regression proof: with the pre-fix matcher restored, the new window_moved case fails on all three of its assertions (ref changed, bounds not refreshed, mutationIdentity not refreshed); it passes on the fix.
  • Pre-fix shared Swift case unrelated-discovery-preserves-window-ref failed with staleObservation; the same CUA table passed.
  • swift test --parallel --package-path apps/macos (exit 0, zero failures)
  • swift test --filter Computer (31 tests in 3 suites passed)
  • node scripts/run-vitest.mjs extensions/cua-computer src/plugins/computer-use-contract.test.ts src/agents/tools (96 files, 2,066 tests passed, one file/test skipped)
  • pnpm tsgo, pnpm check:test-types
  • swiftformat --config config/swiftformat --lint and swiftlint lint --config config/swiftlint.yml on both changed Swift files (clean)
  • node scripts/run-oxlint.mjs on the changed TS tests, oxfmt --check (clean)
  • node --import tsx scripts/check-madge-import-cycles.ts (0 cycles), pnpm deadcode:full, git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main (clean, no accepted/actionable findings)

Production LOC: +71/-56 (net +15), of which 9 lines are two invariant doc comments. Tests and shared fixture: +312/-1. The one-instantiation generic ComputerOpaqueReferenceStore from the earlier revision is gone; the lifecycle is plain concrete state plus small helpers on its only owner, with no injected matcher or ref-minting closures.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 15, 2026, 11:59 PM ET / August 16, 2026, 03:59 UTC.

ClawSweeper review

What this changes

The PR aligns native macOS and CUA computer-use reference lifetimes and stale-generation errors, adding shared lifecycle contract cases.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this maintainer PR open: its new stable-window matcher still mints a new reference whenever either optional mutation identity is absent, contradicting the intended generation-lifetime reference contract.

Priority: P2
Reviewed head: ae29929a666ab1020f79c4b3bf5dd02b39c59a73

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused cross-provider regression coverage is useful, but the uncovered optional-identity path leaves the patch short of merge-ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its focused test evidence remains useful but does not resolve the review finding.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its focused test evidence remains useful but does not resolve the review finding.
Evidence reviewed 8 items Changed matcher drops nil-identity continuity: The new matcher returns false if either optional mutation identity is absent, so a repeated discovery cannot reuse and refresh that window's existing reference.
Optional identity is a real production state: The service guards mutationIdentity before several actions, establishing that it can be absent rather than being an unconditional invariant.
Prior behavior retained nil identities: Current main reused a reference when process ID, window ID, and mutationIdentity were equal; two absent optional identities compare equal there, unlike the proposed guard-false matcher.
Findings 1 actionable finding [P2] Preserve refs when mutation identity is absent
Security None None.

How this fits together

Computer-use providers convert model observations into opaque window and element references, then use those references to execute native or CUA actions. The shared lifecycle contract decides whether a reference remains usable or the model must observe again.

flowchart LR
  A[Model observation] --> B[Computer-use provider]
  B --> C[Window and element references]
  C --> D[Action request]
  D --> E{Provider generation current?}
  E -->|Yes| F[Native or CUA action]
  E -->|No| G[Fresh observation error]
Loading

Before merge

  • Preserve refs when mutation identity is absent (P2) - mutationIdentity is optional in this service, but this guard returns false whenever it is absent. Two discoveries of the same such window now mint distinct refs rather than refreshing one target, so the old ref becomes stale and the map grows on each discovery. Match through the app process-generation identity (or retain an equivalent safe fallback) and add the nil-identity regression case. Late finding: this code is unchanged from the previously reviewed head.
  • Resolve merge risk (P1) - As written, a window without mutationIdentity receives a fresh reference after each discovery, leaving prior references stale and allowing the map to grow per refresh.
  • Resolve merge risk (P2) - The native dependency source pinned by apps/macos/Package.resolved was unavailable for direct review, so the proposed process-identity fallback should be verified against its exact type contract.
  • Resolve merge risk (P1) - Production code is +15 net lines for a bug fix; the corrected identity handling should remain absorbed in the lifecycle owner rather than introduce another parallel reference path.
  • Complete next step (P2) - A narrow owner-boundary repair and regression case are clear; the PR should not merge until the matcher handles absent mutation identities.

Findings

  • [P2] Preserve refs when mutation identity is absent — apps/macos/Sources/OpenClaw/ComputerActionServiceV2.swift:667-668
Agent review details

Security

None.

PR surface

Tests +168, Other +175. Total +343 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 168 0 +168
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 4 232 57 +175
Total 7 400 57 +343

Review metrics

Metric Value Why it matters
Production versus regression coverage production +71/-56 (net +15); tests and shared fixture +329/-1 The bug fix adds lifecycle logic and cross-provider coverage; the remaining production growth should stay limited to the canonical identity owner.

Stored data model

Persistent data-model change detected: serialized state: extensions/cua-computer/src/ref-lifecycle.contract.test.ts, serialized state: src/plugins/computer-use-contract.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair nil-identity reference reuse (recommended)
    Use the application process identity and window ID as the stable key or otherwise retain safe same-window continuity when mutationIdentity is absent, then add a regression case.
  2. Accept stale references for identity-less windows
    Land the current behavior only if maintainers intentionally want repeated discovery to invalidate references whenever Peekaboo omits mutation identity.

Technical review

Best possible solution:

Match windows using the WindowServer ID plus the owning application's process-generation identity when available, preserve a safe nil-identity continuity path, and add the missing repeated-discovery regression case before merge.

Do we have a high-confidence way to reproduce the issue?

Yes—construct two discoveries of the same window with nil mutationIdentity and call issueWindowRef twice; current patch source deterministically returns different references, though this was not executed in the read-only review.

Is this the best way to solve the issue?

No—the lifecycle-owner approach is right, but the matcher must cover the optional identity state before it can satisfy the intended cross-provider contract.

Full review comments:

  • [P2] Preserve refs when mutation identity is absent — apps/macos/Sources/OpenClaw/ComputerActionServiceV2.swift:667-668
    mutationIdentity is optional in this service, but this guard returns false whenever it is absent. Two discoveries of the same such window now mint distinct refs rather than refreshing one target, so the old ref becomes stale and the map grows on each discovery. Match through the app process-generation identity (or retain an equivalent safe fallback) and add the nil-identity regression case. Late finding: this code is unchanged from the previously reviewed head.
    Confidence: 0.94
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against acbbff19bad0.

Labels

Label justifications:

  • P2: The patch has a bounded correctness defect in native computer-use reference reuse, affecting a normal observe-then-act workflow when identity data is absent.
  • merge-risk: 🚨 compatibility: Merging changes opaque reference lifetime semantics and would make existing returned window references stale on repeated discovery for identity-less windows.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its focused test evidence remains useful but does not resolve the review finding.

Evidence

Acceptance criteria:

  • [P1] swift test --filter ComputerRefLifecycleContractTests --package-path apps/macos.
  • [P1] swift test --filter Computer --package-path apps/macos.
  • [P1] node scripts/run-vitest.mjs extensions/cua-computer/src/ref-lifecycle.contract.test.ts src/plugins/computer-use-contract.test.ts.

What I checked:

Likely related people:

  • steipete: Current-main blame and history connect the existing native reference lifecycle to this area, and this PR continues that repair. (role: recent area contributor; confidence: high; commits: 1d5321192485; files: apps/macos/Sources/OpenClaw/ComputerActionServiceV2.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make repeated discovery reuse a reference when mutationIdentity is absent without weakening process-reuse protection.
  • Add a focused nil-identity case to the Swift lifecycle contract test and rerun the native computer-use suite.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-16T03:08:16.916Z sha 4859a37 :: found issues before merge. :: [P2] Refresh reused window targets during discovery
  • reviewed 2026-08-16T03:44:29.775Z sha 27f3207 :: found issues before merge. :: [P2] Exercise the actual in-flight CUA action path

Peekaboo matched an existing window ref on the whole WindowMutationIdentity,
which embeds capturedBounds and isMinimized. Any move, resize, or minimize
therefore minted a new ref for the same live window, never evicted the old
one, and let the old ref keep resolving to a stale ServiceWindowInfo whose
identity and bounds were then used as the per-action expectations, so the
operator saw a downstream mismatch instead of COMPUTER_STALE_OBSERVATION.

Window refs now key on stable identity only (WindowServer id plus the owner
process generation that guards pid reuse) and refresh the stored target in
place on every discovery, so one live window keeps one ref for the whole
lifecycle generation and later checks compare against current data. The
one-instantiation generic reference store is folded back into the service as
plain state plus small concrete helpers.

The shared case table gains window_moved, which both providers must satisfy,
and the Swift side now drives the real ComputerActionServiceV2 with real
Peekaboo values instead of a toy store with an equality matcher. Its
in-flight generation case runs a real perform() whose lifecycle is revoked
mid-action rather than throwing the error it asserted.
@steipete
steipete marked this pull request as ready for review August 16, 2026 03:37
@steipete

Copy link
Copy Markdown
Contributor Author

Both actionable items addressed in ae29929.

Exercise the actual in-flight CUA action path — correct, and it was the mirror of the finding this PR already fixed on the Swift side. The case called verifyGeneration, a pre-call guard, while the production behavior lives in callWindowTool (driver-result.ts:230), which snapshots driver.generation, awaits driver.callTool, then detects rotation. The case is now async and drives callWindowTool against a fake driver whose callTool rotates the generation mid-await.

Proven by negative test rather than assertion: with the post-await branch disabled (if (false && ...)), exactly in-flight-generation-change-uses-contract-code fails and the other seven still pass; restored, all eight pass. That is the regression the old case could not have caught.

Peekaboo stable-identity assumption — inspected directly in the pinned source rather than assumed. WindowMutationIdentity.processIdentity is ApplicationProcessIdentity(processIdentifier:processStartIdentity:) (Core/PeekabooAutomationKit/Sources/PeekabooAutomationKit/Services/Core/Protocols/ApplicationServiceProtocol.swift:549), so matching on windowID + processIdentity keeps the pid-reuse guard while excluding capturedBounds and isMinimized, which is the whole defect. Worth noting for future readers: Peekaboo ships hasSameStableReceipt on the same type, and it looks like the obvious helper to reuse — but it still compares capturedBounds, so reusing it would have reintroduced the bug. The match is written out explicitly for that reason.

Test-access surface — agreed and already bounded. The widened members are private to internal within the app module only (@testable import reaches internal, not private); no new public API, no test-only production seam, and no production branch that exists only for tests.

Proof re-run after the change: 12 files / 98 tests green across extensions/cua-computer, check:test-types clean, oxlint and oxfmt clean, git diff --check clean. Production delta is unchanged at +15 (nine of those lines are invariant comments); this commit is test-only.

@steipete
steipete merged commit 62deb87 into main Aug 16, 2026
184 checks passed
@steipete
steipete deleted the steipete/cu-ref-convergence branch August 16, 2026 04:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…penclaw#124374)

* fix(computer-use): converge provider ref lifecycles

* test(computer-use): expect stale lifecycle code

* fix(computer-use): key native window refs on stable window identity

Peekaboo matched an existing window ref on the whole WindowMutationIdentity,
which embeds capturedBounds and isMinimized. Any move, resize, or minimize
therefore minted a new ref for the same live window, never evicted the old
one, and let the old ref keep resolving to a stale ServiceWindowInfo whose
identity and bounds were then used as the per-action expectations, so the
operator saw a downstream mismatch instead of COMPUTER_STALE_OBSERVATION.

Window refs now key on stable identity only (WindowServer id plus the owner
process generation that guards pid reuse) and refresh the stored target in
place on every discovery, so one live window keeps one ref for the whole
lifecycle generation and later checks compare against current data. The
one-instantiation generic reference store is folded back into the service as
plain state plus small concrete helpers.

The shared case table gains window_moved, which both providers must satisfy,
and the Swift side now drives the real ComputerActionServiceV2 with real
Peekaboo values instead of a toy store with an equality matcher. Its
in-flight generation case runs a real perform() whose lifecycle is revoked
mid-action rather than throwing the error it asserted.

* test(cua-computer): drive the real in-flight generation-rotation path
steipete added a commit that referenced this pull request Aug 16, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: cua-computer rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant