fix(sessions): retire stale direct dm rows after dmscope changes

Summary:
- Add explicit sessions cleanup --fix-dm-scope handling for stale direct-DM rows after session.dmScope returns to main.
- Preserve removed-row transcripts as deleted archives and expose the option through CLI, Gateway RPC, protocol schema, generated Swift mirrors, docs, tests, and changelog.
- Fixes #47561 and #45554.

Verification:
- pnpm exec oxfmt --check --threads=1 CHANGELOG.md docs/cli/sessions.md docs/concepts/session.md src/config/sessions/cleanup-service.ts src/commands/sessions-cleanup.ts src/cli/program/register.status-health-sessions.ts src/gateway/protocol/schema/sessions.ts src/gateway/server-methods/sessions.ts src/config/sessions/store.pruning.integration.test.ts src/commands/sessions-cleanup.test.ts src/cli/program/register.status-health-sessions.test.ts
- git diff --check origin/main...HEAD
- pnpm protocol:check
- pnpm exec oxlint src/config/sessions/cleanup-service.ts src/commands/sessions-cleanup.ts src/cli/program/register.status-health-sessions.ts src/gateway/protocol/schema/sessions.ts src/gateway/server-methods/sessions.ts src/config/sessions/store.pruning.integration.test.ts src/commands/sessions-cleanup.test.ts src/cli/program/register.status-health-sessions.test.ts
- pnpm test src/config/sessions/store.pruning.integration.test.ts src/commands/sessions-cleanup.test.ts src/cli/program/register.status-health-sessions.test.ts src/gateway/server.sessions.store-rpc.test.ts
- pnpm changed:lanes --json

Security:
- No new network, credential, process execution, dependency, or permission surface. Cleanup is explicit operator-invoked local session-store repair.

CI note:
- Exact-head CI failures match current main at 2e78fc57af in unrelated extensions/codex and extensions/microsoft-foundry type checks, outside this PR diff. No required checks are reported for this branch.
This commit is contained in:
Val Alexander
2026-05-07 02:16:46 -05:00
committed by GitHub
parent 2e78fc57af
commit d4e04f33a6
13 changed files with 283 additions and 12 deletions

View File

@@ -239,6 +239,7 @@ describe("registerStatusHealthSessionsCommands", () => {
"--dry-run",
"--enforce",
"--fix-missing",
"--fix-dm-scope",
"--active-key",
"agent:main:main",
"--json",
@@ -252,6 +253,7 @@ describe("registerStatusHealthSessionsCommands", () => {
dryRun: true,
enforce: true,
fixMissing: true,
fixDmScope: true,
activeKey: "agent:main:main",
json: true,
}),

View File

@@ -182,6 +182,11 @@ export function registerStatusHealthSessionsCommands(program: Command) {
"Remove store entries whose transcript files are missing (bypasses age/count retention)",
false,
)
.option(
"--fix-dm-scope",
"Retire stale direct-DM session rows that no longer match session.dmScope=main",
false,
)
.option("--active-key <key>", "Protect this session key from budget-eviction")
.option("--json", "Output JSON", false)
.addHelpText(
@@ -193,6 +198,10 @@ export function registerStatusHealthSessionsCommands(program: Command) {
"openclaw sessions cleanup --dry-run --fix-missing",
"Also preview pruning entries with missing transcript files.",
],
[
"openclaw sessions cleanup --dry-run --fix-dm-scope",
"Preview stale direct-DM rows after returning dmScope to main.",
],
["openclaw sessions cleanup --enforce", "Apply maintenance now."],
["openclaw sessions cleanup --agent work --dry-run", "Preview one agent store."],
["openclaw sessions cleanup --all-agents --dry-run", "Preview all agent stores."],
@@ -220,6 +229,7 @@ export function registerStatusHealthSessionsCommands(program: Command) {
dryRun: Boolean(opts.dryRun),
enforce: Boolean(opts.enforce),
fixMissing: Boolean(opts.fixMissing),
fixDmScope: Boolean(opts.fixDmScope),
activeKey: opts.activeKey as string | undefined,
json: Boolean(opts.json || parentOpts?.json),
},