fix(engines): validate mktemp output and set trap before temp creation in opencode sandbox - #108
Conversation
…+ routing helper Resolves a 2026-08-16 false-negative where 'which codex' missed /Users/hermes/.local/bin/codex (off default PATH), wrongly forcing a delegate_task fallback on Aegis. New tools resolve each [engines.NAME].bin directly from config.toml (os.path.exists / shutil.which), never 'which'. Scripts are self-locating (resolve paths relative to their own dir), so the canonical clone may live anywhere (e.g. ~/Projects/ringer-fleet-swarm). - scripts/ring-engine-probe.py: per-engine AVAILABLE/MISSING report, exit 0/1/2 - checks/engine-bin-probe.py: lint-gate (PASS/FAIL) for pre-dispatch - scripts/verify-ringer-engines.sh: preflight wrapper, aborts on MISSING - scripts/ring-route.sh: host+engine router, failing closed on probe - README: Preflight engine-bin gate section
Post-review sanity check: passed ✅This PR went through two independent AI-assisted review passes after the initial submission, with all findings fixed and re-verified: Round 1 — Gemini 3.1 Pro review flagged:
→ Fixed in Round 2 — Claude Code sanity check flagged:
→ Fixed in Re-verification: all findings confirmed resolved, including empirical failure-injection tests (failed From a shell-safety standpoint this is merge-ready on my end. |
|
hey nate and team hope this is useful |
Running pytest from the repo root had no config, so it collected 258 tests by sweeping test_*.py under swarms/*/work/... and templates/ (transient swarm work-dirs). Add pytest.ini with `testpaths = tests` to restrict default collection to the real suite (258 -> 175, all under tests/). Pre-existing tests/ failures (foreign hardcoded path, stale date assertion, lint template) are independent of this change. Reviewed-by: qwen2.5-coder:14b (local alternate-brain review: APPROVE) Authored-by: Zatara (session:437bb9f9) Co-authored-by: hermes <hermes@Aegis.local> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…n in opencode sandbox
ad86682 to
49e59dd
Compare
|
Smoke-tested the rebased branch (now on current upstream main) on macOS:
Both the silent |
The opencode sandbox fix branch accidentally included two JackReis/ringer main-only commits (engine-bin probe + pytest testpaths). Strip those so this PR diffs only engines/opencode-sandboxed.sh against upstream main. Co-authored-by: Cursor <cursoragent@cursor.com>
Bugs Found During Audit Two related issues in
engines/opencode-sandboxed.shwere discovered while auditing the script for macOS-specific problems. ### 1. Sandbox bypass on mktemp failure (security) Line 46 (original):bash SCRATCH=$(cd $(mktemp -d -t ringer-opencode-scratch) && pwd -P)Bash disablesset -einside command substitutions. Ifmktemp -dfails (disk full, permissions, path too long), the inner substitution returns empty,cdfalls through to the current directory, andSCRATCHis set to$HOMEorPWD. The sandbox then allows writes to the entire home directory. Reproduced on macOS:$ bash -c set -euo pipefail; OUTER=$(cd $(false) && pwd -P); echo OUTER=$OUTER OUTER=/Users/hermes### 2. Profile file leak on early termination Lines 47-49 (original):bash PROFILE=$(mktemp -t ringer-opencode-prof) cleanup() { rm -rf $SCRATCH $PROFILE; } trap cleanup EXITIf the script receives a signal or crashes betweenmktempandtrap cleanup EXIT, the profile file is never cleaned up. Over many runs this accumulates files in/var/folders/.../T/. ## Fix - Movetrap cleanup EXITbefore any temp file creation. - Definecleanup()early with guards against uninitializedSCRATCH/PROFILE(so it is safe to call before those vars are set). - Separatemktemp -dfromcd/pwd -Pand explicitly validate the result: exit with an error message if the directory was not created. - Same validation for the profilemktemp. ## Verification -bash -nsyntax check passes. - The script still runs correctly in--no-sandboxmode (verified live withopencodeon macOS). - No other tracked files in the repo usemktemp, so this is a complete fix for the pattern. ## Files Changed -engines/opencode-sandboxed.sh(+23 / −3)