openclaw - 💡(How to fix) Fix [Feature]: Subagent session reuse for expert agents (avoid new session per spawn) [1 comments, 2 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#50963Fetched 2026-04-08 01:06:14
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1labeled ×1

Allow expert subagents to reuse an existing session instead of creating a new one every sessions_spawn(mode="run")

Root Cause

Allow expert subagents to reuse an existing session instead of creating a new one every sessions_spawn(mode="run")

RAW_BUFFERClick to expand / collapse

Summary

Allow expert subagents to reuse an existing session instead of creating a new one every sessions_spawn(mode="run")

Problem to solve

Every sessions_spawn(mode="run") generates a new random UUID (subagent-spawn.ts:374), so expert agents lose all conversation context between spawns. The existing mode="session" + thread=true fixes this but requires subagent_spawning hook — only Discord and Feishu implement it. Teams has no path to session reuse.

Proposed solution

Option A: Add subagent_spawning hook to Teams (ref: Discord/Feishu implementations) Option B (preferred): Registry-based reuse in core — on spawn, check registry for active session with same agentId, reuse if within TTL. New sessionTarget: "reuse" parameter. No hook dependency.

Alternatives considered

No response

Impact

All multi-expert setups on Teams. Medium severity, daily frequency. Experts can't build on prior analysis.

Evidence/examples

Discord (extensions/discord/src/subagent-hooks.ts) and Feishu already have it. Teams declares threads: true but missing hook.

Additional information

No response

extent analysis

Fix Plan

To implement the preferred solution (Option B), follow these steps:

  • Introduce a new parameter sessionTarget with value "reuse" in the sessions_spawn function.
  • Create a registry to store active sessions with their corresponding agentId and a time-to-live (TTL) value.
  • When sessions_spawn is called with mode="run" and sessionTarget="reuse", check the registry for an active session with the same agentId within the TTL.
  • If a matching session is found, reuse it instead of creating a new one.

Example code snippet:

// registry.ts
interface SessionRegistry {
  [agentId: string]: { sessionId: string; expiresAt: number };
}

const sessionRegistry: SessionRegistry = {};

export function getSession(agentId: string, ttl: number): string | null {
  const now = Date.now();
  const session = sessionRegistry[agentId];
  if (session && session.expiresAt > now) {
    return session.sessionId;
  }
  return null;
}

export function setSession(agentId: string, sessionId: string, ttl: number): void {
  const expiresAt = Date.now() + ttl;
  sessionRegistry[agentId] = { sessionId, expiresAt };
}

// subagent-spawn.ts
import { getSession, setSession } from './registry';

export function sessionsSpawn(mode: string, agentId: string, sessionTarget: string): string {
  if (mode === 'run' && sessionTarget === 'reuse') {
    const sessionId = getSession(agentId, 3600000); // 1 hour TTL
    if (sessionId) {
      return sessionId;
    }
  }
  const newSessionId = generateUUID();
  setSession(agentId, newSessionId, 3600000); // 1 hour TTL
  return newSessionId;
}

Verification

To verify the fix, test the sessions_spawn function with mode="run" and sessionTarget="reuse" for an agent with an existing active session. The function should return the existing session ID instead of generating a new one.

Extra Tips

  • Adjust the TTL value according to your specific use case and requirements.
  • Consider implementing a mechanism to remove expired sessions from the registry to prevent memory leaks.

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]: Subagent session reuse for expert agents (avoid new session per spawn) [1 comments, 2 participants]