Skip to content

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 ​

mermaid
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 --> MCP

1. 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 shell timeout, pass timeout_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. Set keep_alive=true for 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 a SHARED mirror row and subscribes through ProcessNotificationHub (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 list and /process-monitors cancel <id> (plus /processes and /process-logs tail <id> 100).
  • Web Harness: open the /processes tab 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 | notifications or the dedicated process_notify tool.
  • 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/message when the host supports it. If the host cannot deliver unsolicited wake-ups, Kompile explicitly tells the agent (wakeSupported=false) to check process action=status instead 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_edit immediately returns state: RELEASED and 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_edits and register_edits before 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|false in metadata so external MCP clients without a wake bridge know to re-run query_edit_monitors (or idempotent monitor_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 / WaiterHow it is armedWhat 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 confirmLive per-chat CPU, RSS, GPU VRAM, and managed subprocess trees checked against declared policy weights.
Crawl Job Monitor (crawl_control)crawl_control action=monitorTracks 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.

text
│ 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 kindWhat it showsWhat Enter opensWhat Delete does
main← [main] Main chat (pinned at top)Returns the transcript viewport to your main conversationInformational only
subagentActive & 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 chatCancels the running subagent (subagentRunner.cancel)
processLocal background processes (process action=launch), diagnostic logs, and mirrored SHARED processes from sibling sessions in the same repoOpens 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)
monitorArmed process completion wake-up monitorsShows the watched process, wake-up monitor_message, and how long it has been armedCancels the wake-up monitor only — leaves the underlying process running
toolRunning and recent tool calls (prettified input, result metadata, linked live log for shell/process calls)Opens full tool arguments, output, and linked live logStops the linked background process if it owns one (in-turn calls remind you to use Esc)
taskBackgrounded parent turns (Ctrl+B) linked to an active subagentOpens task status, error/output, and linked subagent transcriptInformational / manage via the linked subagent
chat (REPL)In-process supervisory / auxiliary chats (e.g., Judge side-channel)Opens the auxiliary chat transcriptInspect-only
projectLive project-wide agent dashboard (/activity)Opens active agents across the repositoryInspect-only

Keyboard Controls (from a Blank Prompt) ​

KeyAction
↓ (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
EnterOpen the selected process log, subagent transcript, tool output, or monitor details in the main viewport (select ← [main] Main chat + Enter to return)
DeleteStop 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 / PageDownScroll 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+BBackgrounds a currently blocking subagent invocation into the browser below so your prompt stays free
EscCloses an opened non-subagent inspection view and returns to Main chat

Built-In Safety & Isolation Guarantees ​

  • Race-safe Delete protection: if a process finishes or disappears while you have it highlighted, the browser clears focus automatically (normalizeSelection) so a late Delete keypress can never accidentally kill whichever row shifted into that slot.
  • Cross-session isolation: SHARED rows let you browse and read logs of builds running in sibling sessions (labeled with owner: ... · 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 Enter to 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 /processes tab 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:

  1. Launch, never poll: start long commands with process action=launch (setting timeout_minutes and monitor_message) rather than bash + sleep / timeout.
  2. 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.
  3. Pair monitor_edit with draft: if a sibling agent holds a file lock or build lane, stage your edits safely in a Kompile draft and arm edit_coordinator action=monitor_edit (or wait_for_activity) to wake and apply atomically when free.
  4. Always re-verify after waking: edit-lock wakes are advisory (query_edits → register_edits first); process wakes include the exit code and log path — read the log via process action=output or process_log before acting.
  5. Respect wakeSupported: in Kompile CLI and Web chat, wakes are delivered automatically; on external MCP clients where a tool reports wakeSupported=false, check process action=status / query_edit_monitors explicitly instead of ending your turn waiting for a push wake.

Released under the Apache-2.0 License.