Monitors & Reactive Wake-Ups
Long builds, test suites, file locks held by sibling agents, GPU/RAM admission queues, and crawl jobs all share the same failure mode in naive agent harnesses: the agent resorts to sleep 30, shell while polling loops, or timeout 600 ... wrappers that burn tokens, tie up worker slots, and miss host-side kills.
Kompile replaces polling with host-managed, event-driven monitors. The Enforcer (ShellMandatePolicy) deterministically blocks sleep, shell wait loops, and timeout <duration> <cmd> / gtimeout — and Kompile's monitor layer wakes the agent automatically as soon as the watched process exits, the file lock clears, or the resource lane opens.
Architecture: How Reactive Wake-Ups Flow
flowchart LR
subgraph Sources["Watched Events"]
P["Background Processes\nprocess action=launch / monitor\n(local + shared pool)"]
N["Standing Subscriptions\nprocess_notify / process notify\n(ProcessNotificationHub)"]
E["Edit Locks\nedit_coordinator monitor_edit"]
L["Named Locks & RAM/GPU Lanes\nacquire_lock • wait_for_activity"]
C["Crawl Jobs\ncrawl_control monitor"]
end
subgraph Delivery["Surface-Aware Delivery"]
BUS["Coordination Bus & Pending Queue\n.kompile/coordination/\n.pending-events.json (survives restarts)"]
CHAT["Kompile CLI & Web Chat\nAutomatic wake.* turn delivery"]
MCP["External MCP Hosts\nnotifications/message or wakeSupported=false hint"]
end
P --> BUS
N --> BUS
E --> BUS
L --> BUS
C --> CHAT
BUS --> CHAT
BUS --> MCP1. Process Completion Monitors (process)
Every background process launched through process action=launch is monitored by default (BackgroundProcessManager.launchMonitored):
- Required by the harness: even if an agent passes
monitor=false, Kompile forces a completion monitor on launch (monitorForced: true) so background jobs are never orphaned silently. - Custom wake-up instructions (
monitor_message): attach a short reminder of what to do on exit (for example, "Inspect proc-042 output; if green, run integration tests"). Kompile echoes it right inside the completion wake-up. - Host-side runtime limits (
timeout_minutes&/process-config): instead of shelltimeout, passtimeout_minutes(or configure defaults via/process-config set maxRuntimeMinutes .../testTimeoutMinutes). The host watchdog enforces the limit, records the termination reason, and still delivers the wake-up. Setkeep_alive=truefor intentional long-lived daemons. - Works across sibling sessions (shared pool): call
process action=monitor process_id=<id>on a running process owned by another session in the same workspace. Kompile projects aSHAREDmirror row and subscribes throughProcessNotificationHub(which watches coordination state every 2 seconds and marks an owner lost after 3 consecutive absent passes).
How it works in practice
When you tell the agent "Watch CI run 12345 in the background with a 30-minute timeout and verify the published artifacts when it exits", the harness launches it through process (launch with timeout_minutes and monitor_message), arms the completion monitor automatically, and wakes the agent on exit. Agents can also attach to an already-running local or shared-pool process (monitor), inspect active watches (monitors), or detach (unmonitor) — no shell loops needed.
User Controls (CLI & Web)
- CLI Chat:
/process-monitors listand/process-monitors cancel <id>(plus/processesand/process-logs tail <id> 100). - Web Harness: open the
/processestab to inspect active monitors, read the 2,000-line log viewer, or click Cancel wake-up on any watched process.
2. Standing Process Notifications (process_notify / process action=notify)
When an agent discovers an already-running process via process list, process status, or process_log — especially across sessions or over MCP stdio — ProcessNotificationHub provides standing terminal-state subscriptions:
- Tool entry points:
process action=notify | unnotify | notificationsor the dedicatedprocess_notifytool. - Idempotent & persistent: subscriptions are keyed per
(subscriber, processId)and persisted under.kompile/coordination/notify/<sessionId>.json(stale stores older than 7 days are pruned automatically). If the process has already exited, registration immediately reports its terminal state and exit code instead of installing a dead monitor. - Surface-aware delivery:
- Inside Kompile CLI & Web Chat, subscriptions arm the completion-monitor wake channel so the agent wakes automatically on exit.
- On external MCP stdio hosts, the hub pushes
notifications/messagewhen the host supports it. If the host cannot deliver unsolicited wake-ups, Kompile explicitly tells the agent (wakeSupported=false) to checkprocess action=statusinstead of ending its turn waiting for a wake that cannot arrive.
3. Edit-Lock Monitors (edit_coordinator action=monitor_edit)
When another agent holds an edit lock on a file you need to modify, the harness never polls query_edits in a loop — instead, the agent subscribes to that path or lock ID (monitor_edit, with an optional monitor_message such as "Re-check locks and apply draft"), and can inspect (query_edit_monitors) or cancel (unmonitor_edit) watches at any time.
Key semantics:
- Fires on any release path: wakes when the holder releases the lock, the lock expires, or the holder process dies. If the lock is already gone,
monitor_editimmediately returnsstate: RELEASEDand installs nothing. - Advisory, not a reservation: a wake-up means the lock became free, not that the file was reserved exclusively for you. Always re-run
query_editsandregister_editsbefore modifying the file (or prepare your changes ahead of time in a Draft and rebase/apply once the lock clears). - External MCP host awareness: returns
wakeSupported: true|falsein metadata so external MCP clients without a wake bridge know to re-runquery_edit_monitors(or idempotentmonitor_edit) rather than stalling idle.
4. Named Locks, RAM/GPU Admission Waiters & Live Resource Monitoring
Beyond individual processes and file locks, Kompile provides reactive waiters and live telemetry for shared machine capacity:
| Monitor / Waiter | How it is armed | What wakes or updates |
|---|---|---|
Named FIFO Lock (edit_coordinator) | acquire_lock on a shared lane (e.g., build or device lane) | Wakes via wake.* message over the coordination bus when your session reaches the head of the FIFO queue. |
RAM / GPU Activity Admission (/resources & edit_coordinator) | preflight_activity / wait_for_activity (or blocked high-class command returning resourceWaitId + wakeSupported=true) | Parks cleanly until host RAM/GPU capacity is available, then delivers a wake.* event (persisted in .pending-events.json across restarts). See Resource Policies. |
Live Resource Monitor (/resource-monitor) | /resource-monitor show | status | stop | kill <id> confirm | embeddings stop confirm | Live per-chat CPU, RSS, GPU VRAM, and managed subprocess trees checked against declared policy weights. |
Crawl Job Monitor (crawl_control) | crawl_control action=monitor | Tracks active crawl pipeline jobs without shell polling. |
5. Interactive Process & Subagent Browser (Below the Chat Input)
Directly below the kompile > input box sits the fixed-height Process & Subagent Browser (StandardChatActivityPanel). It reserves a constant number of rows for the current terminal size so live process updates, completions, and subagent trees never resize JLine's scroll region or disturb a draft you are typing.
│ kompile > │ Input Pane
├────────────────────────────────────────────────────────────────────────────┤
│ ← [main] Main chat current view │
│ └─ [subagent-2] subagent explore auth (↑14.2k ↓2.1k) running · Del stop │ Process & Subagent
│ └─ [proc-018] process mvn test (42s) running · Del stop │ Browser (tree view)
│ └─ [proc-018] monitor wake on exit (42s) armed · Del stop │
│ ↑/↓ select · ← parent · Enter open · Del stop · type for Main chat │ Live hint row
├────────────────────────────────────────────────────────────────────────────┤
│ ⠋ proc-018 (42s) │ ◐ 1 bg │ Q:0 │ coder │ StatusBar(When you start typing a / slash command, the browser temporarily yields its rows to live slash-command completions and restores the tree automatically once completions dismiss.)
What Appears in the Browser Tree
The browser unifies every live activity source into a single navigable parent/child hierarchy:
| Row kind | What it shows | What Enter opens | What Delete does |
|---|---|---|---|
main | ← [main] Main chat (pinned at top) | Returns the transcript viewport to your main conversation | Informational only |
subagent | Active & recent task / multi_task / quorum_task children (with vendor/model metadata, elapsed time, and ↑in ↓out token usage) | Opens the child's bounded live transcript (StatusBar.SubagentEntry) without cluttering your main chat | Cancels the running subagent (subagentRunner.cancel) |
process | Local background processes (process action=launch), diagnostic logs, and mirrored SHARED processes from sibling sessions in the same repo | Opens the last 2,000 lines of live output + command, PID, and log path (typed subagent processes render as structured transcript blocks) | Kills local owned processes (processManager.kill); safely refuses foreign SHARED processes (non-owned watcher; inspect/logs only) |
monitor | Armed process completion wake-up monitors | Shows the watched process, wake-up monitor_message, and how long it has been armed | Cancels the wake-up monitor only — leaves the underlying process running |
tool | Running and recent tool calls (prettified input, result metadata, linked live log for shell/process calls) | Opens full tool arguments, output, and linked live log | Stops the linked background process if it owns one (in-turn calls remind you to use Esc) |
task | Backgrounded parent turns (Ctrl+B) linked to an active subagent | Opens task status, error/output, and linked subagent transcript | Informational / manage via the linked subagent |
chat (REPL) | In-process supervisory / auxiliary chats (e.g., Judge side-channel) | Opens the auxiliary chat transcript | Inspect-only |
project | Live project-wide agent dashboard (/activity) | Opens active agents across the repository | Inspect-only |
Keyboard Controls (from a Blank Prompt)
| Key | Action |
|---|---|
↓ (Down) | Focus the Process & Subagent Browser below the prompt and move down through rows |
↑ (Up) | Move up through rows (past the top returns focus to the input box) |
← (Left) | Jump straight to the selected row's parent node in the tree |
Enter | Open the selected process log, subagent transcript, tool output, or monitor details in the main viewport (select ← [main] Main chat + Enter to return) |
Delete | Stop the selected owned process, cancel the selected running subagent, or cancel an armed wake-up monitor (works identically when focused in the Results Sidebar via killByKey) |
PageUp / PageDown | Scroll through an opened process log or subagent transcript |
Type + Enter (with a live subagent open) | Sends your message directly as a follow-up to that open subagent (if the subagent has already finished, Kompile returns cleanly to Main chat and sends it there instead of dropping it) |
Ctrl+B | Backgrounds a currently blocking subagent invocation into the browser below so your prompt stays free |
Esc | Closes an opened non-subagent inspection view and returns to Main chat |
Built-In Safety & Isolation Guarantees
- Race-safe
Deleteprotection: if a process finishes or disappears while you have it highlighted, the browser clears focus automatically (normalizeSelection) so a lateDeletekeypress can never accidentally kill whichever row shifted into that slot. - Cross-session isolation:
SHAREDrows let you browse and read logs of builds running in sibling sessions (labeled withowner: ... · mirrored from coordination state; inspect/logs only), while refusing foreign kills and never leaking another chat's logs into your own main transcript. - No main-transcript clutter: subagent transcripts stay inside the browser until you press
Enterto inspect them; the parent chat only shows a compact launch notice (↓ select in process browser below · Enter to inspect · Delete to stop). - Web Harness equivalent: in
kompile chat --web, the/processestab provides the browser counterpart with a 2,000-line log viewer, Kill / Cancel wake-up buttons, and per-subagent follow-up composers.
The Golden Reactive Workflow for Agents
Every agent operating in Kompile should follow this five-step pattern whenever waiting on asynchronous work:
- Launch, never poll: start long commands with
process action=launch(settingtimeout_minutesandmonitor_message) rather thanbash+sleep/timeout. - Stay productive or yield cleanly: while a monitor is armed, either do independent read-only/drafting work (
read,lsp,draft) or end the turn cleanly so the harness wakes you when the event fires. - Pair
monitor_editwithdraft: if a sibling agent holds a file lock or build lane, stage your edits safely in a Kompiledraftand armedit_coordinator action=monitor_edit(orwait_for_activity) to wake and apply atomically when free. - Always re-verify after waking: edit-lock wakes are advisory (
query_edits→register_editsfirst); process wakes include the exit code and log path — read the log viaprocess action=outputorprocess_logbefore acting. - Respect
wakeSupported: in Kompile CLI and Web chat, wakes are delivered automatically; on external MCP clients where a tool reportswakeSupported=false, checkprocess action=status/query_edit_monitorsexplicitly instead of ending your turn waiting for a push wake.
Related Documentation
- Edit Coordinator & Message Bus — File locks, FIFO named locks, durable mailboxes,
wake.*events, and.pending-events.jsonpersistence. - How a Kompile Session Works — End-to-end agent turn loop including reactive monitoring and verification.
- Standard Daily Workflow — Day-to-day patterns pairing monitors, drafts, skills, and subagent controls.
- Interactive Workflows —
/process-monitors,/process-config,/resources, and/resource-monitorcommand reference. - Agent Skill (
SKILL.md) — PublicSKILL.mdinstructing agents how to use monitors and obey thesleep/timeoutban. - Resource Policies (
/resources) — Classifying heavy commands and tuning RAM/GPU admission lanes.