Skip to content

Keep chat Redis data short-lived and schema-light #1267

Description

@sentry-junior

Redis chat/runtime records have nested shapes and multi-day TTLs, so schema changes hang around after deploy. SQL remains the durable history authority. Redis should only hold bounded operational state that is safe to expire. OAuth tokens/sessions are out of scope.

Goals

  1. Redis schema changes must not require multi-day compatibility code.
  2. Durable conversation history and metadata have one authority in SQL.
  3. Redis holds only bounded operational state that is safe to expire.
  4. Terminal state is deleted quickly or kept only for a short diagnostic grace period.
  5. Redis records avoid embedding shared nested plugin/API contracts when stable ids or an authoritative lookup suffice.

A mailbox or idempotency record can still be authoritative in Redis while work is in flight. The test is whether loss/expiry is an accepted operational outcome—not whether the data is "history."

Exit criteria

  • No chat Redis record uses the chat-sdk 30d TTL.
  • Every key family documents authority, loss behavior, active TTL, and terminal TTL/deletion.
  • SQL-owned conversation metadata is not duplicated into Redis except during a named rollout.
  • Redis schemas do not store full Source / Destination / actor contracts unless that store explicitly owns the bounded operational record.
  • Dashboard/reporting reads SQL, not Redis indexes.
  • Compatibility code has a release/date removal condition and an owning TODO.
  • User-authored configuration and user-visible context do not silently disappear because a scratch TTL elapsed.
  • Tests prove terminal cleanup and authoritative reconstruction without legacy Redis fields.

Cutover rule

  1. Deploy readers that use the canonical authority (usually SQL).
  2. Dual-write only while old readers may still be running.
  3. Once canonical readers are deployed, remove the Redis write path and obsolete schema fields immediately. Do not wait for old Redis TTLs.
  4. Put cleanup TODOs beside temporary dual-write/schema code and reference this tracker (#1267).

Done

Turn sessions — complete

Resume lease over SQL history. Nested routing/actors and ops metadata are out of Redis; TTLs are short; dashboard indexes are gone.

  • #1268 — resume routing from SQL only
  • #1286 — stop nested source/destination writes; explicit strip schemas
  • #1298 — stop actor writes
  • #1308 — 24h unfinished / 1h terminal; drop runtimeContext on terminal
  • #1313 — thin recovery indexes; remove global dashboard list
  • #1315 — remove ops metadata from Redis records
  • #1266 closed without merge once Redis no longer owned nested source

Leftover: TODO(#1267) in packages/junior/src/chat/state/turn-session.ts for the temporary caller-to-SQL runtimeMetadata write. Resolve or re-home with a clear owner.

Thread/channel scratch — partial

  • #1320 — Junior 7d TTL instead of chat-sdk 30d
  • #1323 — drop rebuildable conversation stats/backfill from Redis

Still in Redis scratch today: processing/pendingAuth, vision cache, artifacts, sandbox ref, channel configuration.

Remaining

Decide authority and loss behavior before thinning each store. Do not move fields to SQL only to satisfy the slogan, and do not keep accidental durability in Redis.

1. Finish classifying thread/channel scratch

Treat each group separately:

  • Processing / pending auth — valid ephemeral control. Keep in Redis; bind retention to the active pause/turn window where practical.
  • Sandbox ref — ephemeral runtime linkage. Keep in Redis; TTL should match sandbox resumability.
  • Vision summaries — expensive rebuildable cache. Keep as an explicitly versioned cache, or give summaries a durable home; do not relocate just for consistency.
  • Artifacts — user-visible conversation context across turns. 7d expiry may be product-visible loss. Needs a durable conversation-owned projection, or an explicit cache-only decision.
  • Channel configuration — durable user configuration, not scratch. Move off 7d Redis TTL.

2. Thin the conversation work mailbox

junior:conversation:* still mixes in-flight mailbox/control with duplicated durable conversation metadata (destination, actor, channel name, source, title) under a 7d TTL.

  • Remove schema-v1 mailbox compatibility (TODO(v0.110.0)) once aged out
  • Keep mailbox entries, execution status/lease, dedupe ids, recovery cursors
  • Stop mirroring SQL-owned conversation metadata
  • Define terminal/idle deletion or short grace instead of refreshing whole records for 7d
  • Decision: must pending messages survive Redis loss? If yes, Redis cannot be their sole authority.

3. Redesign agent dispatch deliberately

junior:agent_dispatch:* still stores strict 7d records embedding actor, credential subject, destination, visibility, source, input, metadata, attribution, and status, plus legacy rollout fields through v0.116.0.

Before coding:

  • Is a dispatch a durable product/API object whose idempotency/status must survive Redis loss or a >7d delay? If yes, SQL is canonical and Redis keeps locks/wake indexes only.
  • If it is bounded operational state, document the 7d expiry contract and thin nested routing/authority via lookups where possible.
  • Remove legacy execution fields and key/input compatibility after the stated release window.
  • Split terminal retention from active retention.

Working order

  1. Close turn-session rollout cleanup; mark turn sessions done.
  2. Move channel configuration to durable storage.
  3. Decide durable vs cache semantics for artifacts and vision; implement each separately.
  4. Tighten processing/sandbox TTLs to real lease windows.
  5. Thin mailbox metadata; remove schema-v1 compatibility.
  6. Decide whether pending mailbox work must survive Redis loss; move only if yes.
  7. Define dispatch durability/idempotency guarantees; SQL-canonicalize or explicitly bound/thin the Redis record.
  8. Add terminal deletion/grace and remove expired compatibility code for mailbox and dispatch.

Out of scope

  • OAuth user tokens and auth sessions
  • SQL conversation history / events (already durable authority)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions