Skip to content

Feature Request: Expose appendAssistantMessageToSessionTranscript in Plugin Runtime API #73274

Description

@kagura-agent

Problem

Plugins that hook agent_end (e.g. for cron output injection) need to persist messages into other sessions' transcripts. Currently, the only cross-session injection API available to plugins is enqueueSystemEvent, which is in-memory only and ephemeral.

This creates a fundamental limitation:

  • enqueueSystemEvent queues events in memory, consumed only when the target session is activated
  • Many sessions (e.g. Discord channel sessions that only receive cron announce delivery) are never activated — no user messages, no heartbeat targeting them
  • If the gateway restarts before the session activates, all queued events are lost
  • Even if events survive, they can accumulate unboundedly and overflow the context window on the next activation

Use Case: Cron Output → Channel Session Context

OpenClaw cron jobs with sessionTarget: "isolated" produce output delivered to Discord channels via announce mode. This delivery sends a Discord message but does not enter the target channel's persistent session context. The channel session never "remembers" what its cron jobs produced.

A plugin hooking agent_end can detect cron completions, extract the output, and should be able to persist it into the target channel's session transcript — so that when the session is eventually activated, the cron output is already in its conversation history.

Proposed Solution

Expose appendAssistantMessageToSessionTranscript (or a similar write API) through api.runtime.agent.session in the plugin runtime:

// In PluginRuntimeCore.agent.session:
appendMessageToTranscript: (params: {
  sessionKey: string;
  text: string;
  role?: "assistant" | "user";  // default: "assistant"
  idempotencyKey?: string;
}) => Promise<{ ok: boolean; reason?: string }>;

This would allow plugins to:

  • Persist messages directly to the JSONL transcript file
  • Target any session by sessionKey
  • Survive gateway restarts (on-disk persistence)
  • Be consumed naturally when the session is next loaded

Alternatives Considered

  1. enqueueSystemEvent — in-memory only, lost on restart, requires session activation to consume
  2. Dynamic import of internal transcript module — fragile (build hashes in filenames), unsupported
  3. Manual JSONL file append — bypasses session manager, risks corruption, misses transcript update events
  4. callGateway with sessions.send — triggers a full agent turn, expensive and side-effect heavy

Context

  • The internal appendAssistantMessageToSessionTranscript function already exists in src/config/sessions/transcript.ts
  • It is used by outbound-send-service.ts and deliver.ts for delivery mirroring
  • It handles idempotency, deduplication, and emits transcript update events
  • It is already exported from config/sessions/transcript.runtime.ts but not wired into the plugin runtime surface

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🌊 off-meta tidepoolIssue quality rating does not apply to this item.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions