Repository navigation
fix(computer-use): converge provider ref lifecycles on the contract - #124374
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 15, 2026, 11:59 PM ET / August 16, 2026, 03:59 UTC. ClawSweeper reviewWhat this changesThe PR aligns native macOS and CUA computer-use reference lifetimes and stale-generation errors, adding shared lifecycle contract cases. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep 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 Review scores
Verification
How this fits togetherComputer-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]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceTests +168, Other +175. Total +343 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against acbbff19bad0. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles) |
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.
|
Both actionable items addressed in 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 Proven by negative test rather than assertion: with the post-await branch disabled ( Peekaboo stable-identity assumption — inspected directly in the pinned source rather than assumed. Test-access surface — agreed and already bounded. The widened members are Proof re-run after the change: 12 files / 98 tests green across |
|
Merged via squash.
|
…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
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_windowswith CUA, but the identical flow failed on native Peekaboo. Two separate defects caused that:windowRefs, so any earlier window ref went stale.WindowMutationIdentity, which embedscapturedBoundsandisMinimized. 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 staleServiceWindowInfo. ItsmutationIdentityandboundswere then passed asexpectedWindowIdentity/expectedWindowBounds, so the operator got a downstream mismatch failure instead of the contract'sCOMPUTER_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
WindowTargetis 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.mutationIdentitykeeps 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
ComputerActionServiceV2with realServiceApplicationInfo/ServiceWindowInfo/WindowMutationIdentityvalues; its in-flight case runs a realperform()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_windowsorget_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
window_movedcase fails on all three of its assertions (ref changed, bounds not refreshed,mutationIdentitynot refreshed); it passes on the fix.unrelated-discovery-preserves-window-reffailed withstaleObservation; 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-typesswiftformat --config config/swiftformat --lintandswiftlint lint --config config/swiftlint.ymlon both changed Swift files (clean)node scripts/run-oxlint.mjson 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
ComputerOpaqueReferenceStorefrom 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.