feat: live session monitoring with circuit breakers (v1.0.0)#17
Merged
Conversation
Add `agent-strace watch` — tails the active session's events.ndjson and fires alerts when configurable thresholds are exceeded. Watchers: - RetryWatcher: same command fails N times (default: 5) - CostWatcher: estimated cost exceeds threshold (default: $10) - DurationWatcher: session exceeds time limit (default: 30m) - LoopWatcher: same event sequence repeats N times (default: 3x) - ScopeWatcher: file write denied by .agent-scope.json policy Alert actions: - terminal: print warning to stderr (default) - file: append to .agent-traces/alerts.log - webhook: POST JSON via stdlib urllib.request - kill: SIGTERM to agent process Config via .agent-watch.json or CLI flags. Each violation fires exactly once (deduped by key). Zero new dependencies. 19 new tests covering retry detection, cost threshold, duration limit, loop detection, alert actions, and config loading. Co-authored-by: Ona <no-reply@ona.com>
watch.py: - Remove unused Callable import - Remove dead meta load block (PID not stored in meta) - _dispatch_alert: always write to terminal regardless of action; also write to file when action is 'file' or 'kill' - Cost dedup key: use single 'cost' key so violation fires exactly once, not once per dollar crossed above the threshold - Idle timeout comment: clarify it triggers on the next event after the idle window, not mid-sleep tests/test_watch.py: - Add test: cost violation fires exactly once across multiple events - Add test: _dispatch_alert always calls _alert_terminal regardless of configured action Co-authored-by: Ona <no-reply@ona.com>
66d6813 to
88e4e42
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8
What
Adds
agent-strace watch— real-time session monitoring that tails the active session'sevents.ndjsonand fires alerts when configurable thresholds are exceeded.Usage
Watchers
.agent-scope.jsonpolicyAlert actions
terminal— print warning to stderr (default)file— append to.agent-traces/alerts.logwebhook— POST JSON to a URL (Slack, PagerDuty, etc.) via stdliburllib.requestkill— send SIGTERM to the agent processConfig file (
.agent-watch.json){ "watchers": { "retry": { "max": 3, "alert": "terminal" }, "cost": { "max_dollars": 5.0 }, "duration": { "max_minutes": 15 }, "loop": { "sequence_length": 3, "max_repeats": 3 } }, "webhook": { "url": "https://hooks.slack.com/services/..." } }Implementation
src/agent_trace/watch.py— watcher state machines, alert dispatcher, file tailercost.pytoken estimation (_event_tokens,_dollars)audit.pypolicy loadingZero new dependencies. 19 new tests covering retry detection, cost threshold, duration limit, loop detection, alert actions (terminal + file), and config loading.