openclaw - 💡(How to fix) Fix Feature Request: Expose appendAssistantMessageToSessionTranscript in Plugin Runtime API [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#73274Fetched 2026-04-29 06:21:34
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
commented ×1referenced ×1
  • 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

Root Cause

  • 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

Code Example

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

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

extent analysis

TL;DR

Expose appendAssistantMessageToSessionTranscript through the plugin runtime to enable persistent message injection into session transcripts.

Guidance

  • Review the proposed appendMessageToTranscript API and its parameters to ensure it meets the requirements for persisting messages to session transcripts.
  • Verify that the internal appendAssistantMessageToSessionTranscript function is correctly exported and can be wired into the plugin runtime surface.
  • Consider the idempotency and deduplication features of the proposed API to prevent duplicate messages in the transcript.
  • Test the new API with the openclaw-plugin-cron-context plugin to ensure it correctly persists cron output to the target channel's session transcript.

Example

// Example usage of the proposed appendMessageToTranscript API
const sessionKey = 'target-channel-session-key';
const text = 'Cron job output';
const role = 'assistant';

api.runtime.agent.session.appendMessageToTranscript({
  sessionKey,
  text,
  role,
})
  .then((result) => {
    if (result.ok) {
      console.log('Message appended to transcript');
    } else {
      console.error(`Error appending message: ${result.reason}`);
    }
  })
  .catch((error) => {
    console.error(`Error appending message: ${error}`);
  });

Notes

The proposed solution relies on the internal appendAssistantMessageToSessionTranscript function being correctly implemented and exported. Additionally, the new API should be thoroughly tested to ensure it works as expected and does not introduce any regressions.

Recommendation

Apply the proposed solution by exposing appendAssistantMessageToSessionTranscript through the plugin runtime, as it provides a persistent and reliable way to inject messages into session transcripts, addressing the current limitations of enqueueSystemEvent.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature Request: Expose appendAssistantMessageToSessionTranscript in Plugin Runtime API [1 comments, 1 participants]