Skip to content

Use Apple container system API for resident network recovery - #48

Merged
gitcommit90 merged 1 commit into
mainfrom
fix/apple-supported-network-restart
Aug 1, 2026
Merged

Use Apple container system API for resident network recovery#48
gitcommit90 merged 1 commit into
mainfrom
fix/apple-supported-network-restart

Conversation

@gitcommit90

@gitcommit90 gitcommit90 commented Aug 1, 2026

Copy link
Copy Markdown
Owner

The real Mac release gate proved Apple's plugin launch service is not addressable through launchctl. Network recovery now uses the supported container system stop/start API and refuses a shared-runtime bounce while other resident work is active.

Verified:

  • node --test test/channel-computers.mjs
  • npm run typecheck
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes
    • Improved Apple guest network recovery by checking for active terminals, commands, and agent activity before restarting shared services.
    • Updated network service recovery to use supported container restart operations.
    • Added clearer error reporting when services cannot be stopped.

Signed-off-by: Joseph Yaksich <gitcommit90@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Apple guest network recovery now defers during active work and restarts networking through Apple container system stop and system start commands. Tests verify both operations, and the fake container handles system stop.

Changes

Apple network recovery

Layer / File(s) Summary
Guarded Apple container restart
src/server/channel-computers.ts, test/channel-computers.mjs, test/fake-container.mjs
Recovery checks active terminals, commands, and agent turns before restarting services. It uses system stop and system start, reports stop failures, and updates test support and assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • gitcommit90/1Helm#30: Both changes update channel-computer networking behavior and tests.
  • gitcommit90/1Helm#46: Both changes update Apple guest-network recovery and service restart behavior.
  • gitcommit90/1Helm#47: Both changes replace the vmnet launchctl restart with container system stop/start operations.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and lists some verification, but it omits the required change type, release notes, acceptance ledger, and post-merge sections. Add the missing template sections, mark the applicable change type, provide release-note status, complete the acceptance ledger, and record all verification checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: using the Apple container system API for resident network recovery.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/apple-supported-network-restart

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 2

🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/server/channel-computers.ts`:
- Around line 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.
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: db6641db-03e5-4206-8299-082d87599dc1

📥 Commits

Reviewing files that changed from the base of the PR and between 4610efe and b011af5.

📒 Files selected for processing (3)
  • src/server/channel-computers.ts
  • test/channel-computers.mjs
  • test/fake-container.mjs

Comment on lines +595 to 599
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");
}

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.

Comment on lines +600 to +602
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");

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.

@gitcommit90
gitcommit90 merged commit c232d30 into main Aug 1, 2026
6 checks passed
@gitcommit90
gitcommit90 deleted the fix/apple-supported-network-restart branch August 1, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant