Skip to content

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

Hand-off threads: only a thread "new" opened closes on failure or stop; the standing work thread closes on done work, as before

milind-sonia503c4846449
diff --git a/server/host/finished-work.test.ts b/server/host/finished-work.test.ts
index 5ad1ecc294..eceafa50e1 100644
--- a/server/host/finished-work.test.ts
+++ b/server/host/finished-work.test.ts
@@ -224,9 +224,12 @@ describe("createHandedClose", () => {
}
});
- it("only closes the standing work thread when its work fails", () => {
+ it("leaves the standing work thread open when its work fails, and only closes it when work is done", () => {
const { record, start } = world({ openedBy: opened({ kind: "work" }) });
- start().ended(failed, chief, false);
+ const close = start();
+ close.ended(failed, chief, false);
+ expect(record.closedBy).toBeUndefined();
+ close.ended(work({}), chief, false);
expect(record.closedBy?.botId).toBe("chief");
expect(record.archivedAt).toBeUndefined();
});
@@ -389,13 +392,11 @@ describe("createHandedClose", () => {
expect(record.openedBy).toEqual(oneShot());
});
- it("keeps the standing work thread the person stopped open for an hour too, then only closes it", () => {
+ it("leaves the standing work thread the person stopped open", () => {
const { record, start } = world({ openedBy: opened({ kind: "work" }) });
start().ended(personStop, chief, false);
+ vi.advanceTimersByTime(2 * STOP_GRACE_MS);
expect(record.closedBy).toBeUndefined();
- vi.advanceTimersByTime(STOP_GRACE_MS);
- expect(record.closedBy).toEqual({ botId: "chief", name: "Clive", at: 1_000_000 + STOP_GRACE_MS });
- expect(record.archivedAt).toBeUndefined();
expect(record.openedBy).toEqual(opened({ kind: "work" }));
});
diff --git a/server/host/finished-work.ts b/server/host/finished-work.ts
index d84ed0818e..ba2da69ad2 100644
--- a/server/host/finished-work.ts
+++ b/server/host/finished-work.ts
@@ -1,6 +1,6 @@
-// Work one bot hands a teammate is finished once its result is reported back, whether it was done, failed or was stopped.
-// The standing work thread closes, which folds it out of the sidebar. A thread coordinate_bots opened with thread "new" for
-// that one hand-off (`openedBy.oneShot`) is due to close, and closes into the archive once no bot works there and nothing
+// Work one bot hands a teammate is finished once its result is reported back. When it was done, the standing work thread
+// closes, which folds it out of the sidebar. A thread coordinate_bots opened with thread "new" for that one hand-off
+// (`openedBy.oneShot`) is due to close whether the work was done, failed or was stopped, and closes into the archive once no bot works there and nothing
// there waits on the person. The person's Stop makes it due only an hour later, so a stop by mistake can be taken back by
// writing there: a thread the person wrote in, or one a post_to_thread reached, stays open for good. A new message takes the
// due close off, and brings a closed thread back. Every other thread stays as it is.
@@ -236,8 +236,9 @@ export function createHandedClose(deps: HandedCloseDeps): HandedClose {
const task = store.taskByThread(child.botId, child.threadId);
if (!task?.openedBy || !closesOnResult(task, parent.botId, child.botId)) return;
const stopped = stoppedByPerson(child, parent, deps.node);
- if (task.openedBy.kind === "work" && !stopped) {
- if (!deps.working(child.threadId)) finishHandedThread(store, child.botId, child.threadId, parent.botId, now());
+ // The standing work thread closes only on done work, as before: the opener's next work goes on in it.
+ if (task.openedBy.kind === "work") {
+ if (child.status === "completed" && !deps.working(child.threadId)) finishHandedThread(store, child.botId, child.threadId, parent.botId, now());
return;
}
store.setTaskOpenedBy(child.botId, child.threadId, { ...task.openedBy, closesAt: now() + (stopped ? STOP_GRACE_MS : 0) });