Skip to content

Add an event-driven monitor tool (port of #29922) + session-access alignment - #1

Draft
hassaans wants to merge 2 commits into
mainfrom
feat/monitor-tool
Draft

hassaans wants to merge 2 commits into
mainfrom
feat/monitor-tool

Conversation

@hassaans

@hassaans hassaans commented Jun 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the monitor tool from openai#29922 on current main, and runs its watcher with the same sandbox access the session has already granted.

monitor runs a shell command as a long-lived background watcher. Every line it writes to stdout or stderr comes back to the model as a notification, so the agent reacts to output as it arrives instead of polling. It builds on the existing unified_exec plumbing: the watcher is a unified_exec process. A delivery task subscribes to its output and batches lines that come in close together, then wakes an idle session with try_start_turn_if_idle. A flood guard stops a runaway command.

  • start begins a watch and returns its id
  • stop ends the watch for a given id
  • list shows the active watches

The watcher used to build its exec request with sandbox_permissions: Default::default() and never resolved granted permissions, so it stayed on the turn's default sandbox even after the session was granted more access. It now goes through apply_granted_turn_permissions, the same path exec_command.rs uses, so a watched command runs with the granted access too.

Porting notes

The reference targeted rust-v0.142.0. Two things needed adjusting against current main: a conflict in the feature-flag list, and resolve_tool_environment now takes a &TurnEnvironmentSnapshot instead of a &TurnContext, so the handler passes step_context.environments into start().

Testing

core/tests/suite/monitor.rs covers the watch behavior: per-line wake on stdout and stderr, output captured before the first yield, an unterminated final line, the flood-guard auto-stop, a newline-free flood getting truncated, the "watcher exited" notice, and registry pruning when the command exits.

core/tests/suite/request_permissions.rs has a regression test for the permission change. It grants a turn-scoped write, has the watcher write a path the base sandbox blocks, and checks the write lands. The test fails against the old default-sandbox behavior and passes once the watcher inherits the grant.

hassaans added 2 commits June 29, 2026 22:05
Adds a `monitor` tool (gated behind the Monitor feature) that runs a shell
command as a long-lived background watcher and delivers each output line back to
the model as a notification, so the agent can react to events (a log line, a file
change, a CI check, a build going green) without polling. It reuses the existing
unified_exec machinery: the watcher is a unified_exec process and a delivery task
subscribes to its output, coalesces lines, bounds them, and wakes an idle session.
A flood guard auto-stops a runaway command. action=start returns a monitor id,
action=stop ends a watch, and action=list shows active watches. Covered by an
end-to-end suite in core/tests/suite/monitor.rs.
The monitor watcher previously ran under a hard-coded default sandbox, so it
could not see permissions the user granted for the turn (e.g. a write path
approved via request_permissions or an exec approval). It would silently fail to
write or read paths the rest of the turn could already reach.

Resolve the turn's effective permissions the same way exec does — via
apply_granted_turn_permissions over the session and turn environment, anchored at
the native turn cwd when available and the config cwd otherwise — and pass the
resulting sandbox permissions, additional permissions, and pre-approval flag into
the watcher's exec request. The watcher now inherits exactly the access the
session has granted, no more and no less.

Adds request_permissions_grant_applies_to_monitor: a turn-scoped write grant lets
the watcher write a path the base sandbox forbids; it fails under the old default
sandbox and passes with the inherited grant.
@hassaans

hassaans commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Closing as part of a backlog cleanup: this has been open since 2026-06-28, more than two weeks, so it is being cleared out by age rather than on its merits.

Note: this one was deliberately parked rather than abandoned, so it is being closed only because of the age sweep. If the thing it was waiting on has landed, reopen it.

The branch is preserved and this reopens in one click.

@hassaans hassaans closed this Sep 2, 2026
@hassaans hassaans reopened this Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant