feat: replay session history on session/load and resume #10
No reviewers
Labels
No labels
code-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
sam/brainless!10
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/session-replay"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
session/load(andsession/resume) now replay the stored conversation to the client asuser_message_chunk/agent_message_chunkupdates before returning the response.Why
Paseo's
initializeResumedSession()setsreplayingHistory = trueand collects onlysession/updatetimeline items whilesession/loadis in flight — with none, a resumed brainless agent rendered an empty conversation while ADK still held the real context. The same mechanism makeslistImportableSessions()drop every brainless session (hasConversation === false→null).Implementation notes:
UpdateUserMessageTextfor user-role events andUpdateAgentMessageTextfor final model responses (eventTextalready filters to final responses).LoadSessionandResumeSession(same 1-line call; both had the same empty-conversation bug for clients that usesession/resume).Test
New E2E test
TestACPLoadSessionReplaysHistory: runs a real prompt over pipes against a mock Responses server, thensession/loadand asserts the client received["first question", "pong"]in order.acpTestClientnow records user and agent chunks. Full suite +golangci-lint+ race detector clean.Docs
README "Next steps" now documents the two follow-ups:
2. Advertise session capabilities —
Initializereports onlyLoadSession: true; Paseo's import listing is gated onsessionCapabilities.listand probe cleanup onsessionCapabilities.close.3. Per-session
cwd—session/listreports the lastNewSessioncwd (or""on a probe process) and Paseo feeds it back intosession/loadand its import UI.Reviewed feat/session-replay (#10) against the cc-skills-golang review set. Core logic is sound: replayHistory walks the stored events oldest-first, classifies user vs agent by ev.Content.Role, filters non-final/empty events via eventText, is a safe no-op when no ACP client is attached, and is shared as a single 1-line call by both LoadSession and ResumeSession (so the empty-conversation fix covers clients that use either).
The new E2E test is well-built: it drives a real prompt over pipes, resets the recorder, then LoadSession and asserts the replay order. I verified against the ACP SDK source (client.go / connection.go) that after LoadSession returns, all replay notifications are guaranteed processed via SendRequest's waitNotificationsUpTo notification-barrier — so reading/resetting client.updates from the test goroutine is properly synchronized and there is no data race despite no explicit lock. No new dependencies (only stdlib
slices), idiomatic modern Go (slices.Equal, t.Context, t.Parallel), and the build/vet claims check out.Three non-blocking suggestions below. No blocking issues found — the PR is ready. (Forgejo blocks APPROVED on one's own PR, hence COMMENT.)
@ -325,0 +348,4 @@return}resp, err := h.store.Get(ctx, &session.GetRequest{🟡 SUGGESTION — redundant store read. activate() already fetches this same session via h.store.Get (line 320) to validate it exists; replayHistory then fetches it again, so every load/resume does two identical SQLite reads. Non-blocking: have activate() return the fetched *session.Session and pass it to replayHistory (or have it build the event list), instead of re-reading the store.
@ -325,0 +353,4 @@UserID: userID,SessionID: sid,})if err != nil {🟡 SUGGESTION — replay failures are invisible to the client. On a store.Get error the replay logs and returns, yet LoadSession/ResumeSession still return success — so a client (Paseo) relying on the replay to render history gets an empty conversation with no error signal, which is exactly the symptom this PR fixes, now silent. This is documented as deliberate ('logs rather than aborts'), so keep it, but consider reporting the replayed count (or returning the error) so the client can distinguish 'loaded with full history' from 'replay failed'.
@ -325,0 +371,4 @@update = acp.UpdateAgentMessageText(text)}if err := conn.SessionUpdate(ctx, acp.SessionNotification{🟡 SUGGESTION — replay loop keeps iterating after cancellation. If the client cancels the load/resume request or disconnects mid-replay, conn.SessionUpdate returns an error which is logged at LevelError, but the loop continues — emitting one Error log per remaining event (a log storm proportional to conversation length) and doing wasted work. Fix: break out of the loop on ctx.Err() != nil or after the first SessionUpdate error.
Review findings resolved in
de8acde(PR head is nowde8acde; full suite, golangci-lint, and race detector pass).activatenow returns the fetchedsession.Session(resp.Session) andreplayHistorytakes it as a parameter, so the secondstore.Getis gone.activatekeeps its existence check + active-cursor write;TestHarnessActivatenow also asserts the returned session id matches.replayHistoryreturns on the firstSessionUpdateerror. Verified in the SDK source (connection.goSendNotification) that it checksctx.Done()at entry and returns anInternalError, so a canceled/disconnected load surfaces as that first error — no log storm, no wasted sends.LoadSession/ResumeSessionnow return the replay error, so a load that could not deliver its history fails the request instead of silently rendering an empty conversation. With the store read folded intoactivate(see #397), the only remaining replay failure is a send failure (cancel/disconnect), which is exactly the case where failing loudly beats an empty chat.Reviewed feat/session-replay (#10) at head
de8acdeaagainst the cc-skills-golang review set. No blocking issues — this is solid and ready to merge. (Forgejo blocks APPROVED on one's own PR, hence COMMENT; verdict would be APPROVED.)Verified against the ADK + ACP SDK sources, not just the diff:
replayHistorywalkssess.Events().All()oldest-first; both the in-memory and SQLite stores return event snapshots (the SQLite path clones), so iteration is safe.Partial:falseand no function calls, sosession.Event.IsFinalResponse()returns true for them too —eventTexttherefore yields the user text and the role switch (ev.Content.Role == genai.RoleUser) correctly emitsUpdateUserMessageTextvsUpdateAgentMessageText. The["first question","pong"]assertion is achievable.session/load, ordered assertion.client.updatesis only appended on the client read-loop goroutine before the load response is delivered, so the reset/read from the test goroutine is properly synchronized (no data race).slicesin a test); idiomatic modern Go (t.Parallel,t.Context,slices.Equal).The three suggestions from the earlier review (id 18, stale against
44aaa111) are all resolved at this head:activatenow returns the fetched session (no double store read), andreplayHistorybreaks on the first send failure and propagates the error, so replay failures are no longer silently swallowed.One remaining non-blocking SUGGESTION: the PR description's "logs rather than aborts on update failures" no longer matches the code, which now aborts and fails the load.
@ -322,0 +380,4 @@SessionId: acp.SessionId(sid),Update: update,}); err != nil {return fmt.Errorf("replay session update: %w", err)🟡 SUGGESTION — PR description contradicts the implemented behavior. The PR body says "logs rather than aborts on update failures", but this line returns the first
conn.SessionUpdateerror andLoadSession/ResumeSessionpropagate it, so a load that hits a send failure fails rather than logging and continuing. The code behavior is the correct one (a load that could not deliver its history should not silently report success — this also resolves the earlier "replay failures invisible to the client" concern), so only the PR description is stale. Update the PR body to say the load aborts and returns the error on update failure, so the documented contract matches the code.Fixed — PR description updated (comment #418): the stale "logs rather than aborts on update failures" line now reads "the first update failure aborts the replay and fails the load, so a session that could not deliver its history is never reported as loaded". No code change needed; verified no other "logs rather than aborts" phrasing remains in the README or the harness.