Skip to content

fix(agent): preserve default-agent session routing compatibility#72414

Merged
vincentkoc merged 4 commits into
mainfrom
clownfish/ghcrawl-207038-agentic-merge
Apr 27, 2026
Merged

fix(agent): preserve default-agent session routing compatibility#72414
vincentkoc merged 4 commits into
mainfrom
clownfish/ghcrawl-207038-agentic-merge

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

Credit

This carries forward the useful work from @mushuiyu886 in #64108 and related default-agent routing analysis from #56453.

Validation

  • pnpm -s vitest run src/commands/agent/session.test.ts src/agents/command/session.resolve-session-key.test.ts src/config/sessions/session-key.test.ts
  • pnpm check:changed

Fixes #63992. Related #56370, #56453, #42009.

ProjectClownfish replacement details:

@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Apr 26, 2026
@greptile-apps

greptile-apps Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes session routing for configured non-main default agents: new --to sessions are now keyed and stored under the default agent's namespace, while a backward-compatibility shim (resolveLegacyMainStoreSessionForDefaultAgent) resumes pre-existing agent:main:<mainKey> rows from the main store so no prior session is silently forked. The Slack fallback path and resolveSessionKey signature receive the matching agentId propagation.

Confidence Score: 4/5

Safe to merge; logic is sound and well-tested. One minor test-mock fidelity concern noted.

No P0 or P1 issues found. The session-key routing logic, the legacy fallback, and the shared-store deduplication are all correctly implemented and covered by focused tests. A single P2 observation about the resolveDefaultAgentId mock in session.test.ts not applying normalizeAgentId keeps the score at 4.

No files require special attention. src/agents/command/session.ts carries the most logic and is well-covered by the accompanying tests.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/commands/agent/session.test.ts
Line: 30-38

Comment:
**Test mock omits `normalizeAgentId` on the return value**

The inline mock for `resolveDefaultAgentId` returns the raw `.id` string directly, while the real `resolveDefaultAgentId` in `agent-scope-config.ts` always passes the chosen id through `normalizeAgentId(chosen || DEFAULT_AGENT_ID)` before returning. The divergence means tests won't catch bugs triggered by an unnormalized agent id in config (e.g. `{ id: "MyBot" }` → mock returns `"MyBot"`, real function returns `"mybot"`).

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(clownfish): address review for ghcra..." | Re-trigger Greptile

Comment thread src/commands/agent/session.test.ts Outdated
@vincentkoc

Copy link
Copy Markdown
Member Author

ProjectClownfish follow-up pushed: 5c81bf6

Fix:

  • rebased onto current main
  • resolved Slack SDK import drift from the rebase
  • addressed Greptile's test mock finding by normalizing the mocked default-agent id like production
  • addressed Aisle's cross-agent fallback concern by migrating legacy agent:main:<mainKey> entries into the configured default-agent store instead of returning the legacy main store

Blacksmith validation:

  • pnpm test:serial src/commands/agent/session.test.ts src/agents/command/session.resolve-session-key.test.ts src/config/sessions/session-key.test.ts extensions/slack/src/monitor/monitor.test.ts
  • pnpm check:changed

@aisle-research-bot

aisle-research-bot Bot commented Apr 27, 2026

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟡 Medium Implicit cross-agent session migration copies full SessionEntry (auth/config/ACP) from legacy main store into default agent store
1. 🟡 Implicit cross-agent session migration copies full SessionEntry (auth/config/ACP) from legacy main store into default agent store
Property Value
Severity Medium
CWE CWE-269
Location src/agents/command/session.ts:88-106

Description

resolveSessionKeyForRequest() can silently migrate a legacy agent:main:* row into the configured default-agent store when the user provides only --to (no explicit --agent, --sessionId, or --sessionKey).

During migration, the code copies the entire legacy SessionEntry object via spread ({ ...legacyEntry }) into the target agent’s main session key.

Impacts:

  • Cross-agent data leakage / confusion: state that was previously scoped to the main agent (e.g. delivery context, thread bindings, plugin ownership, etc.) is reused under a different agent id.
  • Privilege / configuration confusion: SessionEntry includes fields such as authProfileOverride, execSecurity, execAsk, permissionProfile, and ACP metadata (acp / runtime options). Copying these across agents can cause the default agent to inherit privileged settings intended only for main.
  • Session fixation (local): if an attacker (or untrusted process) can write to the legacy session store file, they can influence the newly-created default-agent session by planting a crafted legacy entry that will be adopted on first use.

Vulnerable code:

// Copies full legacy entry into a different agent's session key
opts.sessionStore[opts.sessionKey] = { ...legacyEntry };

Recommendation

Avoid copying the entire legacy SessionEntry across agent boundaries.

Safer options:

  1. Only migrate the minimal required fields (typically just sessionId and perhaps updatedAt) and explicitly clear sensitive/agent-specific fields.
  2. Require an explicit opt-in flag or one-time migration command rather than doing this implicitly on plain --to.

Example (minimal-field migration):

const { sessionId, updatedAt } = legacyEntry;
opts.sessionStore[opts.sessionKey] = { sessionId, updatedAt: Date.now() };// do NOT carry over auth/acp/exec overrides, delivery context, plugin owner, etc.

Additionally, consider validating store file permissions / ownership and documenting that session stores must not be writable by untrusted users.


Analyzed PR: #72414 at commit 9e1db57

Last updated on: 2026-04-27T22:04:56Z

@vincentkoc

Copy link
Copy Markdown
Member Author

ProjectClownfish follow-up on latest head a4a9185122:

  • fixed the touched Slack monitor import to use the narrow openclaw/plugin-sdk/agent-runtime surface instead of deprecated config-runtime
  • Blacksmith: pnpm lint:plugins:no-monolithic-plugin-sdk-entry-imports passed
  • Blacksmith: pnpm test:serial src/commands/agent/session.test.ts src/agents/command/session.resolve-session-key.test.ts src/config/sessions/session-key.test.ts extensions/slack/src/monitor/monitor.test.ts passed
  • Blacksmith: pnpm check:changed passed

@vincentkoc
vincentkoc force-pushed the clownfish/ghcrawl-207038-agentic-merge branch from a4a9185 to 9e1db57 Compare April 27, 2026 22:03
@vincentkoc

Copy link
Copy Markdown
Member Author

ProjectClownfish rebased follow-up on latest head 9e1db57:

  • rebased onto current origin/main
  • preserved the Slack narrow openclaw/plugin-sdk/agent-runtime import fix
  • confirmed current base already fixes the Telegram route test helper to use runtime-config-snapshot, removing the stale merge-ref config-runtime failure
  • Blacksmith: pnpm lint:plugins:no-monolithic-plugin-sdk-entry-imports && pnpm check:deprecated-internal-config-api passed
  • Blacksmith: pnpm test:serial src/commands/agent/session.test.ts src/agents/command/session.resolve-session-key.test.ts src/config/sessions/session-key.test.ts extensions/slack/src/monitor/monitor.test.ts passed
  • Blacksmith: pnpm check:changed passed

@vincentkoc
vincentkoc merged commit 61a18e5 into main Apr 27, 2026
67 checks passed
@vincentkoc
vincentkoc deleted the clownfish/ghcrawl-207038-agentic-merge branch April 27, 2026 22:09
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…nclaw#72414)

* fix(agent): preserve default-agent session routing compatibility

* fix(clownfish): address review for ghcrawl-207038-agentic-merge (1)

* fix(agent): migrate legacy default-agent sessions

* fix(slack): use narrow agent runtime import
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…nclaw#72414)

* fix(agent): preserve default-agent session routing compatibility

* fix(clownfish): address review for ghcrawl-207038-agentic-merge (1)

* fix(agent): migrate legacy default-agent sessions

* fix(slack): use narrow agent runtime import
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…nclaw#72414)

* fix(agent): preserve default-agent session routing compatibility

* fix(clownfish): address review for ghcrawl-207038-agentic-merge (1)

* fix(agent): migrate legacy default-agent sessions

* fix(slack): use narrow agent runtime import
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…nclaw#72414)

* fix(agent): preserve default-agent session routing compatibility

* fix(clownfish): address review for ghcrawl-207038-agentic-merge (1)

* fix(agent): migrate legacy default-agent sessions

* fix(slack): use narrow agent runtime import
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…nclaw#72414)

* fix(agent): preserve default-agent session routing compatibility

* fix(clownfish): address review for ghcrawl-207038-agentic-merge (1)

* fix(agent): migrate legacy default-agent sessions

* fix(slack): use narrow agent runtime import
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…nclaw#72414)

* fix(agent): preserve default-agent session routing compatibility

* fix(clownfish): address review for ghcrawl-207038-agentic-merge (1)

* fix(agent): migrate legacy default-agent sessions

* fix(slack): use narrow agent runtime import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: slack Channel integration: slack clawsweeper Tracked by ClawSweeper automation commands Command implementations maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: session key write still hardcodes DEFAULT_AGENT_ID after PR #30654 (regression of #29683)

1 participant