feat: replay session history on session/load and resume #10

Merged
sam merged 2 commits from feat/session-replay into main 2026-09-24 18:58:39 +00:00
Collaborator

What

session/load (and session/resume) now replay the stored conversation to the client as user_message_chunk / agent_message_chunk updates before returning the response.

Why

Paseo's initializeResumedSession() sets replayingHistory = true and collects only session/update timeline items while session/load is in flight — with none, a resumed brainless agent rendered an empty conversation while ADK still held the real context. The same mechanism makes listImportableSessions() drop every brainless session (hasConversation === false → null).

Implementation notes:

  • Replay walks the ADK session store's events oldest-first, emitting UpdateUserMessageText for user-role events and UpdateAgentMessageText for final model responses (eventText already filters to final responses).
  • The ADK runner still loads the events itself on the next Prompt; the replay only feeds the client's view.
  • No-op when no ACP client is attached (single-shot CLI path); 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.
  • Replay is shared by LoadSession and ResumeSession (same 1-line call; both had the same empty-conversation bug for clients that use session/resume).

Test

New E2E test TestACPLoadSessionReplaysHistory: runs a real prompt over pipes against a mock Responses server, then session/load and asserts the client received ["first question", "pong"] in order. acpTestClient now 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 — Initialize reports only LoadSession: true; Paseo's import listing is gated on sessionCapabilities.list and probe cleanup on sessionCapabilities.close.
3. Per-session cwd — session/list reports the last NewSession cwd (or "" on a probe process) and Paseo feeds it back into session/load and its import UI.

## What `session/load` (and `session/resume`) now replay the stored conversation to the client as `user_message_chunk` / `agent_message_chunk` updates before returning the response. ## Why Paseo's `initializeResumedSession()` sets `replayingHistory = true` and collects **only** `session/update` timeline items while `session/load` is in flight — with none, a resumed brainless agent rendered an empty conversation while ADK still held the real context. The same mechanism makes `listImportableSessions()` drop every brainless session (`hasConversation === false` → `null`). Implementation notes: - Replay walks the ADK session store's events oldest-first, emitting `UpdateUserMessageText` for user-role events and `UpdateAgentMessageText` for final model responses (`eventText` already filters to final responses). - The ADK runner still loads the events itself on the next Prompt; the replay only feeds the client's view. - No-op when no ACP client is attached (single-shot CLI path); 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. - Replay is shared by `LoadSession` and `ResumeSession` (same 1-line call; both had the same empty-conversation bug for clients that use `session/resume`). ## Test New E2E test `TestACPLoadSessionReplaysHistory`: runs a real prompt over pipes against a mock Responses server, then `session/load` and asserts the client received `["first question", "pong"]` in order. `acpTestClient` now 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** — `Initialize` reports only `LoadSession: true`; Paseo's import listing is gated on `sessionCapabilities.list` and probe cleanup on `sessionCapabilities.close`. 3. **Per-session `cwd`** — `session/list` reports the last `NewSession` cwd (or `""` on a probe process) and Paseo feeds it back into `session/load` and its import UI.
feat: replay session history on session/load and resume
All checks were successful
code-review / Agent review (pull_request) Successful in 8s
44aaa11165
session/load (and session/resume) now stream the stored conversation back
to the client as user_message_chunk and agent_message_chunk updates before
returning. Paseo's initializeResumedSession collects exactly those updates
while session/load is in flight and renders them as the conversation, and
its import listing drops any session with no conversation updates - so
without the replay every resumed or listed brainless session looked empty.

The ADK runner still loads the events itself on the next Prompt; the replay
only feeds the client's view, and is a no-op when no client is attached.

Also documents the two next steps: advertising sessionCapabilities.list/
close in Initialize (Paseo gates import listing and probe cleanup on them),
and per-session cwd reporting (session/list currently reports the last
NewSession cwd, or "" on a probe process).
pi-agent left a comment

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.)

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{
Author
Collaborator

🟡 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.

🟡 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.
sam marked this conversation as resolved
@ -325,0 +353,4 @@
UserID: userID,
SessionID: sid,
})
if err != nil {
Author
Collaborator

🟡 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'.

🟡 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'.
sam marked this conversation as resolved
@ -325,0 +371,4 @@
update = acp.UpdateAgentMessageText(text)
}
if err := conn.SessionUpdate(ctx, acp.SessionNotification{
Author
Collaborator

🟡 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.

🟡 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.
sam marked this conversation as resolved
refactor: resolve session-replay review findings
All checks were successful
code-review / Agent review (pull_request) Successful in 8s
de8acdea9a
- activate now returns the fetched session so replayHistory reads its
  events without a second store lookup (review #397).
- replayHistory stops and returns on the first SessionUpdate failure;
  the SDK's SendNotification checks ctx.Done() at entry, so a canceled
  load/resume no longer logs once per remaining event (review #398).
- LoadSession/ResumeSession propagate the replay error, so a load that
  could not deliver its history fails instead of silently rendering an
  empty conversation (review #399).
Author
Collaborator

Review findings resolved in de8acde (PR head is now de8acde; full suite, golangci-lint, and race detector pass).

  • #397 redundant store read — fixed. activate now returns the fetched session.Session (resp.Session) and replayHistory takes it as a parameter, so the second store.Get is gone. activate keeps its existence check + active-cursor write; TestHarnessActivate now also asserts the returned session id matches.
  • #398 loop keeps iterating after cancellation — fixed. replayHistory returns on the first SessionUpdate error. Verified in the SDK source (connection.go SendNotification) that it checks ctx.Done() at entry and returns an InternalError, so a canceled/disconnected load surfaces as that first error — no log storm, no wasted sends.
  • #399 replay failures invisible to the client — fixed by propagating. LoadSession/ResumeSession now 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 into activate (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.
Review findings resolved in de8acde (PR head is now de8acde; full suite, golangci-lint, and race detector pass). - **#397 redundant store read** — fixed. `activate` now returns the fetched `session.Session` (`resp.Session`) and `replayHistory` takes it as a parameter, so the second `store.Get` is gone. `activate` keeps its existence check + active-cursor write; `TestHarnessActivate` now also asserts the returned session id matches. - **#398 loop keeps iterating after cancellation** — fixed. `replayHistory` returns on the first `SessionUpdate` error. Verified in the SDK source (`connection.go` `SendNotification`) that it checks `ctx.Done()` at entry and returns an `InternalError`, so a canceled/disconnected load surfaces as that first error — no log storm, no wasted sends. - **#399 replay failures invisible to the client** — fixed by propagating. `LoadSession`/`ResumeSession` now 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 into `activate` (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.
pi-agent left a comment

Reviewed feat/session-replay (#10) at head de8acdea against 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:

  • replayHistory walks sess.Events().All() oldest-first; both the in-memory and SQLite stores return event snapshots (the SQLite path clones), so iteration is safe.
  • Stored user-message events have Partial:false and no function calls, so session.Event.IsFinalResponse() returns true for them too — eventText therefore yields the user text and the role switch (ev.Content.Role == genai.RoleUser) correctly emits UpdateUserMessageText vs UpdateAgentMessageText. The ["first question","pong"] assertion is achievable.
  • The new E2E test is well-built: real prompt over pipes, recorder reset, session/load, ordered assertion. client.updates is 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).
  • No new dependencies (only stdlib slices in 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: activate now returns the fetched session (no double store read), and replayHistory breaks 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.

Reviewed feat/session-replay (#10) at head de8acdea against 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: - `replayHistory` walks `sess.Events().All()` oldest-first; both the in-memory and SQLite stores return event snapshots (the SQLite path clones), so iteration is safe. - Stored user-message events have `Partial:false` and no function calls, so `session.Event.IsFinalResponse()` returns true for them too — `eventText` therefore yields the user text and the role switch (`ev.Content.Role == genai.RoleUser`) correctly emits `UpdateUserMessageText` vs `UpdateAgentMessageText`. The `["first question","pong"]` assertion is achievable. - The new E2E test is well-built: real prompt over pipes, recorder reset, `session/load`, ordered assertion. `client.updates` is 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). - No new dependencies (only stdlib `slices` in 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: `activate` now returns the fetched session (no double store read), and `replayHistory` breaks 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)
Author
Collaborator

🟡 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.SessionUpdate error and LoadSession/ResumeSession propagate 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.

🟡 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.SessionUpdate` error and `LoadSession`/`ResumeSession` propagate 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.
sam marked this conversation as resolved
Author
Collaborator

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.

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.
sam merged commit de09ce95f9 into main 2026-09-24 18:58:39 +00:00
sam deleted branch feat/session-replay 2026-09-24 18:58:39 +00:00
Sign in to join this conversation.
No reviewers
No labels
code-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sam/brainless!10
No description provided.