Skip to content

Durable CopilotKit AgentRunner on B4 storage: full event replay and live-run rejoin #928

Open

Description

@blove

Why

CopilotKit's connect replays an in-memory runner (InMemoryAgentRunner: 1000 threads, 100 runs per thread, process-local). A Next restart, eviction, serverless or a second instance loses the thread, and the activity kit (@b4run/ag-ui/react + ./copilotkit) then renders nothing for a restored thread. CopilotKit documents AgentRunner (run/connect/isRunning/stop) as pluggable and explicitly invites "a custom runner backed by shared storage (Redis, PostgreSQL, etc.)"; the only first-party options are the single-instance @copilotkit/sqlite-runner and the hosted Intelligence tier. No OSS multi-instance runner exists (research: docs/superpowers/notes/2026-10-04-activity-restore-and-ecosystem-research.md, Part 2 §2 and §5 row A).

What

A @b4run/copilotkit-runner package implementing CopilotKit's AgentRunner over @b4run/sqlite-storage / @b4run/postgres-storage:

  • append every outbound AG-UI event per (threadId, runId);
  • connect() replays RUN_STARTED (marked as replay in metadata), MESSAGES_SNAPSHOT, the stored CUSTOM b4.step / STEP_* / SUBAGENT_* / ACTIVITY_* events, and the terminal RUN_FINISHED keeping outcome: interrupt so pendingInterrupts restores;
  • tail a run still streaming (live rejoin), handle connect-before-run, and prune by retention like the tool-call records.

Advantage

First OSS multi-instance runner, and the only one that restores a step/subagent/approval view losslessly. Depends on the storage decisions in the 2b restore spec (stamps and GET /threads/:id/turns), which may let the runner serve connect from the checkpoint instead of a separate event log.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions