[adk/session] FileStore accepts tab/CR/LF in EventID or Kind and corrupts the session log
Describe the bug
adk/session.FileStore writes each event as one line, <EventID>\t<Kind>\t<Data>\n. AppendEvents rejects serialized Data containing CR/LF, but it writes EventID and Kind as raw columns without checking them. An event ID or kind containing \t, \r or \n is accepted and corrupts the log. From then on the whole session can no longer be loaded.
Both values can come from outside the framework: event IDs from a custom SessionEventIDGenerator or from callers of AppendEvents, and kinds from application extension events (x. + any string).
To Reproduce (branch alpha/10, 269a188d)
store, _ := session.NewFileStore[*schema.Message](dir, nil)
_ = store.AppendEvents(ctx, "s", []*adk.SessionEvent[*schema.Message]{msgEvent("ok")})
err := store.AppendEvents(ctx, "s", []*adk.SessionEvent[*schema.Message]{msgEvent("bad\nid")}) // err == nil
reopened, _ := session.NewFileStore[*schema.Message](dir, nil)
_, err = reopened.LoadEvents(ctx, "s", &adk.LoadSessionEventsRequest{})
Results:
| appended | AppendEvents |
later LoadEvents |
later AppendEvents |
|---|---|---|---|
EventID bad\nid |
nil | invalid event_id: missing tab separator at line 2 |
same error |
EventID bad\tid |
nil | failed to unmarshal JSON: Syntax error … |
nil |
Kind x.bad\tkind |
nil | failed to unmarshal JSON: Syntax error … |
nil |
The valid event written earlier (ok) can no longer be read either.
Expected behavior
AppendEvents rejects such an event up front, as it already does for CR/LF in Data. The batch is not written and the session stays readable. ErrInvalidEventID is the natural error for a bad ID.
Version: alpha/10 @ 269a188d
I have a fix with tests ready and will open a PR.