| name | gateway-restart |
| description | Gracefully restart the KiroCrew gateway from within a running agent session, preserving conversation continuity via scheduled resume jobs. Use when user says "restart yourself", "restart gateway", "reload config", or after config changes that require a restart. |
| triggers | restart, reload, restart yourself, restart gateway, apply changes, reload config |
Gateway Restart
Overview
Gracefully restart the KiroCrew gateway from within a running agent session. The challenge: kirocrew restart is blocked by kiro-cli's security filter, and killing the gateway kills the current session. This skill teaches the agent to schedule the restart externally and resume the conversation afterward.
Core Concepts
The Problem
The agent cannot directly run kirocrew restart — kiro-cli blocks it. Even if it could, the restart would kill the agent mid-response. The solution is a two-phase approach: schedule resume jobs, then trigger the restart via a mechanism that runs outside the agent session.
Restart Mechanism
The agent cannot run kirocrew restart directly — kiro-cli's security filter blocks it at the shell command level (regex match on the command string). Platform-specific scripts handle this indirectly:
Linux / macOS:
nohup /path/to/skills/gateway-restart/do-restart.sh >/dev/null 2>&1 & disown
The script sleeps 10 seconds (giving the session time to respond), then invokes the restart. Because it's a detached process reparented to PID 1, it survives the gateway's death and executes reliably.
Windows:
$kiroBin = (Get-Command kirocrew).Source
$logFile = Join-Path $env:USERPROFILE ".kiro\crew\logs\restart.log"
Start-Process -WindowStyle Hidden powershell -ArgumentList "-ExecutionPolicy", "Bypass", "-File", "`"<path>\do-restart.ps1`"", "-KirocrewBin", "`"$kiroBin`"", "-LogFile", "`"$logFile`""
The PowerShell script (do-restart.ps1) accepts -KirocrewBin (the resolved absolute path to kirocrew.exe) and -LogFile (optional, for diagnosing silent failures). It sleeps 10 seconds, then calls the binary. Start-Process -WindowStyle Hidden creates a detached process that survives the gateway's death. Unlike Unix, Windows has no nohup/disown — Start-Process with -WindowStyle Hidden is the equivalent pattern for fire-and-forget background work.
Important: Always resolve kirocrew to an absolute path at schedule time (before the detached process launches). A hidden process may not inherit the same PATH as the agent session — this is the documented Windows reality. If resolution fails, the script falls back to PATH lookup and then to python -m kiro_crew.cli restart via the venv Python. All path arguments passed to Start-Process -ArgumentList must be wrapped in escaped quotes (`"..`") to handle paths containing spaces (e.g. C:\Users\John Smith\...).
Resume Jobs
Before triggering the restart, schedule LLM-mode cron jobs that fire after the gateway comes back up. These resume the conversation in the same thread:
cron_add(
name="restart-resume-fast",
delay=60,
channel="<channel_id>",
thread_ts="<thread_ts>",
message="Gateway restarted successfully. [Describe pending work if any]. Remove the job named 'restart-resume-slow'.",
)
cron_add(
name="restart-resume-slow",
delay=300,
channel="<channel_id>",
thread_ts="<thread_ts>",
message="Gateway restarted (slow path). [Describe pending work if any].",
)
- Fast (60s): Fires once the gateway has restarted and initialized (~15s restart + buffer). Its message includes an instruction to delete the slow backup job.
- Slow (5 min): Backup in case startup takes longer than expected.
- Thread targeting: Both MUST include
channel and thread_ts so the resume appears in the original conversation.
- Clean exit: The resume cron should always acknowledge the restart ("Back online."). If there's pending work, continue it. If not, acknowledge and end the session promptly to avoid stale "Cron: restart-resume-*" sessions in the dashboard.
Procedure
1. Clean up stale restart jobs
List crons and remove any leftover jobs from a previous restart by matching their names:
The cron_remove tool requires the job ID (not the name), so list first, match by name, then remove by ID.
2. Schedule resume jobs
Always schedule both fast and slow resume jobs with the current channel and thread context. If there's pending work, describe it in the message so the resumed session knows what to continue.
3. Schedule the restart
Launch the bundled script as a detached process:
Linux / macOS:
nohup /path/to/skills/gateway-restart/do-restart.sh >/dev/null 2>&1 & disown
Windows:
$kiroBin = (Get-Command kirocrew).Source
$scriptPath = Join-Path (Split-Path $PSScriptRoot) "skills\gateway-restart\do-restart.ps1"
if (-not (Test-Path $scriptPath)) { $scriptPath = "$env:USERPROFILE\.kiro\crew\skills\gateway-restart\do-restart.ps1" }
$logFile = "$env:USERPROFILE\.kiro\crew\logs\restart.log"
Start-Process -WindowStyle Hidden powershell -ArgumentList "-ExecutionPolicy", "Bypass", "-File", "`"$scriptPath`"", "-KirocrewBin", "`"$kiroBin`"", "-LogFile", "`"$logFile`""
The script's 10-second delay gives the current session time to finish responding.
Path resolution: On both platforms, use the installed skill path (~/.kiro/crew/skills/gateway-restart/). The <path> in the Restart Mechanism section above is the same directory.
4. Confirm to user
Gateway restart scheduled. It will restart in ~10 seconds. I'll resume automatically afterward.
When to Restart
- User explicitly asks ("restart yourself", "reload")
- Config change made that requires restart (
config.json, mcp.json, agent files)
- After applying a KiroCrew update (see self-update skill)
- After changing the gateway model (
kirocrew config set model <X>)
Consent and Offering Restarts
Never restart without the user's knowledge. The user should never be surprised by a restart.
When a restart is needed (but user didn't ask for one)
If you make a config change or apply an update that requires a restart, inform and offer — do not restart automatically:
I've updated the config. A gateway restart is needed for this to take effect. Want me to restart now?
Only proceed with the restart if the user confirms.
Learning automatic restart permission
If the user grants blanket permission for a specific scenario (e.g. "yes, always restart after auto-updates"), save it as a lesson:
learn_add(
rule="Okay to automatically restart the gateway after applying a KiroCrew update.",
category="preference",
)
In future sessions, if that lesson exists, you may restart without re-asking for that specific scenario. But only for the scenario the user explicitly approved — not as general permission.
Setting up automatic updates
When configuring an auto-update cron (see self-update skill), explicitly mention that updates require a restart and ask for consent:
Auto-updates will check for and apply new versions. After applying an update, I'll need to restart the gateway for it to take effect. Should I restart automatically, or notify you first?
Save the user's answer as a lesson so the auto-update cron knows whether to restart or just notify.
Common Mistakes
- Forgetting resume jobs — the restart completes but nobody resumes the conversation. Always schedule both fast and slow.
- Forgetting
channel and thread_ts — resume fires as a disconnected DM instead of replying in the original thread.
- Not cleaning up the slow job — the fast resume message MUST instruct the agent to remove
restart-resume-slow.
- Setting delay too short — if the restart cron fires before the agent finishes responding, the response is lost. 10 seconds is safe.
- Windows: inline Python
-c scripts via Start-Process — nested quotes and backslash paths break PowerShell argument passing. Always use a script file (do-restart.ps1), never an inline -c "..." command.
- Windows: using bash/nohup/disown — these don't exist on Windows. Use
Start-Process -WindowStyle Hidden powershell instead.