feat(session): join Relaycast messages into completed replay
Closes #1522
What changed
- Extend the existing
SessionClient.replaySession()andrelay session replay <id>path to fetch every indexed Relaycast page for the existingsession_ref, merge workspace-wide messages with Relayhistory turns by timestamp, and return both the structured joined timeline and a copy-pastable prompt. - Display Relaycast availability and the effective retention boundary in every replay.
partial,aged_out, unavailable credentials, invalid responses, pagination failures, and query failures are explicitly marked incomplete/unknown rather than rendered as confident coverage. - Stamp
RELAY_ATTEST_SESSION_IDasmetadata.session_refon channel posts, thread replies, direct messages, and group messages. This is the production write seam required by Relaycast's indexed lookup; a read-only join would find no Relay-authored conversation. - Require Relaycast SDK 8.0.7, whose session lookup and structured message metadata support are the prerequisite shipped by relaycast#342.
- Escape replay payload delimiters and bound the generated prompt while preserving the complete fetched timeline in the structured result.
Verified inventory
packages/session/src/client.ts::replaySessionalready reconstructed{ session, turns, contextPrompt }from Relayhistory.packages/cli/src/cli/commands/session.tsalready exposedrelay session replay <id>; this PR extends that command and does not rebuild it.- The prompt-to-PR path already carries the existing
session_refthroughRELAY_ATTEST_SESSION_IDandSession-Id:. No fourth replay identifier was added. - relaycast#342 /
@relaycast/engine8.0.7 exposes indexedGET /v1/sessions/:session_ref/messages, paginated session messages, availability, and the effective retention policy/boundary.
Recorded constraints
Retention: replay reaches back only as far as the workspace plan's effective Relaycast retention. The output always names that boundary. If the session begins before it, is fully aged out, predates reliable indexing, or cannot be queried confidently, the conversation is labeled incomplete/unknown.
Multi-node: Relaycast lookup is workspace-wide and keyed by the exact shared session_ref, so messages from agents on different nodes are joined independently of where their harness ran. Relayhistory remains per-node. If one node's Relayhistory journal is missing, its private harness turns can be absent, while its stamped Relaycast messages still appear; the replay states that the local Relayhistory count does not prove cross-node completeness.
Verification
npm ci --ignore-scripts— passnpm run typecheck— passnpm run lint— pass with 0 errors (87 existing warnings)- Focused Vitest suites — 73/73 pass, including the required multi-node must-fire and aged-out must-not-fire pair
npm pack --dry-run --jsonfor@agent-relay/sessionand@agent-relay/sdk— pass- Full
npm test— 2,092 pass, 25 skipped, 1 unrelated failure:broker-lifecycle.test.tsstill expects the retired text Reflex warning while current unchanged code emits structured JSON. Neither that source nor test differs fromorigin/main.
The Relaycast verification uses deterministic fixtures, not real production Relaycast data.