Skip to content

fix(agent): make AgentEvent::Warning a struct variant so it serializes#126

Merged
Tryanks merged 1 commit into
mainfrom
fix/agent-event-warning-serialize
Jul 20, 2026
Merged

fix(agent): make AgentEvent::Warning a struct variant so it serializes#126
Tryanks merged 1 commit into
mainfrom
fix/agent-event-warning-serialize

Conversation

@Tryanks

@Tryanks Tryanks commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Problem

AgentEvent is internally tagged (#[serde(tag = "type")], crates/agent/src/lib.rs), and Warning(String) was the only variant wrapping a bare primitive. Serde cannot inject the "type" tag into a plain string, so Store::append_event failed at runtime with:

cannot serialize tagged newtype variant AgentEvent::Warning containing a string

The live timeline still rendered warnings (folding happens regardless of persistence), which is why the app appeared unaffected — but every Warning event was silently dropped from the JSONL log and lost on session resume.

Fix

Warning(String)Warning { message: String }, matching the sibling Error { message, fatal } shape; serializes as {"type":"warning","message":"…"}. All construction/match sites updated (compiler-enforced). Adds a serde round-trip test.

No on-disk compatibility concern: the old shape never serialized successfully, so no legacy data exists.

Other newtype variants (TokenUsage(TokenUsage), ItemStarted(ThreadItem), …) wrap structs, which serialize as maps and accept the tag — they are unaffected, as are the other #[serde(tag = "kind")] enums in the file.

Verification

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo test --workspace --locked ✅ (one pre-existing, environment-only failure in term PTY test locally; fails identically on unchanged main)

🤖 Generated with Claude Code

AgentEvent is internally tagged (#[serde(tag = "type")]), and serde
cannot inject the tag into a newtype variant wrapping a bare string, so
every Warning event failed to persist with 'cannot serialize tagged
newtype variant AgentEvent::Warning containing a string'. The live
timeline still rendered warnings, but they were silently dropped from
the JSONL log and lost on session resume.

Warning(String) becomes Warning { message: String }, matching the
sibling Error { message, fatal } shape. No on-disk compatibility
concern: the old shape never serialized successfully. Adds a serde
round-trip test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Tryanks
Tryanks merged commit b98fe88 into main Jul 20, 2026
3 checks passed
@Tryanks
Tryanks deleted the fix/agent-event-warning-serialize branch July 20, 2026 10:16
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