Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Runtime: guard the progress write, pace the root's stamp too
Seyamalama50948c78cf0
diff --git a/server/runtime/runtime.test.ts b/server/runtime/runtime.test.tsindex 15b6dc2d2b..508aac1f50 100644--- a/server/runtime/runtime.test.ts+++ b/server/runtime/runtime.test.ts@@ -371,6 +371,30 @@ describe("Runtime: one tree, one lane", () => {invariants(w);});+ it("writes the root's activity stamp at most once per cadence, however many children report", () => {+ const w = world(() => "hold");+ const root = w.runtime.begin(beginReq());+ const a = ok(w.runtime.enqueue(toBot("a", root.id)));+ w.runtime.tick();+ const b = ok(w.runtime.enqueue(toBot("b", root.id)));+ w.runtime.tick();+ // Both dispatched at T. a reports at T+10s: the node and the root are stamped.+ w.clock.advance(PROGRESS_WRITE_MS);+ w.runtime.progress(a.id);+ const rootStamp = w.store.get(root.id)!.lastActivityAt;+ expect(rootStamp).toBe(w.clock.t);+ // b reports at T+11s: its own row is still due, but the root is not — it stays at T+10s.+ w.clock.advance(1_000);+ w.runtime.progress(b.id);+ expect(w.store.get(b.id)!.lastActivityAt).toBe(w.clock.t);+ expect(w.store.get(root.id)!.lastActivityAt).toBe(rootStamp);+ // Once the root's window has passed, the next report moves it again.+ w.clock.advance(PROGRESS_WRITE_MS);+ w.runtime.progress(b.id);+ expect(w.store.get(root.id)!.lastActivityAt).toBe(w.clock.t);+ invariants(w);+ });+it("reconciles a restart from stored data: rerun once, cut after handing out work, re-park, fail a rerun cut again", async () => {const store = openRuntimeStore(":memory:");const first = world(() => "hold", {}, store);diff --git a/server/runtime/runtime.ts b/server/runtime/runtime.tsindex 276cfb16a7..61ad3b10a7 100644--- a/server/runtime/runtime.ts+++ b/server/runtime/runtime.ts@@ -549,14 +549,19 @@ export class Runtime {}if (!n || n.status !== "running" || now - n.lastActivityAt < PROGRESS_WRITE_MS) return;n.lastActivityAt = now;- const root = n.rootId === n.id ? undefined : this.store.get(n.rootId);- this.store.transaction(() => {- this.store.update(n);- if (root && !isTerminal(root)) {- root.lastActivityAt = now;- this.store.update(root);- }- });+ try {+ const root = n.rootId === n.id ? undefined : this.store.get(n.rootId);+ this.store.transaction(() => {+ this.store.update(n);+ if (root && !isTerminal(root) && now - root.lastActivityAt >= PROGRESS_WRITE_MS) {+ root.lastActivityAt = now;+ this.store.update(root);+ }+ });+ } catch (error) {+ // Bookkeeping only: a failed stamp never ends the turn or the caller that reported progress.+ this.log(`progress(${id}) write failed: ${String(error)}`);+ }}/** A parked question is answered, by the person unless `by` says otherwise; the next turn carries it. */