Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(computer-server): preserve released Driver state and pin release source (#3703)

Francesco Bonaccidcdbd1bf4960
diff --git a/.github/scripts/resolve_computer_server_release.py b/.github/scripts/resolve_computer_server_release.py
new file mode 100644
index 0000000000..dd920152ae
--- /dev/null
+++ b/.github/scripts/resolve_computer_server_release.py
@@ -0,0 +1,46 @@
+"""Resolve an existing computer-server tag to reviewed, version-matching source."""
+
+import os
+import re
+import subprocess
+import tomllib
+from pathlib import Path
+
+VERSION = re.compile(r"(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)")
+PREFIX = "refs/tags/computer-server-v"
+
+
+def git(*arguments):
+ return subprocess.check_output(["git", *arguments], text=True, timeout=60).strip()
+
+
+def resolve(version, ref):
+ selected = version or (ref.removeprefix(PREFIX) if ref.startswith(PREFIX) else "")
+ if not VERSION.fullmatch(selected):
+ raise ValueError("a stable computer-server version is required")
+ if ref.startswith(PREFIX) and ref != PREFIX + selected:
+ raise ValueError("release input and tag disagree")
+ sha = git("rev-parse", "--verify", f"{PREFIX}{selected}^{{commit}}")
+ if not re.fullmatch(r"[0-9a-f]{40}", sha):
+ raise ValueError("invalid release commit")
+ # A release is from landed source, not an arbitrary unmerged tag.
+ git("merge-base", "--is-ancestor", sha, "refs/remotes/origin/main")
+ project = tomllib.loads(git("show", f"{sha}:libs/python/computer-server/pyproject.toml"))
+ if (
+ project["project"]["name"] != "cua-computer-server"
+ or project["project"]["version"] != selected
+ ):
+ raise ValueError("release tag and package metadata disagree")
+ return {"version": selected, "sha": sha}
+
+
+def main():
+ result = resolve(os.environ.get("RELEASE_VERSION", ""), os.environ.get("RELEASE_REF", ""))
+ with Path(os.environ["GITHUB_OUTPUT"]).open("a", encoding="utf-8") as output:
+ for key, value in result.items():
+ output.write(f"{key}={value}\n")
+ print(f"computer-server {result['version']} source {result['sha']}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/.github/scripts/tests/test_computer_server_release_wiring.py b/.github/scripts/tests/test_computer_server_release_wiring.py
new file mode 100644
index 0000000000..25198a234b
--- /dev/null
+++ b/.github/scripts/tests/test_computer_server_release_wiring.py
@@ -0,0 +1,105 @@
+"""Computer-server publication must use the version-matching landed tag."""
+
+import importlib.util
+import subprocess
+import unittest
+from pathlib import Path
+from unittest import mock
+
+import yaml
+
+ROOT = Path(__file__).resolve().parents[3]
+SPEC = importlib.util.spec_from_file_location(
+ "computer_server_release", ROOT / ".github/scripts/resolve_computer_server_release.py"
+)
+RELEASE = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(RELEASE)
+SHA = "a" * 40
+PROJECT = '[project]\nname="cua-computer-server"\nversion="0.3.46"\n'
+
+
+class ReleaseResolutionTests(unittest.TestCase):
+ def test_existing_tag_resolves_to_version_matching_landed_commit(self):
+ with mock.patch.object(RELEASE, "git", side_effect=[SHA, "", PROJECT]) as git:
+ self.assertEqual(
+ RELEASE.resolve("0.3.46", "refs/heads/main"), {"version": "0.3.46", "sha": SHA}
+ )
+ self.assertEqual(
+ git.call_args_list,
+ [
+ mock.call("rev-parse", "--verify", "refs/tags/computer-server-v0.3.46^{commit}"),
+ mock.call("merge-base", "--is-ancestor", SHA, "refs/remotes/origin/main"),
+ mock.call("show", f"{SHA}:libs/python/computer-server/pyproject.toml"),
+ ],
+ )
+
+ def test_tag_push_selects_same_source(self):
+ with mock.patch.object(RELEASE, "git", side_effect=[SHA, "", PROJECT]):
+ self.assertEqual(RELEASE.resolve("", "refs/tags/computer-server-v0.3.46")["sha"], SHA)
+
+ def test_invalid_input_never_reaches_git(self):
+ for version in ("", "main", "0.3.46-rc.1", "0.3.46\n", "01.3.46", "0.3.46;echo test"):
+ with self.subTest(version=version), mock.patch.object(RELEASE, "git") as git:
+ with self.assertRaises(ValueError):
+ RELEASE.resolve(version, "refs/heads/main")
+ git.assert_not_called()
+ with mock.patch.object(RELEASE, "git") as git:
+ with self.assertRaises(ValueError):
+ RELEASE.resolve("0.3.46", "refs/tags/computer-server-v0.3.45")
+ git.assert_not_called()
+
+ def test_invalid_sha_metadata_missing_tag_and_unmerged_source_fail_closed(self):
+ cases = [
+ ["main"],
+ [SHA, "", PROJECT.replace("0.3.46", "0.3.45")],
+ [SHA, "", PROJECT.replace("cua-computer-server", "other-package")],
+ subprocess.CalledProcessError(1, ["git", "rev-parse"]),
+ [SHA, subprocess.CalledProcessError(1, ["git", "merge-base"])],
+ ]
+ for replies in cases:
+ with (
+ self.subTest(replies=replies),
+ mock.patch.object(RELEASE, "git", side_effect=replies),
+ ):
+ with self.assertRaises((ValueError, subprocess.CalledProcessError)):
+ RELEASE.resolve("0.3.46", "refs/heads/main")
+
+
+class ReleaseWiringTests(unittest.TestCase):
+ def workflow(self, name):
+ return yaml.safe_load((ROOT / ".github/workflows" / name).read_text())
+
+ def test_all_release_outputs_use_the_resolved_commit(self):
+ workflow = self.workflow("cd-py-computer-server.yml")
+ jobs = workflow["jobs"]
+ self.assertEqual(
+ workflow["concurrency"],
+ {"group": "computer-server-publish", "cancel-in-progress": False},
+ )
+ self.assertEqual(jobs["prepare"]["outputs"]["sha"], "${{ steps.get-version.outputs.sha }}")
+ for name in ("publish", "create-release"):
+ self.assertEqual(jobs[name]["with"]["source_sha"], "${{ needs.prepare.outputs.sha }}")
+ self.assertEqual(jobs["publish"]["with"]["python_version"], "3.12")
+ self.assertEqual(
+ jobs["build-binaries"]["steps"][0]["with"]["ref"], "${{ needs.prepare.outputs.sha }}"
+ )
+
+ def test_immutable_publish_does_not_run_legacy_main_reset(self):
+ workflow = self.workflow("py-reusable-publish.yml")
+ steps = workflow["jobs"]["build-and-publish"]["steps"]
+ self.assertEqual(steps[0]["with"]["ref"], "${{ inputs.source_sha || 'main' }}")
+ reset = next(step for step in steps if step.get("name") == "Ensure latest main branch")
+ self.assertEqual(reset["if"], "inputs.source_sha == ''")
+ verify = next(
+ step for step in steps if step.get("name") == "Verify immutable release checkout"
+ )
+ self.assertEqual(verify["if"], "inputs.source_sha != ''")
+ self.assertIn('test "$(git rev-parse HEAD)" = "$RELEASE_SOURCE_SHA"', verify["run"])
+ self.assertLess(
+ steps.index(verify),
+ next(i for i, step in enumerate(steps) if step.get("name") == "Build and publish"),
+ )
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/cd-py-computer-server.yml b/.github/workflows/cd-py-computer-server.yml
index 40060bd609..bac2a7184a 100644
--- a/.github/workflows/cd-py-computer-server.yml
+++ b/.github/workflows/cd-py-computer-server.yml
@@ -25,42 +25,33 @@ on:
permissions:
contents: write
+concurrency:
+ group: computer-server-publish
+ cancel-in-progress: false
+
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
+ sha: ${{ steps.get-version.outputs.sha }}
steps:
- uses: actions/checkout@v4
-
- - name: Determine version
- id: get-version
- run: |
- # Check inputs.version first (set by workflow_call)
- if [ -n "${{ inputs.version }}" ]; then
- VERSION=${{ inputs.version }}
- elif [ "${{ github.event_name }}" == "push" ]; then
- # Extract version from tag (for package-specific tags)
- if [[ "${{ github.ref }}" =~ ^refs/tags/computer-server-v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
- VERSION=${BASH_REMATCH[1]}
- else
- echo "Invalid tag format for computer-server"
- exit 1
- fi
- elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
- # Use version from workflow dispatch
- VERSION=${{ github.event.inputs.version }}
- else
- echo "No version provided"
- exit 1
- fi
- echo "VERSION=$VERSION"
- echo "version=$VERSION" >> $GITHUB_OUTPUT
+ with:
+ fetch-depth: 0
+ persist-credentials: false
- name: Set up Python
- uses: actions/setup-python@v4
+ uses: actions/setup-python@v5
with:
- python-version: "3.10"
+ python-version: "3.12"
+
+ - name: Resolve immutable release source
+ id: get-version
+ env:
+ RELEASE_VERSION: ${{ inputs.version }}
+ RELEASE_REF: ${{ github.ref }}
+ run: python .github/scripts/resolve_computer_server_release.py
publish:
needs: prepare
@@ -70,6 +61,8 @@ jobs:
package_dir: "libs/python/computer-server"
version: ${{ needs.prepare.outputs.version }}
base_package_name: "cua-computer-server"
+ source_sha: ${{ needs.prepare.outputs.sha }}
+ python_version: "3.12"
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
@@ -89,6 +82,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
+ with:
+ ref: ${{ needs.prepare.outputs.sha }}
+ persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v5
@@ -137,6 +133,7 @@ jobs:
with:
tag_name: "computer-server-v${{ needs.prepare.outputs.version }}"
release_name: "cua-computer-server v${{ needs.prepare.outputs.version }}"
+ source_sha: ${{ needs.prepare.outputs.sha }}
module_path: "libs/python/computer-server"
body: ""
attach_artifacts: true
diff --git a/.github/workflows/ci-test-python.yml b/.github/workflows/ci-test-python.yml
index 8070affe65..8c6dd1fad0 100644
--- a/.github/workflows/ci-test-python.yml
+++ b/.github/workflows/ci-test-python.yml
@@ -24,10 +24,10 @@ jobs:
- som
- cua-auto
include:
- # computer-server's VNC backend tests assert what vncdotool puts on
- # the wire, so the job needs the package's own `vnc` extra.
+ # Exercise the real pinned Driver state contract and what the VNC
+ # backend puts on the wire, using the package's own extras.
- package: computer-server
- extras: "[vnc]"
+ extras: "[driver,vnc]"
steps:
- name: Checkout code
diff --git a/.github/workflows/ci-test-scripts.yml b/.github/workflows/ci-test-scripts.yml
index e4ef2c489e..407c2349fd 100644
--- a/.github/workflows/ci-test-scripts.yml
+++ b/.github/workflows/ci-test-scripts.yml
@@ -11,6 +11,9 @@ on:
- ".github/workflows/cd-rust-cua-driver.yml"
- ".github/workflows/cd-py-cua-driver.yml"
- ".github/workflows/cd-py-sandbox.yml"
+ - ".github/workflows/cd-py-computer-server.yml"
+ - ".github/workflows/py-reusable-publish.yml"
+ - ".github/workflows/release-github-reusable.yml"
- ".github/workflows/ci-cua-driver-installer-compat.yml"
- ".github/workflows/ci-release-metadata.yml"
- ".github/workflows/cd-swift-lume.yml"
diff --git a/.github/workflows/py-reusable-publish.yml b/.github/workflows/py-reusable-publish.yml
index 3f2ee33253..3359ef95aa 100644
--- a/.github/workflows/py-reusable-publish.yml
+++ b/.github/workflows/py-reusable-publish.yml
@@ -19,6 +19,16 @@ on:
description: "PyPI package name (e.g. cua-agent)"
required: true
type: string
+ source_sha:
+ description: "Optional verified immutable release commit; empty preserves the legacy main flow"
+ required: false
+ type: string
+ default: ""
+ python_version:
+ description: "Build interpreter required by the selected package"
+ required: false
+ type: string
+ default: "3.11"
secrets:
PYPI_TOKEN:
required: true
@@ -37,20 +47,29 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
- ref: main
+ ref: ${{ inputs.source_sha || 'main' }}
fetch-depth: 0 # Full history for release creation
- name: Ensure latest main branch
+ if: inputs.source_sha == ''
run: |
git fetch origin main
git reset --hard origin/main
echo "Current HEAD commit:"
git log -1 --oneline
+ - name: Verify immutable release checkout
+ if: inputs.source_sha != ''
+ env:
+ RELEASE_SOURCE_SHA: ${{ inputs.source_sha }}
+ run: |
+ [[ "$RELEASE_SOURCE_SHA" =~ ^[0-9a-f]{40}$ ]]
+ test "$(git rev-parse HEAD)" = "$RELEASE_SOURCE_SHA"
+
- name: Set up Python
- uses: actions/setup-python@v4
+ uses: actions/setup-python@v5
with:
- python-version: "3.11"
+ python-version: ${{ inputs.python_version }}
- name: Create root pdm.lock file
run: |
@@ -60,7 +79,7 @@ jobs:
- name: Install PDM
uses: pdm-project/setup-pdm@v3
with:
- python-version: "3.11"
+ python-version: ${{ inputs.python_version }}
cache: true
- name: Set version
diff --git a/.github/workflows/release-github-reusable.yml b/.github/workflows/release-github-reusable.yml
index c58b91fcb8..e57ff8023d 100644
--- a/.github/workflows/release-github-reusable.yml
+++ b/.github/workflows/release-github-reusable.yml
@@ -11,6 +11,11 @@ on:
description: "Release display name (e.g., cua-computer v0.5.0)"
required: true
type: string
+ source_sha:
+ description: "Optional verified immutable commit for path-filtered release notes"
+ required: false
+ type: string
+ default: ""
module_path:
description: "Path to the module for filtering commits (e.g., libs/python/agent)"
required: false
@@ -53,6 +58,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
+ ref: ${{ inputs.source_sha || github.sha }}
- name: Generate path-filtered release notes
if: inputs.module_path != '' && inputs.generate_notes
diff --git a/libs/python/computer-server/computer_server/handlers/cua_driver.py b/libs/python/computer-server/computer_server/handlers/cua_driver.py
index e1e78f9b9a..eed7b2bed7 100644
--- a/libs/python/computer-server/computer_server/handlers/cua_driver.py
+++ b/libs/python/computer-server/computer_server/handlers/cua_driver.py
@@ -256,15 +256,20 @@ class CuaDriverAutomationHandler(BaseAutomationHandler):
@classmethod
def _session_state(cls, state: Any) -> Dict[str, Any]:
- return {
+ result = {
"session": state.session,
"capture_scope": cls._enum_name(state.capture_scope),
"effective_scope": cls._enum_name(state.effective_scope),
- "desktop_capture_authorized": state.desktop_capture_authorized,
"desktop_unlocked": state.desktop_unlocked,
"escalation_reason": cls._enum_name(state.escalation_reason),
"escalation_detail": state.escalation_detail,
}
+ # The supported 0.22.x SDK predates this explicit capture-authority
+ # field. Preserve its response instead of failing or inferring authority
+ # from the legacy desktop_unlocked name.
+ if hasattr(state, "desktop_capture_authorized"):
+ result["desktop_capture_authorized"] = state.desktop_capture_authorized
+ return result
@staticmethod
def _ok(data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
diff --git a/libs/python/computer-server/tests/test_cua_driver_handler.py b/libs/python/computer-server/tests/test_cua_driver_handler.py
index 13e41928df..1cb0cbe6d5 100644
--- a/libs/python/computer-server/tests/test_cua_driver_handler.py
+++ b/libs/python/computer-server/tests/test_cua_driver_handler.py
@@ -383,6 +383,25 @@ async def test_auto_scope_escalation_is_explicit_and_typed(sdk, fallback):
assert request.detail == "the window ladder found no target"
+def test_session_state_accepts_the_released_driver_contract():
+ import cua_driver
+
+ state = cua_driver.SessionStateOutput(
+ session="released-contract",
+ capture_scope=cua_driver.CaptureScope.AUTO,
+ effective_scope=cua_driver.EffectiveScope.WINDOW,
+ desktop_unlocked=False,
+ escalation_reason=None,
+ escalation_detail=None,
+ )
+ result = CuaDriverAutomationHandler._session_state(state)
+ assert result["session"] == "released-contract"
+ assert result["effective_scope"] == "window"
+ assert result["desktop_unlocked"] is False
+ # Do not invent a capture-authority value absent from the released SDK.
+ assert "desktop_capture_authorized" not in result
+
+
@pytest.mark.asyncio
async def test_invalid_escalation_reason_is_rejected_without_calling_driver(sdk, fallback):
driver = _Driver()