feat(output): emit warning and compact events on JSONL stdout stream#215
Merged
emal-avala merged 1 commit intomainfrom Apr 23, 2026
Merged
feat(output): emit warning and compact events on JSONL stdout stream#215emal-avala merged 1 commit intomainfrom
emal-avala merged 1 commit intomainfrom
Conversation
JsonStreamSink::on_warning and on_compact wrote only to stderr as plain
human-readable lines. Any automation pipeline that consumed the JSONL
stream from stdout (CI runners, audit logs, monitoring) silently lost
signal for budget-approaching warnings, rate-limit backoffs, and
autocompaction events. That's a real observability gap — consumers
couldn't tell a 4x-cost session apart from a clean one without
re-parsing stderr.
Adds two new Event variants:
- Warning { message, turn } — fired in parallel with the stderr
write, so humans still see the message and automation gets a
structured line.
- Compact { freed_tokens, turn } — same dual-sink pattern.
Both events use the existing snake_case type tag convention and carry
the current turn number pulled under the same lock that on_turn_start
writes to. Stderr output is unchanged; the JSONL line is purely
additive.
3 new tests cover: warning envelope shape, compact envelope shape, and
turn-state correlation. The existing single-line-json check is
extended to cover both new variants (including a multiline message to
confirm serde still escapes newlines).
4 tasks
emal-avala
added a commit
that referenced
this pull request
Apr 23, 2026
Adds a `Notification` hook event. Previously the `sink.on_warning` path only reached stderr (and the JSONL `warning` event as of #215); users couldn't wire a desktop notifier, Slack DM, or SMS to those moments because there was no hook. Context payload: { "session_id": "...", "message": "...", "title": "..." | null, "notification_type": "budget_limit" | "context_full" | ... } `notification_type` lets hook configs filter so a Slack-on-budget hook doesn't also fire on routine context warnings. Wiring: - HookEvent::Notification added with snake_case serde - fire_notification_hooks(message, title, notification_type) async method on QueryEngine - Wired at the 3 most critical user-attention sites in run_turn: - BudgetDecision::Stop -> "budget_limit" - BudgetDecision::ContinueWithWarning -> "budget_warning" - Context window is_blocking -> "context_full" - Non-blocking context % warnings and per-turn rate-limit fallbacks stay warning-only — routing every retry would be noise - HOOK_EVENT_CATALOG, format_hook_event, parse_hook_event updated - hooks/mod.rs module docs updated Tests: 3 new - Schema serde round-trip (notification <-> "notification") - run_hooks dispatches for Notification (async tokio) - parse_hook_event accepts "notification" / "Notification"
emal-avala
added a commit
that referenced
this pull request
Apr 23, 2026
Adds a `Notification` hook event. Previously the `sink.on_warning` path only reached stderr (and the JSONL `warning` event as of #215); users couldn't wire a desktop notifier, Slack DM, or SMS to those moments because there was no hook. Context payload: { "session_id": "...", "message": "...", "title": "..." | null, "notification_type": "budget_limit" | "context_full" | ... } `notification_type` lets hook configs filter so a Slack-on-budget hook doesn't also fire on routine context warnings. Wiring: - HookEvent::Notification added with snake_case serde - fire_notification_hooks(message, title, notification_type) async method on QueryEngine - Wired at the 3 most critical user-attention sites in run_turn: - BudgetDecision::Stop -> "budget_limit" - BudgetDecision::ContinueWithWarning -> "budget_warning" - Context window is_blocking -> "context_full" - Non-blocking context % warnings and per-turn rate-limit fallbacks stay warning-only — routing every retry would be noise - HOOK_EVENT_CATALOG, format_hook_event, parse_hook_event updated - hooks/mod.rs module docs updated Tests: 3 new - Schema serde round-trip (notification <-> "notification") - run_hooks dispatches for Notification (async tokio) - parse_hook_event accepts "notification" / "Notification"
emal-avala
added a commit
that referenced
this pull request
Apr 23, 2026
Adds a `Notification` hook event. Previously the `sink.on_warning` path only reached stderr (and the JSONL `warning` event as of #215); users couldn't wire a desktop notifier, Slack DM, or SMS to those moments because there was no hook. Context payload: { "session_id": "...", "message": "...", "title": "..." | null, "notification_type": "budget_limit" | "context_full" | ... } `notification_type` lets hook configs filter so a Slack-on-budget hook doesn't also fire on routine context warnings. Wiring: - HookEvent::Notification added with snake_case serde - fire_notification_hooks(message, title, notification_type) async method on QueryEngine - Wired at the 3 most critical user-attention sites in run_turn: - BudgetDecision::Stop -> "budget_limit" - BudgetDecision::ContinueWithWarning -> "budget_warning" - Context window is_blocking -> "context_full" - Non-blocking context % warnings and per-turn rate-limit fallbacks stay warning-only — routing every retry would be noise - HOOK_EVENT_CATALOG, format_hook_event, parse_hook_event updated - hooks/mod.rs module docs updated Tests: 3 new - Schema serde round-trip (notification <-> "notification") - run_hooks dispatches for Notification (async tokio) - parse_hook_event accepts "notification" / "Notification"
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.
Summary
`JsonStreamSink::on_warning` and `on_compact` only wrote to stderr as plain text, so automation consumers parsing the JSONL stream from stdout silently lost signal for budget warnings, rate-limit backoffs, and autocompaction events. A run that hit a cost-limit or compacted twice looked identical on the wire to a clean one.
This PR adds two new `Event` variants — `Warning { message, turn }` and `Compact { freed_tokens, turn }` — that fire on stdout in parallel with the existing stderr writes. Stderr output is unchanged; JSONL is purely additive, so downstream tooling only sees more structure.
Both variants use the existing snake_case tag convention and carry the current turn number (read under the same lock `on_turn_start` writes to), so consumers can correlate them with the surrounding `TurnComplete` envelope.
Test plan