-
Notifications
You must be signed in to change notification settings - Fork 0
Use Apple container system API for resident network recovery #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"); | ||
| } | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' srcRepository: 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.tsRepository: 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 || trueRepository: gitcommit90/1Helm Length of output: 2180 🌐 Web query:
💡 Result: In the Apple 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 || trueRepository: gitcommit90/1Helm Length of output: 2180 Check
🤖 Prompt for AI Agents |
||
| if (started.code !== 0) throw new Error(started.stderr.toString("utf8").trim() || "Apple container services could not restart"); | ||
| appleNetworkRepairAt = now(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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:
Repository: gitcommit90/1Helm
Length of output: 50373
🏁 Script executed:
Repository: gitcommit90/1Helm
Length of output: 50373
🏁 Script executed:
Repository: gitcommit90/1Helm
Length of output: 46275
Block mixed work types during Apple network repair.
The global and per-channel guards apply
> 1independently, so one active command and one active turn can pass together. A new terminal is not added toterminalSessionsuntil afterensureChannelComputerRunning, 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