Skip to content

feat(output): emit turn_start event on JSONL stream#217

Merged
emal-avala merged 1 commit intomainfrom
feat/jsonl-turn-start-event
Apr 23, 2026
Merged

feat(output): emit turn_start event on JSONL stream#217
emal-avala merged 1 commit intomainfrom
feat/jsonl-turn-start-event

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

`JsonStreamSink::on_turn_start` only updated an internal counter — it never emitted a JSONL line. Consumers of the stream saw `turn_complete` arrive at the end of each turn but had no signal that a new turn had begun, so a real-time progress renderer ("turn 3 of 10, still working...") couldn't draw without racing the first `text_delta` or `tool_call`.

This PR adds a `turn_start` event — a minimal envelope with just `type` and `turn` — emitted immediately after the internal counter is updated. It's the matching bookend to `turn_complete`. Stderr is unchanged; this is purely additive on stdout.

Test plan

  • `cargo clippy -p agent-code --tests --no-deps -- -D warnings` — clean
  • `cargo test -p agent-code --bin agent output::` — 13 pass (11 prior + 2 new)
  • 2 new tests:
    • snake_case type + turn field shape
    • envelope-size guard: only `type` and `turn` keys (so future refactors can't accidentally add model/session fields and break consumers that snapshot envelope shapes)
  • Existing `all_events_are_single_line_json` extended to cover `TurnStart`

JsonStreamSink::on_turn_start only updated internal state, never
emitting a line. Consumers of the JSONL stream could see TurnComplete
arrive at the end of a turn but had no signal that a new turn had
begun — so a real-time progress indicator ("turn 3 of 10, still
working...") couldn't render without racing a TextDelta or ToolCall
event.

Adds Event::TurnStart { turn } with a minimal envelope (only type +
turn). The event fires immediately after the internal turn counter is
updated, so the line carries the new turn number and consumers
can correlate it with the matching TurnComplete bookend.

Stderr is unchanged; this is purely additive on stdout.

Two new tests cover: snake_case type tag + turn field shape, and an
envelope-size guard that will fail if a future refactor accidentally
adds model/session fields to TurnStart (consumers snapshot envelope
shapes). The existing all_events_are_single_line_json check is
extended to include TurnStart.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit f30c47b into main Apr 23, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/jsonl-turn-start-event branch April 23, 2026 18:54
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