Skip to content

fix(ci): shell-comparable JSON boolean for Agent VM SHA reuse guard - #13686

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
apoorvdarshan:cursor/fix-agent-vm-sha-reuse-49e4
Sep 13, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
apoorvdarshan:cursor/fix-agent-vm-sha-reuse-49e4

Conversation

@apoorvdarshan

@apoorvdarshan apoorvdarshan commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #11758

Investigation

Fix

  • Add .github/scripts/workflow_json_field_for_shell.py to emit JSON fields with json.dumps for shell comparisons.
  • Restore backend/scripts/resolve_agent_vm_sha_release.py and extend backend/tests/unit/test_resolve_agent_vm_sha_release.py with a behavioral regression that runs the workflow one-liners in bash against resolver-shaped output:
    • broken print(json.load…["reuse"]) → rebuild branch
    • fixed print(json.dumps(json.load…["reuse"])) and the helper → reuse branch
  • Ratchet check-desktop-backend-release-policy.py to reject the Python-repr reuse extract when Agent VM resolver steps are present.

If Agent VM deploy steps are restored, both desktop-backend workflows must use one of:

reuse="$(python3 -c 'import json,sys; print(json.dumps(json.load(open(sys.argv[1], encoding="utf-8"))["reuse"]))' "$RUNNER_TEMP/agent-vm-sha-release.json")"

or:

reuse="$(python3 .github/scripts/workflow_json_field_for_shell.py "$RUNNER_TEMP/agent-vm-sha-release.json" reuse)"

Verification

backend/.venv/bin/python -m pytest backend/tests/unit/test_resolve_agent_vm_sha_release.py -v
python3 .github/scripts/check-desktop-backend-release-policy.py
python3 .github/scripts/test_check_desktop_backend_release_policy.py

All passed locally (8 pytest cases; 32 policy unittest cases).

Failure-Class: none

Review in cubic

Failure-Class: none

Re-verify BasedHardware#11758: no open PR; broken print(True) vs "true" reuse extract is
absent on current main because cloud Agent VM deploy steps were removed in
BasedHardware#11795. Restore resolve_agent_vm_sha_release.py for the regression suite and
add a behavioral shell-contract test that runs the workflow one-liners against
resolver output (broken path skips reuse branch; json.dumps and
workflow_json_field_for_shell.py take it). Ratchet desktop-backend release
policy against the Python-repr anti-pattern.

Verification:
  backend/.venv/bin/python -m pytest tests/unit/test_resolve_agent_vm_sha_release.py -v
  python3 .github/scripts/check-desktop-backend-release-policy.py
  python3 .github/scripts/test_check_desktop_backend_release_policy.py

Co-authored-by: Apoorv Darshan <[email protected]>
@apoorvdarshan
apoorvdarshan marked this pull request as ready for review September 13, 2026 06:29

@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.

1 issue found across 5 files

Confidence score: 3/5

  • In .github/scripts/check-desktop-backend-release-policy.py, equivalent shell syntax such as if [[ "${reuse}" == "true" ]] can bypass the guard, causing Python True to select the rebuild branch and potentially misapply the release policy; validate reuse extraction directly or support the shell comparison form.
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=".github/scripts/check-desktop-backend-release-policy.py">

<violation number="1" location=".github/scripts/check-desktop-backend-release-policy.py:190">
P2: Equivalent shell syntax such as `if [[ "${reuse}" == "true" ]]` bypasses this guard, allowing Python `True` to select the rebuild branch. Validate the resolver's `reuse` extraction directly or match the shell comparison semantically rather than requiring one literal spelling.</violation>
</file>

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

Re-trigger cubic

f"{workflow}: Agent VM SHA reuse guard must not print a JSON boolean with Python repr "
'(use json.dumps or .github/scripts/workflow_json_field_for_shell.py)'
)
if 'if [[ "$reuse" == "true" ]]' in text and "resolve_agent_vm_sha_release.py" in text:

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: Equivalent shell syntax such as if [[ "${reuse}" == "true" ]] bypasses this guard, allowing Python True to select the rebuild branch. Validate the resolver's reuse extraction directly or match the shell comparison semantically rather than requiring one literal spelling.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/scripts/check-desktop-backend-release-policy.py, line 190:

<comment>Equivalent shell syntax such as `if [[ "${reuse}" == "true" ]]` bypasses this guard, allowing Python `True` to select the rebuild branch. Validate the resolver's `reuse` extraction directly or match the shell comparison semantically rather than requiring one literal spelling.</comment>

<file context>
@@ -181,6 +181,22 @@ def validate_deploy_workflow(text: str, *, production: bool) -> list[str]:
+            f"{workflow}: Agent VM SHA reuse guard must not print a JSON boolean with Python repr "
+            '(use json.dumps or .github/scripts/workflow_json_field_for_shell.py)'
+        )
+    if 'if [[ "$reuse" == "true" ]]' in text and "resolve_agent_vm_sha_release.py" in text:
+        shell_safe_reuse = (
+            'json.dumps(json.load(open(sys.argv[1], encoding="utf-8"))["reuse"])',
</file context>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in bda4509: the release-policy guard now matches ${reuse} / $reuse compares to JSON true semantically and requires shell-safe extraction in the same Agent VM resolver step (json.dumps or workflow_json_field_for_shell.py).

Failure-Class: none

- Fail closed when GCS describe errors are not object-not-found.
- Scope reuse-extract policy to resolver step blocks; match ${reuse} compares.
- Harden workflow_json_field_for_shell (with-open, scalar-only values).
- shlex.quote plan paths in shell contract test; add policy positive paths.

Verification:
  PYTHONPATH=backend python3 -m pytest backend/tests/unit/test_resolve_agent_vm_sha_release.py -v
  python3 .github/scripts/check-desktop-backend-release-policy.py
  python3 .github/scripts/test_check_desktop_backend_release_policy.py

Co-authored-by: Apoorv Darshan <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified locally at bda4509 — good investigation on #11758, and the guard is genuinely behavioral. What I checked, file by file:

  • backend/scripts/resolve_agent_vm_sha_release.py — faithful restore of the pre-retirement resolver with one deliberate hardening: object_exists() now fails closed on non-404 gcloud errors instead of treating any error as absent (which would have invited a competing rebuild during a transient GCS failure). The hardening has its own test.
  • backend/tests/unit/test_resolve_agent_vm_sha_release.py — this is the right shape for the regression: it executes the actual workflow one-liner in bash against resolver-shaped JSON and asserts the broken print() extract takes the rebuild branch while json.dumps and the helper take the reuse branch. I reproduced the failure mode independently; it behaves exactly as the issue describes.
  • .github/scripts/workflow_json_field_for_shell.py — clean helper; the scalar-only check (bool/int/float/null) prevents silently feeding quoted strings into shell comparisons.
  • .github/scripts/check-desktop-backend-release-policy.py — the ratchet is scoped to resolver step blocks (an unrelated step mentioning the helper cannot satisfy it) and matches both $reuse and ${reuse} compare forms. It runs against the live dev/prod workflows today and passes, since main has had no resolver steps since Retire the cloud Agent VM: tombstone the broker endpoints, delete the control plane #11795.
  • .github/scripts/test_check_desktop_backend_release_policy.py — good coverage: positive paths for both accepted extracts, plus the ${reuse} variant and the unrelated-helper-mention negative case.

All 9 resolver tests, the policy checker, and the 36 policy-fixture tests pass in a worktree at this head; CI is green.

One small wiring note (non-blocking): workflow_json_field_for_shell.py is not in any checks-manifest.yaml trigger list. The backend unit test that executes it lives under backend/, so its coverage fires on backend changes but not on edits to the helper itself — worth adding the path to a manifest trigger in a follow-up so the helper cannot silently regress.

Since this extends the desktop-backend release-policy guard, it needs maintainer sign-off before merge per the repo's release-pipeline risk rule — leaving for human maintainer review for that sign-off, not for any code concern.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added candidate-clean-pr Small, safe, well-scoped, well-tested contribution; model clean PR needs-maintainer-review Needs a human maintainer to sign off before merge workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior docs-tooling Layer: Documentation, examples, dev tools labels Sep 13, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fix(ci): real bug (broken Python-repr JSON boolean vs shell comparison), fixes #11758, confirmed NOT already fixed on main (resolve_agent_vm_sha_release.py doesn't exist there). Behavioral regression test proves broken-vs-fixed. CI green, candidate-clean-pr label. Confidence 4/5 (only the line-count criterion misses). Merging.

@kodjima33
kodjima33 merged commit 3515b58 into BasedHardware:main Sep 13, 2026
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

candidate-clean-pr Small, safe, well-scoped, well-tested contribution; model clean PR docs-tooling Layer: Documentation, examples, dev tools needs-maintainer-review Needs a human maintainer to sign off before merge workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent VM SHA-reuse guard is dead code: workflow compares Python's True to true, so every same-SHA redeploy fails cmp

4 participants