Skip to content

Commit 10b89a3

Browse files
committed
refactor: remove parent fork config knob
1 parent 4f31cbb commit 10b89a3

18 files changed

Lines changed: 80 additions & 168 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5808,7 +5808,7 @@ Docs: https://docs.openclaw.ai
58085808
- Slack/Threading: when `replyToMode="all"` auto-threads top-level Slack DMs, seed the thread session key from the message `ts` so the initial message and later replies share the same isolated `:thread:` session instead of falling back to base DM context. (#26849) Thanks @calder-sandy.
58095809
- Agents/Subagents delivery: refactor subagent completion announce dispatch into an explicit queue/direct/fallback state machine, recover outbound channel-plugin resolution in cold/stale plugin-registry states across announce/message/gateway send paths, finalize cleanup bookkeeping when announce flow rejects, and treat Telegram sends without `message_id` as delivery failures (instead of false-success `"unknown"` IDs). (#26867, #25961, #26803, #25069, #26741) Thanks @SmithLabsLLC and @docaohieu2808.
58105810
- Telegram/Webhook: pre-initialize webhook bots, switch webhook processing to callback-mode JSON handling, and preserve full near-limit payload reads under delayed handlers to prevent webhook request hangs and dropped updates. (#26156).
5811-
- Slack/Session threads: prevent oversized parent-session inheritance from silently bricking new thread sessions, surface embedded context-overflow empty-result failures to users, and share the PI parent-fork fallback between channel threads and subagents. The legacy `session.parentForkMaxTokens` compatibility guard remains available but is no longer the preferred tuning surface. (#26912) Thanks @markshields-tl.
5811+
- Slack/Session threads: prevent oversized parent-session inheritance from silently bricking new thread sessions, surface embedded context-overflow empty-result failures to users, and share the PI parent-fork fallback between channel threads and subagents. The old `session.parentForkMaxTokens` tuning surface is removed; `openclaw doctor --fix` strips it from legacy configs. (#26912) Thanks @markshields-tl.
58125812
- Cron/Message multi-account routing: honor explicit `delivery.accountId` for isolated cron delivery resolution, and when `message.send` omits `accountId`, fall back to the sending agent's bound channel account instead of defaulting to the global account. (#27015, #26975) Thanks @lbo728 and @stakeswky.
58135813
- Gateway/Message media roots: thread `agentId` through gateway `send` RPC and prefer explicit `agentId` over session/default resolution so non-default agent workspace media sends no longer fail with `LocalMediaAccessError`; added regression coverage for agent precedence and blank-agent fallback. (#23249) Thanks @Sid-Qin.
58145814
- Followups/Routing: when explicit origin routing fails, allow same-channel fallback dispatch (while still blocking cross-channel fallback) so followup replies do not get dropped on transient origin-adapter failures. (#26109) Thanks @Sid-Qin.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
f40d6dea3b81c42d5af9e340f091d34b9e39321d171fade6115da594ba90522f config-baseline.json
2-
40b1f91714d6f17e2718ea5d34c135550f5a39fe47f781cddc153cf3a59fe2e7 config-baseline.core.json
1+
0020a49cdf07b79fddfed9584f10323ef77e3ca5c7f907d441c1f2e3f45932c9 config-baseline.json
2+
8193fd771c9fa50e77c71ff69d41015e6dc02d140182ceea3baaa17713f04b18 config-baseline.core.json
33
f42329d45c095881bd226bdb192c235980658fd250606d0c0badc2b12f12f5d3 config-baseline.channel.json
44
af71b84b2411d8ccabcc6e09de0ee41f8212ff9869a6677698b6e7e3afdfaa47 config-baseline.plugin.json

‎docs/gateway/config-agents.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,6 @@ See [Multi-Agent Sandbox & Tools](/tools/multi-agent-sandbox-tools) for preceden
12101210
- **`identityLinks`**: map canonical ids to provider-prefixed peers for cross-channel session sharing. Dock commands such as `/dock_discord` use the same map to switch the active session's reply route to another linked channel peer; see [Channel docking](/concepts/channel-docking).
12111211
- **`reset`**: primary reset policy. `daily` resets at `atHour` local time; `idle` resets after `idleMinutes`. When both configured, whichever expires first wins. Daily reset freshness uses the session row's `sessionStartedAt`; idle reset freshness uses `lastInteractionAt`. Background/system-event writes such as heartbeat, cron wakeups, exec notifications, and gateway bookkeeping can update `updatedAt`, but they do not keep daily/idle sessions fresh.
12121212
- **`resetByType`**: per-type overrides (`direct`, `group`, `thread`). Legacy `dm` accepted as alias for `direct`.
1213-
- **`parentForkMaxTokens`**: deprecated compatibility guard for the historical parent fork ceiling (default `100000`).
1214-
- Channel thread sessions and subagent `context="fork"` now use the same parent fork decision path.
1215-
- When the active parent branch is too large, OpenClaw starts with isolated context instead of failing or inheriting unusable history.
1216-
- Set `0` only if you intentionally want to disable this guard.
12171213
- **`mainKey`**: legacy field. Runtime always uses `"main"` for the main direct-chat bucket.
12181214
- **`agentToAgent.maxPingPongTurns`**: maximum reply-back turns between agents during agent-to-agent exchanges (integer, range: `0`–`5`). `0` disables ping-pong chaining.
12191215
- **`sendPolicy`**: match by `channel`, `chatType` (`direct|group|channel`, with legacy `dm` alias), `keyPrefix`, or `rawKeyPrefix`. First deny wins.

‎docs/reference/session-management-compaction.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Rules of thumb:
148148
- **Daily reset** (default 4:00 AM local time on the gateway host) creates a new `sessionId` on the next message after the reset boundary.
149149
- **Idle expiry** (`session.reset.idleMinutes` or legacy `session.idleMinutes`) creates a new `sessionId` when a message arrives after the idle window. When daily + idle are both configured, whichever expires first wins.
150150
- **System events** (heartbeat, cron wakeups, exec notifications, gateway bookkeeping) may mutate the session row but do not extend daily/idle reset freshness. Reset rollover discards queued system-event notices for the previous session before the fresh prompt is built.
151-
- **Parent fork policy** uses PI's active branch when creating a thread or subagent fork. If that branch is too large, OpenClaw starts the child with isolated context instead of failing or inheriting unusable history. The legacy `session.parentForkMaxTokens` key remains as a deprecated compatibility guard; set `0` only if you intentionally want to disable it.
151+
- **Parent fork policy** uses PI's active branch when creating a thread or subagent fork. If that branch is too large, OpenClaw starts the child with isolated context instead of failing or inheriting unusable history. The sizing policy is automatic; legacy `session.parentForkMaxTokens` config is removed by `openclaw doctor --fix`.
152152

153153
Implementation detail: the decision happens in `initSessionState()` in `src/auto-reply/reply/session.ts`.
154154

‎src/agents/subagent-spawn.test-helpers.ts‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,8 @@ export async function loadSubagentSpawnModuleForTest(params: {
184184
resolveContextEngine: params.resolveContextEngineMock ?? (async () => ({})),
185185
resolveParentForkDecision:
186186
params.resolveParentForkDecisionMock ??
187-
(async (forkParams: {
188-
cfg?: { session?: { parentForkMaxTokens?: unknown } };
189-
parentEntry?: { totalTokens?: unknown };
190-
}) => {
191-
const configured = forkParams.cfg?.session?.parentForkMaxTokens;
192-
const maxTokens =
193-
typeof configured === "number" && Number.isFinite(configured) && configured >= 0
194-
? Math.floor(configured)
195-
: 100_000;
187+
(async (forkParams: { parentEntry?: { totalTokens?: unknown } }) => {
188+
const maxTokens = 100_000;
196189
const parentTokens =
197190
typeof forkParams.parentEntry?.totalTokens === "number" &&
198191
Number.isFinite(forkParams.parentEntry.totalTokens)

‎src/agents/subagent-spawn.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ async function prepareSubagentSessionContext(params: {
364364
);
365365
}
366366
const forkDecision = await subagentSpawnDeps.resolveParentForkDecision({
367-
cfg: params.cfg,
368367
parentEntry,
369368
storePath: parentTarget.storePath,
370369
});

‎src/auto-reply/reply/session-fork.ts‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { SessionEntry } from "../../config/sessions/types.js";
2-
import type { OpenClawConfig } from "../../config/types.openclaw.js";
32

43
/**
54
* Default max parent token count beyond which thread/session parent forking is skipped.
@@ -28,19 +27,6 @@ function loadSessionForkRuntime(): Promise<typeof import("./session-fork.runtime
2827
return sessionForkRuntimePromise;
2928
}
3029

31-
/**
32-
* Deprecated compatibility guard for deployments that explicitly tuned the
33-
* historical thread fork ceiling. New behavior should use the shared parent
34-
* fork decision helper so channel threads and subagents degrade the same way.
35-
*/
36-
export function resolveParentForkMaxTokens(cfg: OpenClawConfig): number {
37-
const configured = cfg.session?.parentForkMaxTokens;
38-
if (typeof configured === "number" && Number.isFinite(configured) && configured >= 0) {
39-
return Math.floor(configured);
40-
}
41-
return DEFAULT_PARENT_FORK_MAX_TOKENS;
42-
}
43-
4430
export function formatParentForkTooLargeMessage(params: {
4531
parentTokens: number;
4632
maxTokens: number;
@@ -52,14 +38,10 @@ export function formatParentForkTooLargeMessage(params: {
5238
}
5339

5440
export async function resolveParentForkDecision(params: {
55-
cfg: OpenClawConfig;
5641
parentEntry: SessionEntry;
5742
storePath: string;
5843
}): Promise<ParentForkDecision> {
59-
const maxTokens = resolveParentForkMaxTokens(params.cfg);
60-
if (maxTokens <= 0) {
61-
return { status: "fork", maxTokens };
62-
}
44+
const maxTokens = DEFAULT_PARENT_FORK_MAX_TOKENS;
6345
const parentTokens = await resolveParentForkTokenCount({
6446
parentEntry: params.parentEntry,
6547
storePath: params.storePath,

‎src/auto-reply/reply/session.test.ts‎

Lines changed: 2 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,8 @@ vi.mock("./session-fork.js", () => ({
5252
sessionForkMocks.forkSessionFromParent(...args),
5353
resolveParentForkTokenCount: (...args: [{ parentEntry: SessionEntry; storePath: string }]) =>
5454
sessionForkMocks.resolveParentForkTokenCount(...args),
55-
resolveParentForkDecision: async (params: {
56-
cfg: { session?: { parentForkMaxTokens?: unknown } };
57-
parentEntry: SessionEntry;
58-
storePath: string;
59-
}) => {
60-
const configured = params.cfg.session?.parentForkMaxTokens;
61-
const maxTokens =
62-
typeof configured === "number" && Number.isFinite(configured) && configured >= 0
63-
? Math.floor(configured)
64-
: 100_000;
65-
if (maxTokens <= 0) {
66-
return { status: "fork", maxTokens };
67-
}
55+
resolveParentForkDecision: async (params: { parentEntry: SessionEntry; storePath: string }) => {
56+
const maxTokens = 100_000;
6857
const parentTokens = await sessionForkMocks.resolveParentForkTokenCount({
6958
parentEntry: params.parentEntry,
7059
storePath: params.storePath,
@@ -625,84 +614,6 @@ describe("initSessionState thread forking", () => {
625614
expect(sessionForkMocks.forkSessionFromParent).not.toHaveBeenCalled();
626615
});
627616

628-
it("respects session.parentForkMaxTokens override", async () => {
629-
const root = await makeCaseDir("openclaw-thread-session-overflow-override-");
630-
const sessionsDir = path.join(root, "sessions");
631-
await fs.mkdir(sessionsDir);
632-
633-
const parentSessionId = "parent-override";
634-
const parentSessionFile = path.join(sessionsDir, "parent.jsonl");
635-
const header = {
636-
type: "session",
637-
version: 3,
638-
id: parentSessionId,
639-
timestamp: new Date().toISOString(),
640-
cwd: process.cwd(),
641-
};
642-
const message = {
643-
type: "message",
644-
id: "m1",
645-
parentId: null,
646-
timestamp: new Date().toISOString(),
647-
message: { role: "user", content: "Parent prompt" },
648-
};
649-
const assistantMessage = {
650-
type: "message",
651-
id: "m2",
652-
parentId: "m1",
653-
timestamp: new Date().toISOString(),
654-
message: { role: "assistant", content: "Parent reply" },
655-
};
656-
await fs.writeFile(
657-
parentSessionFile,
658-
`${JSON.stringify(header)}\n${JSON.stringify(message)}\n${JSON.stringify(assistantMessage)}\n`,
659-
"utf-8",
660-
);
661-
662-
const storePath = path.join(root, "sessions.json");
663-
const parentSessionKey = "agent:main:slack:channel:c1";
664-
await writeSessionStoreFast(storePath, {
665-
[parentSessionKey]: {
666-
sessionId: parentSessionId,
667-
sessionFile: parentSessionFile,
668-
updatedAt: Date.now(),
669-
totalTokens: 170_000,
670-
},
671-
});
672-
673-
const cfg = {
674-
session: {
675-
store: storePath,
676-
parentForkMaxTokens: 200_000,
677-
},
678-
} as OpenClawConfig;
679-
680-
const threadSessionKey = "agent:main:slack:channel:c1:thread:789";
681-
const result = await initSessionState({
682-
ctx: {
683-
Body: "Thread reply",
684-
SessionKey: threadSessionKey,
685-
ParentSessionKey: parentSessionKey,
686-
},
687-
cfg,
688-
commandAuthorized: true,
689-
});
690-
691-
expect(result.sessionEntry.forkedFromParent).toBe(true);
692-
expect(result.sessionEntry.sessionFile).toBeTruthy();
693-
const forkedContent = await fs.readFile(result.sessionEntry.sessionFile ?? "", "utf-8");
694-
const headerLine = forkedContent.split(/\r?\n/).find((line) => line.trim().length > 0);
695-
if (!headerLine) {
696-
throw new Error("Missing session header");
697-
}
698-
const parsedHeader = JSON.parse(headerLine) as { parentSession?: string };
699-
const expectedParentSession = await fs.realpath(parentSessionFile);
700-
const actualParentSession = parsedHeader.parentSession
701-
? await fs.realpath(parsedHeader.parentSession)
702-
: undefined;
703-
expect(actualParentSession).toBe(expectedParentSession);
704-
});
705-
706617
it("records topic-specific session files when MessageThreadId is present", async () => {
707618
const root = await makeCaseDir("openclaw-topic-session-");
708619
const storePath = path.join(root, "sessions.json");

‎src/auto-reply/reply/session.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ export async function initSessionState(params: {
701701
) {
702702
const parentEntry = sessionStore[parentSessionKey];
703703
const forkDecision = await resolveParentForkDecision({
704-
cfg,
705704
parentEntry,
706705
storePath,
707706
});

‎src/commands/doctor/shared/legacy-config-migrate.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ describe("legacy session maintenance migrate", () => {
4141
});
4242
});
4343

44+
describe("legacy session parent fork migrate", () => {
45+
it("removes legacy session.parentForkMaxTokens", () => {
46+
const res = migrateLegacyConfigForTest({
47+
session: {
48+
store: "sessions.json",
49+
parentForkMaxTokens: 200_000,
50+
},
51+
});
52+
53+
expect(res.config?.session).toEqual({
54+
store: "sessions.json",
55+
});
56+
expect(res.changes).toContain(
57+
"Removed session.parentForkMaxTokens; parent fork sizing is automatic.",
58+
);
59+
});
60+
});
61+
4462
describe("legacy thread binding spawn migrate", () => {
4563
it("moves matching split spawn flags to unified spawnSessions", () => {
4664
const res = migrateLegacyConfigForTest({

0 commit comments

Comments
 (0)