feat(session): join Relaycast messages into completed replay

Merged
KH
3mo ago
+2659-53

Closes #1522

What changed

  • Extend the existing SessionClient.replaySession() and relay session replay <id> path to fetch every indexed Relaycast page for the existing session_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_ID as metadata.session_ref on 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::replaySession already reconstructed { session, turns, contextPrompt } from Relayhistory.
  • packages/cli/src/cli/commands/session.ts already exposed relay session replay <id>; this PR extends that command and does not rebuild it.
  • The prompt-to-PR path already carries the existing session_ref through RELAY_ATTEST_SESSION_ID and Session-Id:. No fourth replay identifier was added.
  • relaycast#342 / @relaycast/engine 8.0.7 exposes indexed GET /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 — pass
  • npm run typecheck — pass
  • npm 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 --json for @agent-relay/session and @agent-relay/sdk — pass
  • Full npm test — 2,092 pass, 25 skipped, 1 unrelated failure: broker-lifecycle.test.ts still expects the retired text Reflex warning while current unchanged code emits structured JSON. Neither that source nor test differs from origin/main.

The Relaycast verification uses deterministic fixtures, not real production Relaycast data.