mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-02 14:07:14 +00:00
Allow ACP lineage in sessions.patch
This commit is contained in:
@@ -252,6 +252,29 @@ describe("gateway sessions patch", () => {
|
|||||||
expect(entry.spawnDepth).toBe(2);
|
expect(entry.spawnDepth).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("sets spawnedBy for ACP sessions", async () => {
|
||||||
|
const entry = expectPatchOk(
|
||||||
|
await runPatch({
|
||||||
|
storeKey: "agent:main:acp:child",
|
||||||
|
patch: {
|
||||||
|
key: "agent:main:acp:child",
|
||||||
|
spawnedBy: "agent:main:main",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(entry.spawnedBy).toBe("agent:main:main");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("sets spawnDepth for ACP sessions", async () => {
|
||||||
|
const entry = expectPatchOk(
|
||||||
|
await runPatch({
|
||||||
|
storeKey: "agent:main:acp:child",
|
||||||
|
patch: { key: "agent:main:acp:child", spawnDepth: 2 },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(entry.spawnDepth).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
test("rejects spawnDepth on non-subagent sessions", async () => {
|
test("rejects spawnDepth on non-subagent sessions", async () => {
|
||||||
const result = await runPatch({
|
const result = await runPatch({
|
||||||
patch: { key: MAIN_SESSION_KEY, spawnDepth: 1 },
|
patch: { key: MAIN_SESSION_KEY, spawnDepth: 1 },
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import type { SessionEntry } from "../config/sessions.js";
|
import type { SessionEntry } from "../config/sessions.js";
|
||||||
import {
|
import {
|
||||||
|
isAcpSessionKey,
|
||||||
isSubagentSessionKey,
|
isSubagentSessionKey,
|
||||||
normalizeAgentId,
|
normalizeAgentId,
|
||||||
parseAgentSessionKey,
|
parseAgentSessionKey,
|
||||||
@@ -62,6 +63,10 @@ function normalizeExecAsk(raw: string): "off" | "on-miss" | "always" | undefined
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function supportsSpawnLineage(storeKey: string): boolean {
|
||||||
|
return isSubagentSessionKey(storeKey) || isAcpSessionKey(storeKey);
|
||||||
|
}
|
||||||
|
|
||||||
export async function applySessionsPatchToStore(params: {
|
export async function applySessionsPatchToStore(params: {
|
||||||
cfg: OpenClawConfig;
|
cfg: OpenClawConfig;
|
||||||
store: Record<string, SessionEntry>;
|
store: Record<string, SessionEntry>;
|
||||||
@@ -97,8 +102,8 @@ export async function applySessionsPatchToStore(params: {
|
|||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
return invalid("invalid spawnedBy: empty");
|
return invalid("invalid spawnedBy: empty");
|
||||||
}
|
}
|
||||||
if (!isSubagentSessionKey(storeKey)) {
|
if (!supportsSpawnLineage(storeKey)) {
|
||||||
return invalid("spawnedBy is only supported for subagent:* sessions");
|
return invalid("spawnedBy is only supported for subagent:* or acp:* sessions");
|
||||||
}
|
}
|
||||||
if (existing?.spawnedBy && existing.spawnedBy !== trimmed) {
|
if (existing?.spawnedBy && existing.spawnedBy !== trimmed) {
|
||||||
return invalid("spawnedBy cannot be changed once set");
|
return invalid("spawnedBy cannot be changed once set");
|
||||||
@@ -114,8 +119,8 @@ export async function applySessionsPatchToStore(params: {
|
|||||||
return invalid("spawnDepth cannot be cleared once set");
|
return invalid("spawnDepth cannot be cleared once set");
|
||||||
}
|
}
|
||||||
} else if (raw !== undefined) {
|
} else if (raw !== undefined) {
|
||||||
if (!isSubagentSessionKey(storeKey)) {
|
if (!supportsSpawnLineage(storeKey)) {
|
||||||
return invalid("spawnDepth is only supported for subagent:* sessions");
|
return invalid("spawnDepth is only supported for subagent:* or acp:* sessions");
|
||||||
}
|
}
|
||||||
const numeric = Number(raw);
|
const numeric = Number(raw);
|
||||||
if (!Number.isInteger(numeric) || numeric < 0) {
|
if (!Number.isInteger(numeric) || numeric < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user