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
30 changes: 30 additions & 0 deletions loopx/agy_goal_mode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,38 @@ and audit-continuation) with `quota should-run` (advisory guidance; LoopX
does not intercept native host continuations), and arm the next bounded
wake with the native `schedule` tool only when quota allows more work.

## Reboot-Survival Watchdog (`antigravity-app` on macOS)

In-session `schedule(...)` timers suspend while Antigravity is running, so an
OS reboot or Antigravity Language Server restart clears in-memory timers.
`loopx.agy_goal_mode.host_runtime` provides two guarded subcommands for
surviving restarts without disturbing healthy `swarm_wait` or `schedule` sleeps:

- `heartbeat-tick`: discovers the running Antigravity Language Server, reads
`trajectorySummaries[<conversation-id>]` (`status` and `lastModifiedTime`)
and `ps -o lstart= -p <ls_pid>`, checks Core admission (`quota should-run --scheduler-observation`)
only when eligible, acquires an exclusive file lock before sending
`SendUserCascadeMessage`, and wakes **only** when `status == "CASCADE_RUN_STATUS_IDLE"` and either:
1. `ls_start_epoch > last_modified_epoch + 5.0` (proven OS reboot or LS restart
since the last turn, deduped once per `last_woken_ls_pid`), **or**
2. `now - last_modified_epoch >= long_idle_seconds` (default `2400`s / 40m
stall fallback, bounded by `>= 1800`s cooldown).
- `install-launchd`: previews (default dry-run) or installs/unloads a
`~/Library/LaunchAgents/<label>.plist` (`RunAtLoad=true`, `StartInterval=300`,
resolved absolute `--registry`/`--runtime-root`/`--state-dir`/`--log-dir`, and
captured `PATH`) running `heartbeat-tick` with `--execute` (or
`--uninstall --execute`, verifying via `launchctl print` that the job is
unloaded or absent before removing the plist).

```bash
python3 -E -P -m loopx.agy_goal_mode.host_runtime install-launchd \
--goal-id <goal-id> --agent-id <agent-id> --conversation-id <conversation-id> --execute
```

## Layout

- `__init__.py` — host facts: install surface id, fixed skills root resolution,
activation extras (advisory quota pacing and continuation boundaries),
and the native goal + wake primitives the activation cites.
- `host_runtime.py` — stdio `Stop` hook recovery and guarded `heartbeat-tick` / LaunchAgent CLI.
- `launchd_watchdog.py` — macOS LaunchAgent plist builder and `launchctl` lifecycle helper.
33 changes: 33 additions & 0 deletions loopx/agy_goal_mode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,30 @@ def build_antigravity_hooks_template(
}


def build_antigravity_launchd_command(
*,
cli_bin: str = "loopx",
goal_id: str | None = None,
agent_id: str | None = None,
runtime_root: str | None = None,
conversation_id: str | None = None,
registry: str | None = None,
resolve_local_executable: bool = True,
) -> list[str]:
"""Return argv to preview or install the reboot-surviving LaunchAgent watchdog."""
conversation_id = conversation_id or os.environ.get(ANTIGRAVITY_CONVERSATION_ID_ENV)
return _antigravity_provider_args(
"install-launchd",
cli_bin=cli_bin,
goal_id=goal_id,
agent_id=agent_id,
conversation_id=conversation_id,
runtime_root=runtime_root,
registry=registry,
resolve_local_executable=resolve_local_executable,
)


def agy_activation_extras() -> dict[str, Any]:
"""Keyword overrides for ``agy_cli_activation``'s facade call.

Expand Down Expand Up @@ -374,6 +398,14 @@ def antigravity_app_activation_extras(
registry=registry,
resolve_local_executable=False,
)
launchd_command = build_antigravity_launchd_command(
cli_bin=cli_bin,
goal_id=goal_id,
agent_id=agent_id,
runtime_root=runtime_root,
registry=registry,
resolve_local_executable=False,
)
wake_prompt = sidecar_template["sidecar"]["loopx-heartbeat"]["bootstrap_prompt"]
return {
"activation_method": "bind_antigravity_schedule_loop_and_sidecar",
Expand All @@ -391,6 +423,7 @@ def antigravity_app_activation_extras(
"host_mcp_config": ANTIGRAVITY_MCP_CONFIG_LABEL,
"host_hooks_config": ANTIGRAVITY_HOOKS_CONFIG_LABEL,
"host_sidecar_config": ANTIGRAVITY_SIDECAR_CONFIG_LABEL,
"reboot_watchdog_command": shlex.join([*launchd_command, "--execute"]),
"in_session_schedule_call": {
"tool": "schedule",
"arguments": {
Expand Down
Loading
Loading