the marker readers follow the new default: cockpit names the 2.x pin, the stray-2.x guard says how to move

Since v1.56.0 (decision 1546) OpenCode 2 is the default, so the cockpit's opencode_pinned
falls back to the 2.x pin when neither the binary nor the marker speaks: a box installed
before v1.56.0 (no marker) is told the version a plain ./install.sh brings, and its Agent
tab says ./install.sh brings it in line. A marker "1" still names the 1.x pin, so a box
that chose --opencode 1 is not nagged. install-agent.sh keeps its stray-2.x refusal (a
marker 1 or no marker with a 2.x binary on the PATH) and its message now says that a
plain ./install.sh serves OpenCode 2 since v1.56.0; its no-marker fallback stays 1, since
a markerless box is one a pre-v1.56.0 release installed. switch-model.sh's comment says
the marker holds 1 or 2. The two new tests failed on the previous code; 66 + 8 green after.

Generated by Mistral Vibe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hasan Basbunar committed 2026-11-20 15:50:39 +01:00
1 parent 3c00d59ba9
commit 9d2266706f
5 files changed
+52 -16

No files matched your search

+8 -6
View File
@@ -2550,17 +2550,19 @@ _OC_PIN_CACHE: dict = {}
def opencode_pinned(binary_version: str | None = None) -> str | None:
"""The opencode version install.sh pins, of the OpenCode this box runs: 1.x is pinned
by OPENCODE_VERSION, the --opencode 2 choice by OPENCODE2_VERSION (both are GitHub
release assets, digested the same way). The binary answers when the panel can see it;
the choice marker from install.sh answers otherwise; 1.x remains the word when neither
speaks. The page and the installer must never name two versions of the same thing."""
by OPENCODE_VERSION, OpenCode 2 by OPENCODE2_VERSION (both are GitHub release assets,
digested the same way). The binary answers when the panel can see it; the choice marker
from install.sh answers otherwise ("1" or "2" since v1.56.0); when neither speaks, the
default pin is the 2.x one, because since v1.56.0 a plain ./install.sh installs it
(decision 1546). The page and the installer must never name two versions of the same
thing."""
major = "2" if (binary_version or "").split(".")[0] == "2" else None
if major is None:
try:
first = (CONFIG_DIR / "opencode.major").read_text().splitlines()[0].strip()
major = "2" if first == "2" else "1"
major = first if first in ("1", "2") else "2"
except (OSError, IndexError):
major = "1"
major = "2"
var = "OPENCODE2_VERSION" if major == "2" else "OPENCODE_VERSION"
path = REPO_DIR / "install.sh"
try:
+8 -6
View File
@@ -89,19 +89,21 @@ OC_VERSION="$("$OPENCODE_BIN" --version 2>/dev/null || true)"; OC_VERSION="${OC_
OC_MAJOR="$(printf '%s' "$OC_VERSION" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 | cut -d. -f1 || true)"
# OpenCode 2 speaks the tab's language now (the relay probes /api/info, reads the ordered
# "permissions" and scrubs the answers that resolve {file:...} keys, measured on 2.3.0 the
# 2026-11-14) - but only on a box that chose it: ./install.sh --opencode 2 hands
# OPENCODE_MAJOR=2 down here. A stray 2.x found on the PATH (Homebrew Core's formula is
# one) is still refused before anything renders, so the installed unit keeps the opencode
# it runs (decision 455, 2026-10-22).
# 2026-11-14) - but only on a box that serves it: since v1.56.0 install.sh hands
# OPENCODE_MAJOR=2 down on any box it moved to the default (decision 1546). A stray 2.x
# found on the PATH of a box whose marker says 1 (Homebrew Core's formula is one) is still
# refused before anything renders, so the installed unit keeps the opencode it runs
# (decision 455, 2026-10-22).
# The box's own choice, read from its marker when ./install.sh did not pass it down: a standalone
# re-run (the retry hint, docs/cockpit.md) must render the profile this box actually serves
# (independent review of the v2 migration, finding 4).
# (independent review of the v2 migration, finding 4). No marker means a box a pre-v1.56.0
# release installed, still serving 1.x: the fallback stays 1 there.
OPENCODE_MAJOR="${OPENCODE_MAJOR:-$(head -1 "$HOME/.config/qwen38/opencode.major" 2>/dev/null || true)}"
OPENCODE_MAJOR="${OPENCODE_MAJOR:-1}"
OC_PROFILE=1
if [ -n "$OC_MAJOR" ] && [ "$OC_MAJOR" -ge 2 ]; then
if [ "${OPENCODE_MAJOR:-1}" != "2" ]; then
die "$OPENCODE_BIN is opencode ${OC_VERSION##* }, OpenCode 2, which this box did not choose: run ./install.sh --opencode 2 (it serves it under the Agent view's own guards), or put the opencode 1.x this repo pins first on your PATH (./install.sh installs it in ~/.opencode/bin), or set OPENCODE_BIN to it (docs/opencode.md)."
die "$OPENCODE_BIN is opencode ${OC_VERSION##* }, OpenCode 2, which this box did not choose: run ./install.sh --opencode 2 (since v1.56.0 a plain ./install.sh serves OpenCode 2 too, it is the default), or put the opencode 1.x this repo pins first on your PATH (./install.sh --opencode 1 installs it in ~/.opencode/bin), or set OPENCODE_BIN to it (docs/opencode.md)."
fi
OC_PROFILE=2
fi
@@ -135,12 +135,23 @@ class TheV2Panel(unittest.TestCase):
class TheV1PanelStillWorks(unittest.TestCase):
def test_the_1_x_branch_reads_its_own_route_and_names_its_own_pin(self):
cp = load("panel_v1", UNIT_V1)
# the box chose 1.x (marker 1, ./install.sh --opencode 1): its panel names the 1.x pin
pathlib.Path(os.environ["COCKPIT_CONFIG_DIR"], "opencode.major").write_text("1\n")
wire(cp, {"healthy": True, "version": PIN_V1}, {"/config": {"permission": {"*": "allow"}}})
out = cp.collect_agent()
self.assertEqual(out["auto_live"], True)
self.assertIsNone(out.get("guard_ok"), "the v2 guard check is not done on 1.x")
self.assertEqual(out["pinned"], PIN_V1)
def test_a_1_x_server_on_a_box_with_no_marker_is_told_the_default_2_x_pin(self):
# Since v1.56.0 a plain ./install.sh brings OpenCode 2 (decision 1546), so a box with
# no marker yet (installed before v1.56.0) is told the 2.x pin beside its 1.x server:
# the Agent tab says ./install.sh brings it in line, which now means moving to 2.
cp = load("panel_v1_nomarker", UNIT_V1)
wire(cp, {"healthy": True, "version": PIN_V1}, {"/config": {"permission": {"*": "allow"}}})
out = cp.collect_agent()
self.assertEqual(out["pinned"], PIN_V2)
def test_the_version_line_is_read_as_opencode_answers_it(self):
# 2.x prints "opencode v2.3.0" where 1.x prints the number alone (measured F2): compared raw,
# the panel would say "restart to serve it" forever
+5 -3
View File
@@ -104,9 +104,11 @@ for _v in IMAGE SERVE_IMAGE STOCK_REPO STOCK_REV UNC_REPO UNC_REV FP8_REPO FP8_R
eval "[ -n \"\${$_v:-}\" ]" || die "install.sh no longer defines $_v (repo layout changed?)"
done
unset _v
# The OpenCode this box serves (./install.sh --opencode 2 wrote the marker): the config
# merges below write its compaction block in the v2 shape on such a box (oc-merge-limits.py
# reads OC_MAJOR), exactly as install.sh exports it for its own calls.
# The OpenCode this box serves, from the marker install.sh wrote (2 is the default since
# v1.56.0, 1 is ./install.sh --opencode 1; no marker means a pre-v1.56.0 box still serving
# 1.x, hence the fallback 1): the config merges below write its compaction block in the v2
# shape on such a box (oc-merge-limits.py reads OC_MAJOR), exactly as install.sh exports it
# for its own calls.
OC_MAJOR="$(head -1 "$CONFIG_DIR/opencode.major" 2>/dev/null || echo 1)"
export OC_MAJOR
+20 -1
View File
@@ -79,6 +79,11 @@ def pinned_default() -> str:
return re.search(r'^OPENCODE_VERSION="\$\{OPENCODE_VERSION:-([0-9.]+)\}"', INSTALL.read_text(), re.M).group(1)
def pinned2_default() -> str:
import re
return re.search(r'^OPENCODE2_VERSION="\$\{OPENCODE2_VERSION:-([0-9.]+)\}"', INSTALL.read_text(), re.M).group(1)
class TheOpencodePin(unittest.TestCase):
def setUp(self):
self.t = pathlib.Path(tempfile.mkdtemp(prefix="oc-pin-"))
@@ -803,6 +808,9 @@ class TheCockpitNamesThePin(Scratch, unittest.TestCase):
and reads that version out of install.sh, so the two can never name different ones."""
def test_the_cockpit_reads_the_installers_pin(self):
# Since v1.56.0 (decision 1546) the pin a box with no marker is told is the 2.x one,
# because that is what a plain ./install.sh installs by default; a box whose marker
# says 1 is told the 1.x pin, so its Agent tab does not nag it to move.
code = ("import importlib.util, os, sys\n"
"t = sys.argv[2]; open(t + '/api-key', 'w').write('k')\n"
"os.environ.update(COCKPIT_DRY_RUN='1', COCKPIT_CONFIG_DIR=t, COCKPIT_PORT='0',\n"
@@ -814,7 +822,13 @@ class TheCockpitNamesThePin(Scratch, unittest.TestCase):
cfg, home = self.scratch("oc-ck-cfg-"), self.scratch("oc-ck-")
r = subprocess.run(["python3", "-c", code, str(REPO), cfg], capture_output=True, text=True,
timeout=60, env={**os.environ, "HOME": home})
self.assertEqual(r.stdout.strip().splitlines()[-1], pinned_default(), r.stderr[-400:])
self.assertEqual(r.stdout.strip().splitlines()[-1], pinned2_default(),
"no marker: the default pin since v1.56.0 " + r.stderr[-400:])
for marker, want in (("1\n", pinned_default()), ("2\n", pinned2_default())):
(pathlib.Path(cfg) / "opencode.major").write_text(marker)
r = subprocess.run(["python3", "-c", code, str(REPO), cfg], capture_output=True, text=True,
timeout=60, env={**os.environ, "HOME": home})
self.assertEqual(r.stdout.strip().splitlines()[-1], want, f"marker {marker!r} " + r.stderr[-400:])
def test_the_agent_tab_says_when_it_serves_another_version(self):
js = (REPO / "dashboard" / "static" / "js" / "agent.js").read_text()
@@ -1011,6 +1025,11 @@ class AMissingOpencodeIsSaidPlainly(Scratch, unittest.TestCase):
# the config directory comes from here and goes with the test: made inside a child
# that has no TMPDIR, it was left in /tmp at every run (2026-10-03)
cfg, home = self.scratch("oc-none-cfg-"), self.scratch("oc-none-")
r = subprocess.run(["python3", "-c", code, str(REPO), cfg], capture_output=True, text=True,
timeout=60, env={"HOME": home, "PATH": "/usr/bin:/bin"})
# no marker: the pin a plain ./install.sh installs is the 2.x one since v1.56.0
self.assertEqual(r.stdout.strip().splitlines()[-1], f"False None {pinned2_default()}", r.stderr[-400:])
(pathlib.Path(cfg) / "opencode.major").write_text("1\n")
r = subprocess.run(["python3", "-c", code, str(REPO), cfg], capture_output=True, text=True,
timeout=60, env={"HOME": home, "PATH": "/usr/bin:/bin"})
self.assertEqual(r.stdout.strip().splitlines()[-1], f"False None {pinned_default()}", r.stderr[-400:])