Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Teammates: close_thread and list_threads say when a thread is archived

luishron12330a240e46616
diff --git a/server/direct-coordination.e2e.test.ts b/server/direct-coordination.e2e.test.ts
index 4206419e51..7abcf7575f 100644
--- a/server/direct-coordination.e2e.test.ts
+++ b/server/direct-coordination.e2e.test.ts
@@ -460,9 +460,10 @@ it("lets the opener list and close a thread \"new\" opened after it was archived
await f.cli("send", "--bot", f.chief.id, "--task", f.chief.activeTaskId, "--text", "Find the finished engineering thread and close it.");
expect((await f.wait()).status).toBe("settled");
const [listed, closed] = f.evidence().at(-1).evidence.filter((entry: any) => entry.step).map((entry: any) => entry.response.result);
- expect(listed.content[0].text).toContain(child.threadId);
+ const { title } = (await f.api("/api/bots")).bots.find((bot: any) => bot.id === f.lead.id).tasks.find((task: any) => task.threadId === child.threadId);
+ expect(listed.content[0].text).toContain(`- #${title} (on @Engineering lead, closed, archived: no longer in the person's sidebar) [thread id: ${child.threadId}]`);
expect(closed.isError).toBeFalsy();
- expect(closed.content[0].text).toContain("Closed #");
+ expect(closed.content[0].text).toBe(`#${title} on @Engineering lead was already closed by @Clive, so nothing changed. It is archived: it is no longer in the person's sidebar.`);
}), 60_000);
it("keeps a thread \"new\" opened open when a person wrote in it before its result came back", () => fixture(async f => {
diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.ts
index dfcbdf70b2..0906b3ec5b 100644
--- a/server/drivers/agents-call.ts
+++ b/server/drivers/agents-call.ts
@@ -432,7 +432,12 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
if (!threadId) return { text: "close_thread needs the thread_id from list_threads or start_thread.", isError: true };
const r = await api(`/api/internal/threads/${encodeURIComponent(threadId)}/close`, { method: "POST", body: JSON.stringify({ fromBotId: BOT_ID, fromThreadId: THREAD_ID }) });
if (r.error) return { text: `Couldn't close that thread: ${String(r.error)}`, isError: true };
- return { text: `Closed #${String(r.title)}${r.botName ? ` on @${String(r.botName)}` : ""}. It stays in the person's sidebar, idle, with a note that you closed it.` };
+ const thread = `#${String(r.title)}${r.botName ? ` on @${String(r.botName)}` : ""}`;
+ if (r.alreadyClosed === true) {
+ const by = typeof r.closedBy === "string" && r.closedBy ? ` by @${r.closedBy}` : "";
+ return { text: `${thread} was already closed${by}, so nothing changed. ${r.archived === true ? "It is archived: it is no longer in the person's sidebar." : "It stays in the person's sidebar, idle."}` };
+ }
+ return { text: `Closed ${thread}. ${r.archived === true ? "It was archived already, so it stays out of the person's sidebar, with a note that you closed it." : "It stays in the person's sidebar, idle, with a note that you closed it."}` };
}
if (name === "start_thread") {
const title = String(args.title ?? "").trim();
diff --git a/server/drivers/agents-list-threads-tool.ts b/server/drivers/agents-list-threads-tool.ts
index 4e21559016..e83954e0fc 100644
--- a/server/drivers/agents-list-threads-tool.ts
+++ b/server/drivers/agents-list-threads-tool.ts
@@ -10,10 +10,11 @@ const STATE_WORD: Record<string, string> = { running: "running", "waiting-on-you
function threadLine(thread: Json): string {
const where = thread.own === true ? "yours" : `on @${String(thread.botName)}${typeof thread.openedBy === "string" && thread.openedBy ? `, opened by @${thread.openedBy}` : ""}`;
const state = STATE_WORD[String(thread.state)] ?? String(thread.state);
+ const archived = thread.archived === true ? ", archived: no longer in the person's sidebar" : "";
const unread = thread.unread === true ? ", unread for the person" : "";
const handoff = typeof thread.delegationId === "string" && thread.delegationId ? ` [delegation id: ${thread.delegationId}]` : "";
const waiting = typeof thread.waiting === "string" && thread.waiting ? `: ${thread.waiting}` : "";
- return `- #${String(thread.title)} (${where}, ${state}${waiting}${unread}) [thread id: ${String(thread.threadId)}]${handoff}`;
+ return `- #${String(thread.title)} (${where}, ${state}${waiting}${archived}${unread}) [thread id: ${String(thread.threadId)}]${handoff}`;
}
export async function callListThreadsTool(args: Json, context: ToolCallContext): Promise<ToolCallResult> {
diff --git a/server/drivers/agents-proxy.test.ts b/server/drivers/agents-proxy.test.ts
index bb8040c94e..186c9f1612 100644
--- a/server/drivers/agents-proxy.test.ts
+++ b/server/drivers/agents-proxy.test.ts
@@ -49,6 +49,7 @@ let assignmentStatusCode = 200;
let lastThreadBody: any = null;
let threadCalls = 0;
let threadsList: unknown = { threads: [] };
+let closeReply: unknown = {};
let lastThreadsUrl = "";
let threadResponse: unknown = { threadId: "thread-new", title: "QA: PR #1", botId: "bot-asker", botName: "Asker", self: true, state: "running", limit: 3 };
let computerRequests: { method: string; url: string; body: unknown }[] = [];
@@ -275,6 +276,11 @@ beforeAll(async () => {
res.end(JSON.stringify(threadsList));
return;
}
+ if (req.method === "POST" && /^\/api\/internal\/threads\/[\w-]+\/close$/.test(req.url ?? "")) {
+ res.writeHead(200, { "content-type": "application/json" });
+ res.end(JSON.stringify(closeReply));
+ return;
+ }
if (req.method === "POST" && req.url === "/api/internal/threads") {
let data = "";
req.on("data", (c) => (data += c));
@@ -1345,6 +1351,29 @@ describe("agents-proxy MCP surface", () => {
}
});
+ it("close_thread and list_threads say whether a thread is archived, and a repeat close says it was already closed", async () => {
+ try {
+ closeReply = { closed: true, threadId: "t-1", title: "Export CSV", botName: "Ops", archived: false };
+ expect((await callTool("close_thread", { thread_id: "t-1" })).result.content[0].text)
+ .toBe("Closed #Export CSV on @Ops. It stays in the person's sidebar, idle, with a note that you closed it.");
+ closeReply = { closed: true, threadId: "t-1", title: "Export CSV", botName: "Ops", archived: true };
+ expect((await callTool("close_thread", { thread_id: "t-1" })).result.content[0].text)
+ .toBe("Closed #Export CSV on @Ops. It was archived already, so it stays out of the person's sidebar, with a note that you closed it.");
+ closeReply = { closed: true, alreadyClosed: true, threadId: "t-1", title: "Export CSV", botName: "Ops", closedBy: "Clive", archived: true };
+ expect((await callTool("close_thread", { thread_id: "t-1" })).result.content[0].text)
+ .toBe("#Export CSV on @Ops was already closed by @Clive, so nothing changed. It is archived: it is no longer in the person's sidebar.");
+ closeReply = { closed: true, alreadyClosed: true, threadId: "t-1", title: "Export CSV", botName: "Ops", closedBy: "Clive", archived: false };
+ expect((await callTool("close_thread", { thread_id: "t-1" })).result.content[0].text)
+ .toBe("#Export CSV on @Ops was already closed by @Clive, so nothing changed. It stays in the person's sidebar, idle.");
+ threadsList = { threads: [{ threadId: "t-1", botId: "bot-ops", botName: "Ops", title: "Export CSV", state: "closed", archived: true, own: false, unread: false, openedAt: 1 }] };
+ expect((await callTool("list_threads", {})).result.content[0].text)
+ .toBe("Threads, newest first:\n- #Export CSV (on @Ops, closed, archived: no longer in the person's sidebar) [thread id: t-1]");
+ } finally {
+ closeReply = {};
+ threadsList = { threads: [] };
+ }
+ });
+
it("list_threads names the next page when more threads are left, and asks for the page it is given", async () => {
const row = { threadId: "t-1", botId: "bot-a", botName: "A", title: "Event 1", state: "idle", own: true, unread: false, openedAt: 1 };
threadsList = { threads: [row], total: 101, page: 1, pageSize: 100 };
diff --git a/server/routes/internal-threads.ts b/server/routes/internal-threads.ts
index 1bce86e815..5057aee34a 100644
--- a/server/routes/internal-threads.ts
+++ b/server/routes/internal-threads.ts
@@ -16,6 +16,8 @@ interface ThreadRow {
/** Why a queued handoff hasn't started (host/queued-reason.ts). */
waiting?: string;
openedBy?: string;
+ /** The person's sidebar no longer shows it. */
+ archived?: true;
}
/** Only dispatch inside the internal capability gate: `from` and `fromThreadId` come from the caller's capability. */
@@ -63,6 +65,7 @@ export function createInternalThreadRoutes(deps: {
threadId: task.threadId, botId: from.id, botName: from.name, title: task.title,
state, unread: task.unread === true, openedAt: task.openedBy?.at ?? task.createdAt,
delegationId: task.openedBy?.delegationId, own: true, ...queued(from, task, state),
+ ...(task.archivedAt !== undefined ? { archived: true as const } : {}),
});
}
for (const peer of reachablePeers(store.bots, from)) {
@@ -76,7 +79,7 @@ export function createInternalThreadRoutes(deps: {
threadId: task.threadId, botId: peer.id, botName: peer.name, title: task.title,
state, unread: task.unread === true, openedAt: opener.at,
delegationId: opener.delegationId, own: false, ...queued(peer, task, state),
- ...(mine ? {} : { openedBy: opener.name }),
+ ...(mine ? {} : { openedBy: opener.name }), ...(task.archivedAt !== undefined ? { archived: true as const } : {}),
});
}
}
@@ -126,7 +129,7 @@ export function createInternalThreadRoutes(deps: {
return json(res, 409, { error: `#${task.title} is still running — wait for it to finish (list_threads), or the person can stop it from the app` });
}
if (task.closedBy) {
- return json(res, 200, { closed: true, alreadyClosed: true, threadId, title: task.title, botName: owner.name, closedBy: task.closedBy.name });
+ return json(res, 200, { closed: true, alreadyClosed: true, threadId, title: task.title, botName: owner.name, closedBy: task.closedBy.name, archived: task.archivedAt !== undefined });
}
store.appendMessage(threadId, {
role: "bot",
@@ -136,6 +139,6 @@ export function createInternalThreadRoutes(deps: {
});
if (task.unread) store.patchTask(owner.id, threadId, { unread: false });
store.setTaskClosedBy(owner.id, threadId, { botId: from.id, name: from.name, at: Date.now() });
- return json(res, 200, { closed: true, threadId, title: task.title, botName: owner.name });
+ return json(res, 200, { closed: true, threadId, title: task.title, botName: owner.name, archived: task.archivedAt !== undefined });
};
}