Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/server/channel-computers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,14 @@ async function repairAppleGuestNetwork(computer: ChannelComputer): Promise<void>
// Avoid repeatedly bouncing shared vmnet while several machines detect
// the same fleet-wide outage during one reconciliation pass.
if (now() - appleNetworkRepairAt > 30_000) {
if (platform() === "darwin") {
const label = `gui/${process.getuid?.() ?? 501}/com.apple.container.network.container-network-vmnet.default`;
const kicked = await spawnCollected("/bin/launchctl", ["kickstart", "-k", label], { timeoutMs: 30_000 });
if (kicked.code !== 0) throw new Error(kicked.stderr.toString("utf8").trim() || "Apple shared VM network service could not restart");
const activeCommands = Number(q1("SELECT COUNT(*) n FROM channel_computer_obligations WHERE kind='command' AND status='active'")?.n || 0);
const activeTurns = Number(q1("SELECT COUNT(*) n FROM agent_turns WHERE state='running'")?.n || 0);
if (terminalSessions.size > 0 || activeCommands > 1 || activeTurns > 1) {
throw new Error("resident computer network is unavailable; automatic repair is waiting for concurrent work to finish");
}
Comment on lines +595 to 599

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 12 \
  -e 'repairAppleGuestNetwork\s*\(' \
  -e 'channel_computer_obligations' \
  -e 'agent_turns' \
  -e 'terminalSessions\.(add|set|delete)' \
  src/server

Repository: gitcommit90/1Helm

Length of output: 50373


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- repair function and surrounding state ---'
sed -n '1,120p;560,630p;800,870p;900,1015p;1280,1330p;1490,1555p' src/server/channel-computers.ts

printf '%s\n' '--- command obligation call sites ---'
rg -n -C 5 'upsertObligation\([^;]*command|satisfyObligation\([^;]*command|kind[[:space:]]*=[[:space:]]*["'\'']command|["'\'']command["'\'']' src/server --glob '*.ts'

printf '%s\n' '--- running-turn creation and lifecycle call sites ---'
rg -n -C 5 'INSERT INTO agent_turns|claimAgentTurn|finalizeAgentTurn|state=.running.|state=.queued.' src/server --glob '*.ts'

printf '%s\n' '--- terminal session lifecycle ---'
rg -n -C 5 'terminalSessions\.(set|delete)|repairAppleGuestNetwork|ensureChannelComputerRunning' src/server/channel-computers.ts

Repository: gitcommit90/1Helm

Length of output: 50373


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- agent-turn creation and command-tool path ---'
rg -n -C 8 \
  -e 'INSERT INTO agent_turns' \
  -e 'claimAgentTurn\(' \
  -e 'runChannelCommand\(' \
  -e 'execute.*tool|tool.*execute|computer_command|command' \
  src/server/turns.ts src/server/bots.ts src/server --glob '*.ts' \
  | head -n 500

printf '%s\n' '--- exact guard predicates ---'
python3 - <<'PY'
from pathlib import Path
p = Path("src/server/channel-computers.ts").read_text()
start = p.index("async function repairAppleGuestNetwork")
end = p.index("const isolatedBackend", start)
print(p[start:end])
PY

printf '%s\n' '--- deterministic mixed-work verifier ---'
python3 - <<'PY'
def global_allows(terminals, commands, turns):
    return not (terminals > 0 or commands > 1 or turns > 1)

def channel_allows(channel_terminals, channel_commands, channel_turns):
    return not (channel_terminals or channel_commands > 1 or channel_turns > 1)

cases = [
    ("current command + unrelated turn, global", global_allows(0, 1, 1)),
    ("current command + unrelated turn, same channel", channel_allows(False, 1, 1)),
    ("two commands", global_allows(0, 2, 0)),
    ("two turns", global_allows(0, 0, 2)),
]
for name, allowed in cases:
    print(f"{name}: {'ALLOWS_RESTART' if allowed else 'BLOCKS_RESTART'}")
PY

Repository: gitcommit90/1Helm

Length of output: 46275


Block mixed work types during Apple network repair.

The global and per-channel guards apply > 1 independently, so one active command and one active turn can pass together. A new terminal is not added to terminalSessions until after ensureChannelComputerRunning, so an active command can also coexist with that terminal's repair. Pass the current operation identity into both checks and block when any other command, running turn, or terminal session is active.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/channel-computers.ts` around lines 595 - 599, Update the repair
guard around activeCommands, activeTurns, and terminalSessions to receive the
current operation identity and exclude only that operation from each activity
check. Block repair whenever any other command, running turn, or terminal
session is active, including mixed command-and-turn work and the terminal being
repaired before it is registered in terminalSessions.

const stopped = await apple(["system", "stop"], { timeoutMs: 90_000 });
const started = await apple(["system", "start"], { timeoutMs: 90_000 });
if (stopped.code !== 0) throw new Error(stopped.stderr.toString("utf8").trim() || "Apple container services could not stop for network recovery");
Comment on lines +600 to +602

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- candidate file map ---'
ast-grep outline src/server/channel-computers.ts
printf '%s\n' '--- target implementation ---'
sed -n '540,635p' src/server/channel-computers.ts
printf '%s\n' '--- related symbols and call sites ---'
rg -n -C 3 'repairAppleGuestNetwork|active commands|agent turns|system stop|system start' src

Repository: gitcommit90/1Helm

Length of output: 25506


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- lock and activity state ---'
sed -n '88,145p' src/server/channel-computers.ts
printf '%s\n' '--- command and turn admission paths ---'
rg -n -C 5 'channel_computer_obligations|kind=.command|status=.active|agent_turns|state=.running|withChannelLock|canStopChannelComputer' src/server
printf '%s\n' '--- stop/restart callers ---'
sed -n '820,875p' src/server/channel-computers.ts
sed -n '1348,1385p' src/server/channel-computers.ts
sed -n '1488,1550p' src/server/channel-computers.ts

Repository: gitcommit90/1Helm

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -e
python3 - <<'PY'
from pathlib import Path
import re

path = Path("src/server/channel-computers.ts")
text = path.read_text()
start = text.index("async function repairAppleGuestNetwork")
end = text.index("\nconst isolatedBackend", start)
body = text[start:end]
lines = body.splitlines()

stop = next(i for i, line in enumerate(lines) if 'apple(["system", "stop"]' in line)
start_cmd = next(i for i, line in enumerate(lines) if 'apple(["system", "start"]' in line)
stop_check = next(i for i, line in enumerate(lines) if "stopped.code !== 0" in line)
start_check = next(i for i, line in enumerate(lines) if "started.code !== 0" in line)

print({
    "system_stop_relative_line": stop + 1,
    "system_start_relative_line": start_cmd + 1,
    "stop_check_relative_line": stop_check + 1,
    "start_check_relative_line": start_check + 1,
    "start_precedes_stop_check": start_cmd < stop_check,
    "start_failure_message_uses_stopped_stderr": "started.code !== 0" in lines[start_check]
    and "stopped.stderr" in lines[start_check],
})

# Read-only control-flow probe for the relevant sequence.
events = []
stopped_code = 1
events.append("system stop")
if True:  # current source invokes start before evaluating stopped.code
    events.append("system start")
if stopped_code != 0:
    events.append("throw stop error")
print({"stop_failure_event_order": events})
PY

printf '%s\n' '--- Apple container CLI references in repository ---'
rg -n -i -C 2 'container (system|service)|system (start|stop)|vmnet' README.md docs src package.json 2>/dev/null || true

Repository: gitcommit90/1Helm

Length of output: 2180


🌐 Web query:

Apple container CLI 1.1.0 container system stop container system start semantics

💡 Result:

In the Apple container CLI version 1.1.0, the container system commands manage the lifecycle of the core background services required for the platform to function [1]. container system start This command initializes the container platform's services, specifically launching the container-apiserver (a launch agent) [1]. Starting these services is a prerequisite for creating and managing containers [2][3]. When executed, it also creates a vmnet network named default to which containers will attach by default [4]. container system stop This command terminates the container services and deregisters them from launchd [5][6]. Running this command stops the container-apiserver, effectively shutting down the background infrastructure [1]. Users are typically instructed to run this command when they need to fully stop the platform or perform system-level tasks such as upgrades or downgrades [2][7][8]. Summary of Semantics - System Lifecycle: The container system commands control the global state of the background API server and associated helpers, rather than the state of individual user containers [1]. - Persistence: Individual containers are managed via container stop and container start [2]. While stopping the system service shuts down the platform, individual container states may not always be gracefully persisted or updated in the CLI's view if the system is interrupted unexpectedly; users are advised to manually stop containers if necessary before performing maintenance [9]. - Configuration: Both commands support a --prefix option (defaulting to com.apple.container.), which allows users to target specific service instances managed by launchd [5][6].

Citations:


🏁 Script executed:

#!/bin/bash
set -e
python3 - <<'PY'
from pathlib import Path

path = Path("src/server/channel-computers.ts")
text = path.read_text()
start = text.index("async function repairAppleGuestNetwork")
end = text.index("\nconst isolatedBackend", start)
lines = text[start:end].splitlines()

stop = next(i for i, line in enumerate(lines) if 'apple(["system", "stop"]' in line)
start_cmd = next(i for i, line in enumerate(lines) if 'apple(["system", "start"]' in line)
stop_check = next(i for i, line in enumerate(lines) if "stopped.code !== 0" in line)
start_check = next(i for i, line in enumerate(lines) if "started.code !== 0" in line)

print({
    "system_stop_relative_line": stop + 1,
    "system_start_relative_line": start_cmd + 1,
    "stop_check_relative_line": stop_check + 1,
    "start_check_relative_line": start_check + 1,
    "start_precedes_stop_check": start_cmd < stop_check,
    "start_failure_message_uses_stopped_stderr": "started.code !== 0" in lines[start_check]
    and "stopped.stderr" in lines[start_check],
})

events = []
stopped_code = 1
events.append("system stop")
events.append("system start")
if stopped_code != 0:
    events.append("throw stop error")
print({"stop_failure_event_order": events})
PY

printf '%s\n' '--- Apple container CLI references in repository ---'
rg -n -i -C 2 'container (system|service)|system (start|stop)|vmnet' README.md docs src package.json 2>/dev/null || true

Repository: gitcommit90/1Helm

Length of output: 2180


Check stopped.code before calling system start.

system start executes even when system stop fails. Throw on a failed stop immediately, then start services only after a successful stop. Preserve started.stderr for the start failure message.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/channel-computers.ts` around lines 600 - 602, Update the Apple
service recovery flow around the stopped and started commands to validate
stopped.code immediately after the system stop call, throwing with
stopped.stderr on failure before invoking system start. Only call system start
after a successful stop, and retain started.stderr for reporting start failures.

if (started.code !== 0) throw new Error(started.stderr.toString("utf8").trim() || "Apple container services could not restart");
appleNetworkRepairAt = now();
}
Expand Down
3 changes: 2 additions & 1 deletion test/channel-computers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ test("Apple channel-computer contract preserves isolation, files, wakes, archive
assert.ok(calls.some((call) => call.includes("-w") && call.includes("/workspace") && call.some((word) => word.includes("/bin/bash")) && call.some((word) => word.includes("-lc"))), "resident commands execute in the correct VM workspace");
assert.equal(db.q1("SELECT disk_bytes FROM channel_computers WHERE channel_id=?", beta.channelId).disk_bytes, computers.MANAGED_CHANNEL_DISK_BYTES, "reported storage is the managed writable allocation, not Apple's host-backed virtual capacity");
const backend = await readFile(join(root, "src", "server", "channel-computers.ts"), "utf8");
assert.match(backend, /com\.apple\.container\.network\.container-network-vmnet\.default/, "network recovery restarts Apple's installed vmnet launch service");
assert.match(backend, /apple\(\["system", "stop"\]/, "network recovery uses Apple's supported service stop operation");
assert.match(backend, /apple\(\["system", "start"\]/, "network recovery uses Apple's supported service start operation");
assert.match(backend, /terminal \? \["-it"\] : pipeInput \? \["-i"\]/, "Apple terminal and streamed-stdin invocations request the exact interactive mode they need");
assert.match(backend, /isolatedInvocation\(\["\/bin\/bash", "-l"\][\s\S]*true\)/, "interactive isolated terminals request an explicit guest login shell");
assert.match(backend, /args: \[\.\.\.words, \.\.\.guestWords\(\.\.\.args\)\]/, "Apple guest argv remains quoted for the runtime's documented second shell parse");
Expand Down
1 change: 1 addition & 0 deletions test/fake-container.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if (args[0] === "system" && args[1] === "status") {
process.stdout.write(JSON.stringify({ status: "running" }));
process.exit(0);
}
if (args[0] === "system" && args[1] === "stop") process.exit(0);
if (args[0] === "system" && args[1] === "start") {
for (const entry of readdirSync(join(stateRoot, "machines"))) rmSync(join(stateRoot, "machines", entry, ".network-down"), { force: true });
process.exit(0);
Expand Down
Loading