Skip to content

bug: session key doesn't include sessionId, causing infinite sessions across /new resets #64

Description

@ajspig

Problem

buildSessionKey() in helpers.ts constructs the Honcho session key from ctx.sessionKey + ctx.messageProvider:

const baseKey = ctx?.sessionKey ?? "default";
const provider = ctx?.messageProvider ?? "unknown";
return `${baseKey}-${provider}`;

Two issues have been reported:

1. Infinite session accumulation across /new and /reset

If OpenClaw's sessionKey is a stable chat/room identifier that persists across /new or /reset, Honcho maps all messages into one ever-growing session. The before_reset hook flushes unsaved messages but doesn't signal session boundaries — subsequent messages continue appending to the same Honcho session key.

The plugin hook context includes sessionId (ephemeral UUID that changes per conversation), but buildSessionKey doesn't use it.

2. -unknown suffix from missing messageProvider

Reports indicate OpenClaw 2026.4.5 may not populate ctx.messageProvider, causing all session keys to end in -unknown instead of the correct platform tag (e.g., -telegram, -discord).

Reported workaround

Users have patched buildSessionKey in dist/helpers.js to:

  • Extract the provider from ctx.sessionKey string splitting instead of ctx.messageProvider
  • Append ctx.sessionId to force session separation on /new

Proposed fix

Update buildSessionKey to incorporate ctx.sessionId when available:

export function buildSessionKey(ctx?: {
  sessionKey?: string;
  sessionId?: string;
  messageProvider?: string;
}): string {
  const baseKey = ctx?.sessionKey ?? "default";
  const sessionId = ctx?.sessionId;
  const provider = ctx?.messageProvider;

  const parts = [baseKey];
  if (sessionId) parts.push(sessionId);
  if (provider && provider !== "unknown") parts.push(provider);

  return parts.join("-").replace(/[^a-zA-Z0-9-]/g, "-");
}

Note: This changes the session key format, which means existing sessions won't carry over. The before_reset flush should handle saving any in-flight data, but this is a breaking change to session continuity that should be documented in the changelog.

Needs verification

  • Confirm ctx.messageProvider is not populated on OpenClaw 2026.4.5
  • Confirm ctx.sessionKey is stable across /new / /reset
  • Confirm ctx.sessionId changes on /new / /reset
  • Test the fix doesn't break subagent session key derivation (isSubagentSession checks for :subagent: in sessionKey)

Files affected

File Change
helpers.ts Update buildSessionKey signature and logic
All callers of buildSessionKey Pass ctx.sessionId through

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions