GUARDS Debug
Invocation: Start only when the user explicitly requests this workflow.
Diagnose and recover agy-guards sessions, projected hooks, spoke subagents, and unattended factory shifts from outside an activated GUARDS conversation.
Inside an active GUARDS run, self-protection hooks restrict reads to <workspace_root> and block ~/.gemini/, guards.sqlite3, and agy-guards control commands (leaving only internal /guards-check-health). Run this workflow from an external shell or agent session started outside <workspace_root>.
Hard rules
- Stay outside
<workspace_root>: Never launch a secondagyhost inside<workspace_root>while diagnosing it; single-agyownership scans/proc(cwdand--add-dir) and activated callers in$XDG_STATE_HOME/agy-guards/hook-callers/(or~/.local/state/agy-guards/hook-callers/) trigger self-protection denials. - Never expose raw credentials: Never print or copy secret values from
~/.config/agy-guards/credentials($GUARDS_CREDENTIALS_FILE/$XDG_CONFIG_HOME/agy-guards/credentials) or~/.gemini/*/antigravity-oauth-token. Check credential health viaagy-guards doctor. - Bound
monitorcalls: Never run bareagy-guards monitor <workspace_root> <session_id> --followsynchronously on a stalled non-terminal session;--followloops every 500ms until a terminal state and blocks the agent turn indefinitely. Default to non-following dumps (--jsonor--since <secs>), or wrap live tailing withtimeout 15sor a background task. - Snapshot before recovery, confirm before acting: Capture diagnostic logs and uncommitted spoke worktree diffs before proposing
approve,gc,reset, or terminating stuck processes, and run each of those only after explicit user confirmation. - Preserve store and receipt integrity: Never mutate
guards.sqlite3with raw SQL or hand-edit~/.gemini/config/hooks.jsonoragy-guards-installation.receipt.json. Useagy-guardssubcommands andagy-guards-installer.
1. Establish external vantage and live processes
Identify <workspace_root> (canonical path to the customer repository) and optional <session_id> (42, review-pr-13, batch-20261029, wave-batch-20261029, or run-chores-20261027-001).
Check live agy and agy-guards processes before reading or mutating state so you can distinguish active execution from orphaned locks:
agy-guards --version
pgrep -af 'agy-guards|(^|/)agy( |$)' || true
When PIDs are present on Linux, inspect /proc/<pid>/cwd and /proc/<pid>/cmdline to see which <workspace_root>, --spoke, or factory instance owns each process.
2. Run read-only CLI triage in order
Run the read-only agy-guards diagnostics in this sequence:
-
Run
doctorfirst (beforeinspect, becauseinspectauto-migrates a behind-versionguards.sqlite3schema and masksSchemaFit::Behind):agy-guards doctor <workspace_root> [session_id] --recent-hours 48Pass
--installation-receipt <path>when diagnosing a factory shift that uses a custom receipt path. Inspectoverall(healthy,attention,broken), projectchecks(store,sessions,readiness,logs,open_calls,caller_identity,recent_errors,github,installation,factory_installation,sandbox), andsession(status,phase,last_spoke,open_calls,errors,slow_calls,deliverables,gaps,verdict). -
Dump stored GUARDS state and events:
agy-guards inspect <workspace_root> [session_id]If
<session_id>was unknown, pick the target session key frominspectoutput. -
Obtain the merged session timeline via
monitor:agy-guards monitor <workspace_root> <session_id> --jsonUse
--since <secs>to narrow noisy histories, or omit--jsonfor the human table (HH:MM:SS <audit|store|server> <start|end|KIND|level> <summary>). Exit code2indicates nothing is recorded for<session_id>in eitherguards.sqlite3orlogs/<session_id>/. When watching a genuinely active session advance, bound--followexplicitly:timeout 15s agy-guards monitor <workspace_root> <session_id> --follow -
Check published MCP tool surfaces when investigating tool-call errors or binary upgrades:
agy-guards tools agy-guards tools --spoke
3. Correlate GUARDS logs, ~/.gemini transcripts, and factory state
- Read log-and-state-map.md when resolving
<state_base>($XDG_STATE_HOME/agy-guardsor~/.local/state/agy-guards), decodingserver.log/audit.log/error.logfields, locating~/.gemini/brain transcripts, inspectingFACTORY_LEDGER.ndjson, or enablingGUARDS_LOG=debug. - Read failure-modes.md to match
doctorwarnings, hook denials, spoke continuation stalls, 128 KiB transcript tail cutoffs, MCP cache drift, or/proclock collisions to root causes andcrates/agy-guards/source files.
Join evidence across the three runtime layers:
-
GUARDS JSONL logs (
<state_base>/<owner>__<repo>/logs/):- Inspect
logs/<session_id>/{error.log,audit.log,server.log}(plus project-levellogs/and subsystem directoriesspoke-continuations/,crew/,cleanup/,workflow-invocations/,feedback-publications/,publication-journal/). - Search
server.logexplicitly for"hook denied"andagy_guards::panic;doctorexcludes"hook denied..."policy enforcements fromrecent_errorseven when a mis-scoped denial wedges an agent loop. - Extract
conversationUUIDs (hubandspokeentries inaudit.logorPROD_SENTevents) and unmatchedcall_idvalues.
- Inspect
-
Antigravity host state (
~/.gemini/antigravity-cli/or~/.gemini/antigravity/):- If
audit.loglacksconversation(missing_caller), look up<workspace_root>in~/.gemini/antigravity-cli/cache/last_conversations.jsonandconversation_metadata.json. - Inspect
<agy_app_dir>/brain/<conversationId>/.system_generated/:logs/transcript.jsonlandlogs/transcript_full.jsonlforUSER_INPUT,PLANNER_RESPONSE,TOOL_CALL, andask_questioncompletions (rememberingagy-guardsreads only the last 128 KiB tail for approvals and interview answers).steps/andtasks/task-*.logfor spoke progress (SPOKE_WAIT_PROGRESS) or stuck interactive prompts.messages/for queuedsend_messageprods between hub and spoke.
- Check
cli.log(MCP stdiostderr, includingFileLayerwrite failures and projected-hook errors),crashes/crash_*.log, cached schemas inmcp/{guards_hub,guards_spoke}/, and spoke worktrees inworktrees/<hubConversationId>/subagent-*.
- If
-
Unattended factory shifts (see ../guards-run-factory/SKILL.md):
- Inspect
<workspace_parent>/guards-factory/<repo-name>/(or--state-dir) forFACTORY_START_FAILURE.md,FACTORY_LEDGER.ndjson(seq,channel,conversation,payload), andFACTORY_REPORT.md, plus workspace lock files under~/.local/share/guards-factory/locks/.
- Inspect
4. Snapshot evidence and run confirmed recovery
Before running any recovery action, save a diagnostic bundle to a temporary scratch directory so bug evidence survives cleanup or resets:
snap_dir="$(mktemp -d "${TMPDIR:-/tmp}/guards-debug-XXXXXX")"
agy-guards doctor <workspace_root> [session_id] --recent-hours 48 >"$snap_dir/doctor.json" 2>&1 || true
agy-guards inspect <workspace_root> [session_id] >"$snap_dir/inspect.json" 2>&1 || true
agy-guards monitor <workspace_root> <session_id> --json >"$snap_dir/monitor.jsonl" 2>&1 || true
If spoke worktrees exist under ~/.gemini/antigravity-cli/worktrees/<hubConversationId>/, also capture git -C <spoke_worktree> status --porcelain and git -C <spoke_worktree> diff into "$snap_dir" before reaping them.
Diagnosis and snapshotting run without asking. Every recovery command below changes run state, opens a human gate, kills a process, or deletes data, so propose it to the user with the evidence that justifies it and run it only after they explicitly confirm that specific command. Propose the narrowest sufficient action first:
-
Open a verified parked bundle gate:
agy-guards approve <workspace_root> <issue_number> -
Garbage-collect leaked spoke worktrees:
agy-guards gc <workspace_root> -
Terminate wedged
agyoragy-guardsprocesses when a hung host or orphaned MCP process blocks workspace ownership orDoor::Resetlive-owner checks (SIGTERMfirst, verify/proc/<pid>exit, thenSIGKILLonly if still alive). -
Reset run state (all three scopes preserve
artifacts/):-
Single issue first (clears one issue’s session, gates, approvals, and events):
agy-guards reset <workspace_root> <issue_number> -
Project-wide store reset when multiple sessions or store state in
<workspace_root>must be cleared:agy-guards reset <workspace_root> -
Global factory reset across every project in
<state_base>when cross-project factory test state must be wiped:agy-guards reset --factory
-
After each confirmed action, re-run agy-guards doctor <workspace_root> to confirm clean state before proposing the next one.
5. Produce the root-cause report
Conclude every investigation with a concise, evidence-backed report:
- Symptom and scope: workspace,
<session_id>(or factory shift), GUARDS phase, and failure mode. - Correlated timeline: ordered events joining
agy-guards(audit.log/server.log/guards.sqlite3) with~/.gemini/(transcript.jsonl,tasks/,messages/,cli.log) orFACTORY_LEDGER.ndjsonvia<conversationId>andcall_id. - Root cause and source boundary: exact invariant, hook policy, MCP schema/transport mismatch, transcript window limit, or host condition responsible. When the
plugin-agy-guardscheckout (crates/agy-guards/andantigravity/) is present locally, cite the responsible files and functions using failure-modes.md; modify plugin source code only if the user asked for a fix. - Recovery and verification: path to saved diagnostic snapshot (clean up temporary scratch files if no longer needed), recovery commands the user confirmed and you executed, and final
agy-guards doctorstatus.