fix(scripts): purge reviewer/arbiter session leftovers on deregister
Deregistration only removed the base group folder, leaving the tribunal reviewer/arbiter runtime behind: DB session rows keyed as "<folder>:reviewer" /":arbiter" and on-disk dirs data/sessions/<folder>-reviewer/-arbiter (plus ipc/workspaces variants). Include those role-suffixed variants in both the sessions DELETE and the disk cleanup so a deregistered room leaves nothing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -163,7 +163,6 @@ const scheduledTaskIds = (
|
|||||||
).map((r) => r.id);
|
).map((r) => r.id);
|
||||||
const qS = scheduledTaskIds.map(() => '?').join(',');
|
const qS = scheduledTaskIds.map(() => '?').join(',');
|
||||||
const safeFolderList = [...safeFolders];
|
const safeFolderList = [...safeFolders];
|
||||||
const qF = safeFolderList.map(() => '?').join(',');
|
|
||||||
|
|
||||||
const count = (t: string, where: string, a: unknown[]): number =>
|
const count = (t: string, where: string, a: unknown[]): number =>
|
||||||
(
|
(
|
||||||
@@ -221,15 +220,22 @@ for (const t of [
|
|||||||
addJid(t);
|
addJid(t);
|
||||||
}
|
}
|
||||||
// sessions are keyed by group folder — only purge folders not shared with a
|
// sessions are keyed by group folder — only purge folders not shared with a
|
||||||
// surviving room.
|
// surviving room. Reviewer/arbiter sessions are stored under the colon-suffixed
|
||||||
if (safeFolderList.length) {
|
// group_folder (e.g. "<folder>:reviewer"), so include those variants too.
|
||||||
|
const sessionFolderKeys = safeFolderList.flatMap((f) => [
|
||||||
|
f,
|
||||||
|
`${f}:reviewer`,
|
||||||
|
`${f}:arbiter`,
|
||||||
|
]);
|
||||||
|
if (sessionFolderKeys.length) {
|
||||||
|
const qSess = sessionFolderKeys.map(() => '?').join(',');
|
||||||
plan.push({
|
plan.push({
|
||||||
table: 'sessions',
|
table: 'sessions',
|
||||||
n: count('sessions', `group_folder IN (${qF})`, safeFolderList),
|
n: count('sessions', `group_folder IN (${qSess})`, sessionFolderKeys),
|
||||||
run: () =>
|
run: () =>
|
||||||
db
|
db
|
||||||
.query(`DELETE FROM sessions WHERE group_folder IN (${qF})`)
|
.query(`DELETE FROM sessions WHERE group_folder IN (${qSess})`)
|
||||||
.run(...safeFolderList),
|
.run(...sessionFolderKeys),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,11 +256,17 @@ if (routerPrune) console.log(` router_state.last_agent_seq: ${routerPrune}`);
|
|||||||
// disk targets
|
// disk targets
|
||||||
const diskDirs: string[] = [];
|
const diskDirs: string[] = [];
|
||||||
for (const folder of safeFolders) {
|
for (const folder of safeFolders) {
|
||||||
|
// Tribunal rooms keep separate reviewer/arbiter runtime dirs suffixed with
|
||||||
|
// the role (e.g. data/sessions/<folder>-reviewer). Include those variants so
|
||||||
|
// deregistration leaves no leftovers.
|
||||||
|
const folderVariants = [folder, `${folder}-reviewer`, `${folder}-arbiter`];
|
||||||
for (const d of [
|
for (const d of [
|
||||||
path.join(GROUPS_DIR, folder),
|
path.join(GROUPS_DIR, folder),
|
||||||
path.join(DATA_DIR, 'workspaces', folder),
|
...folderVariants.flatMap((f) => [
|
||||||
path.join(DATA_DIR, 'sessions', folder),
|
path.join(DATA_DIR, 'workspaces', f),
|
||||||
path.join(DATA_DIR, 'ipc', folder),
|
path.join(DATA_DIR, 'sessions', f),
|
||||||
|
path.join(DATA_DIR, 'ipc', f),
|
||||||
|
]),
|
||||||
]) {
|
]) {
|
||||||
if (fs.existsSync(d)) diskDirs.push(d);
|
if (fs.existsSync(d)) diskDirs.push(d);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user