Skip to content

Commit 9bfe292

Browse files
HermanZengjalehman
andauthored
fix(sessions): keep gateway responsive while large transcript archives are built (#112424)
* fix(sessions): keep gateway responsive during transcript archiving * test(sessions): strengthen archive worker coverage * fix(sessions): bound archive worker concurrency * test(sessions): normalize rollback paths on Windows * fix(sessions): load source archive worker on node 22 * fix(sessions): align archive fencing with session windows * test(sessions): adapt cleanup race to archive worker * fix(sessions): harden archive worker lifecycle * style(sessions): format archive lifecycle tests * fix(sessions): release writer lane during archive work --------- Co-authored-by: Josh Lehman <[email protected]>
1 parent bfcce12 commit 9bfe292

26 files changed

Lines changed: 1844 additions & 149 deletions

‎config/knip.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ const rootEntries = [
122122
"scripts/e2e/*.{js,mjs,ts}!",
123123
"scripts/e2e/lib/**/{assertions,probe,mock-server}.{js,mjs,ts}!",
124124
"src/audit/audit-event-writer.worker.ts!",
125+
// Loaded by URL from the SQLite lifecycle archive owner.
126+
"src/config/sessions/session-accessor.sqlite-archive.worker.ts!",
125127
"src/state/openclaw-database-verify.worker.ts!",
126128
"src/agents/model-provider-auth.worker.ts!",
127129
// Loaded by URL from setup-inference-detection.ts; no static import edge exists.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@
18981898
"test:unit:fast:audit": "node scripts/test-unit-fast-audit.mjs",
18991899
"test:voicecall:closedloop": "node scripts/test-voicecall-closedloop.mjs",
19001900
"test:watch": "node scripts/test-projects.mjs --watch",
1901-
"test:windows:ci": "node scripts/test-projects.mjs src/shared/runtime-import.test.ts src/infra/sqlite-snapshot.test.ts src/infra/ssh-client.windows.test.ts src/infra/update-managed-service-handoff.test.ts src/infra/exec-allowlist-pattern.test.ts src/infra/fs-safe-remove.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/commands/backup-verify.test.ts src/infra/state-migrations.legacy-session-store.test.ts src/test-utils/openclaw-test-state.test.ts src/agents/sessions/windows-git-bash-path.test.ts src/agents/bash-tools.exec.script-preflight.test.ts src/process/exec.windows.test.ts src/process/exec.windows.integration.test.ts src/process/windows-command.test.ts src/infra/windows-install-roots.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/daemon/schtasks.startup-fallback.test.ts extensions/lobster/src/lobster-runner.test.ts extensions/mxc/test/mxc-backend.test.ts extensions/mxc/test/sandbox-policy-loader.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/npm-runner.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ts-topology.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts",
1901+
"test:windows:ci": "node scripts/test-projects.mjs src/shared/runtime-import.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/infra/sqlite-snapshot.test.ts src/infra/ssh-client.windows.test.ts src/infra/update-managed-service-handoff.test.ts src/infra/exec-allowlist-pattern.test.ts src/infra/fs-safe-remove.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/commands/backup-verify.test.ts src/infra/state-migrations.legacy-session-store.test.ts src/test-utils/openclaw-test-state.test.ts src/agents/sessions/windows-git-bash-path.test.ts src/agents/bash-tools.exec.script-preflight.test.ts src/process/exec.windows.test.ts src/process/exec.windows.integration.test.ts src/process/windows-command.test.ts src/infra/windows-install-roots.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/daemon/schtasks.startup-fallback.test.ts extensions/lobster/src/lobster-runner.test.ts extensions/mxc/test/mxc-backend.test.ts extensions/mxc/test/sandbox-policy-loader.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/npm-runner.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ts-topology.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts",
19021902
"test:windows:schtasks:integration": "node scripts/run-with-env.mjs CI_WINDOWS_SCHTASKS_INTEGRATION=1 OPENCLAW_E2E_VERBOSE=1 OPENCLAW_VITEST_MAX_WORKERS=1 -- node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts",
19031903
"tool-display:check": "node --import tsx scripts/tool-display.ts --check",
19041904
"tool-display:write": "node --import tsx scripts/tool-display.ts --write",

‎scripts/ci-changed-scope.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ const NODE_SCOPE_RE =
5050
/^(src\/|test\/|extensions\/|packages\/|scripts\/|ui\/|\.github\/|openclaw\.mjs$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|tsconfig.*\.json$|vitest.*\.ts$|tsdown\.config\.ts$|\.oxlintrc\.json$|\.oxfmtrc\.jsonc$)/;
5151
const WINDOWS_SQLITE_SCOPE_RE = /^src\/(?:state\/|.*sqlite.*\.ts$)/;
5252
const WINDOWS_SCOPE_RE =
53-
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:exec-allowlist-pattern|fs-safe-remove)(?:\.test)?|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mjs|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|js)|lib\/(?:direct-run\.mjs|format-generated-module\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
53+
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:exec-allowlist-pattern|fs-safe-remove)(?:\.test)?|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mjs|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|js)|lib\/(?:direct-run\.mjs|format-generated-module\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
5454
const WINDOWS_TEST_SCOPE_RE =
55-
/^(extensions\/mxc\/test\/(?:mxc-backend|sandbox-policy-loader)\.test\.ts$|src\/agents\/bash-tools\.exec\.script-preflight\.test\.ts$|src\/config\/sessions\/store\.session-lifecycle-mutation\.test\.ts$|src\/process\/(?:exec\.windows|windows-command)\.test\.ts$|src\/infra\/(?:exec-allowlist-pattern|fs-safe-remove|ssh-client\.windows|update-managed-service-handoff|windows-install-roots)\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|src\/state\/openclaw-database-paths\.windows\.test\.ts$|src\/test-utils\/openclaw-test-state\.test\.ts$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
55+
/^(extensions\/mxc\/test\/(?:mxc-backend|sandbox-policy-loader)\.test\.ts$|src\/agents\/bash-tools\.exec\.script-preflight\.test\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive\.worker|store\.session-lifecycle-mutation)\.test\.ts$|src\/process\/(?:exec\.windows|windows-command)\.test\.ts$|src\/infra\/(?:exec-allowlist-pattern|fs-safe-remove|ssh-client\.windows|update-managed-service-handoff|windows-install-roots)\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|src\/state\/openclaw-database-paths\.windows\.test\.ts$|src\/test-utils\/openclaw-test-state\.test\.ts$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
5656
const WINDOWS_DAEMON_SCOPE_RE =
5757
/^src\/daemon\/(?:schtasks(?:[-.][^/]+)?|runtime-hints\.windows-paths(?:\.test)?|test-helpers\/schtasks-(?:base-mocks|fixtures))\.ts$/;
5858
const CONTROL_UI_I18N_SCOPE_RE =

‎scripts/release-check.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const requiredPathGroups = [
114114
"dist/agents/compaction-planning.worker.js",
115115
"dist/agents/model-provider-auth.worker.js",
116116
"dist/audit/audit-event-writer.worker.js",
117+
"dist/config/sessions/session-accessor.sqlite-archive.worker.js",
117118
"dist/config/sessions/session-transcript-reconcile.worker.js",
118119
"dist/state/openclaw-database-verify.worker.js",
119120
"dist/system-agent/setup-inference-detection.worker.js",

‎src/config/sessions/incognito-session-transcript.test.ts‎

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ import os from "node:os";
33
import path from "node:path";
44
import { afterEach, describe, expect, it } from "vitest";
55
import { SessionManager } from "../../agents/sessions/session-manager.js";
6-
import { closeOpenClawAgentDatabasesForTest } from "../../state/openclaw-agent-db.js";
6+
import {
7+
closeOpenClawAgentDatabasesForTest,
8+
resolveIncognitoOpenClawAgentSqlitePath,
9+
} from "../../state/openclaw-agent-db.js";
710
import { resolveStorePath } from "./paths.js";
8-
import { createSessionEntryWithTranscript, loadSessionEntry } from "./session-accessor.js";
11+
import {
12+
createSessionEntryWithTranscript,
13+
listSessionEntries,
14+
loadSessionEntry,
15+
loadTranscriptEvents,
16+
patchSessionEntry,
17+
} from "./session-accessor.js";
18+
import { replaceSqliteTranscriptEvents } from "./session-accessor.sqlite.js";
919

1020
const sessionKey = "agent:main:dashboard:incognito-round-trip";
1121

@@ -81,4 +91,83 @@ describe("incognito transcript access", () => {
8191
fs.rmSync(cwd, { force: true, recursive: true });
8292
}
8393
});
94+
95+
it("prunes incognito transcripts in process without publishing a disk archive", async () => {
96+
const stateDir = fs.realpathSync(
97+
fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), "incognito-maintenance-")),
98+
);
99+
const env = { ...process.env, OPENCLAW_STATE_DIR: stateDir };
100+
const storePath = resolveIncognitoOpenClawAgentSqlitePath({ agentId: "main", env });
101+
const archiveDirectory = path.join(path.dirname(path.dirname(storePath)), "sessions");
102+
const staleScope = {
103+
agentId: "main",
104+
env,
105+
sessionKey: "agent:main:dashboard:incognito-stale",
106+
storePath,
107+
};
108+
const activeScope = {
109+
agentId: "main",
110+
env,
111+
sessionKey: "agent:main:dashboard:incognito-active",
112+
storePath,
113+
};
114+
const now = Date.now();
115+
116+
try {
117+
await patchSessionEntry(
118+
staleScope,
119+
() => ({ sessionId: "incognito-stale-session", updatedAt: now }),
120+
{
121+
fallbackEntry: { sessionId: "incognito-stale-session", updatedAt: now },
122+
replaceEntry: true,
123+
skipMaintenance: true,
124+
},
125+
);
126+
await replaceSqliteTranscriptEvents({ ...staleScope, sessionId: "incognito-stale-session" }, [
127+
{
128+
id: "incognito-stale-event",
129+
timestamp: new Date(now).toISOString(),
130+
type: "metadata",
131+
},
132+
]);
133+
await patchSessionEntry(
134+
activeScope,
135+
() => ({ sessionId: "incognito-active-session", updatedAt: now + 1 }),
136+
{
137+
fallbackEntry: { sessionId: "incognito-active-session", updatedAt: now + 1 },
138+
replaceEntry: true,
139+
skipMaintenance: true,
140+
},
141+
);
142+
143+
await patchSessionEntry(activeScope, () => ({ model: "gpt-test" }), {
144+
maintenanceConfig: {
145+
highWaterBytes: null,
146+
maxDiskBytes: null,
147+
maxEntries: 1,
148+
mode: "enforce",
149+
modelRunPruneAfterMs: 24 * 60 * 60 * 1000,
150+
pruneAfterMs: 365 * 24 * 60 * 60 * 1000,
151+
resetArchiveRetentionMs: null,
152+
},
153+
});
154+
155+
expect(
156+
listSessionEntries({ agentId: "main", env, storePath }).map(
157+
(summary) => summary.sessionKey,
158+
),
159+
).toEqual([activeScope.sessionKey]);
160+
await expect(
161+
loadTranscriptEvents({
162+
...staleScope,
163+
sessionId: "incognito-stale-session",
164+
}),
165+
).resolves.toEqual([]);
166+
expect(fs.existsSync(storePath)).toBe(false);
167+
expect(fs.existsSync(archiveDirectory)).toBe(false);
168+
} finally {
169+
closeOpenClawAgentDatabasesForTest();
170+
fs.rmSync(stateDir, { force: true, recursive: true });
171+
}
172+
});
84173
});

0 commit comments

Comments
 (0)