The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Accounts 2: a turned-off owner ends a chat or an episode with the reason
Claudef7abff4f9c13
diff --git a/src/server/assist/agent.ts b/src/server/assist/agent.tsindex 58eb84d3..1ece204d 100644--- a/src/server/assist/agent.ts+++ b/src/server/assist/agent.ts@@ -26,8 +26,8 @@ import {type SkillMeta,} from "@/lib/assist";import type { Engine, Generation, MediaKind } from "@/lib/catalog/types";-import { currentActor } from "../access/actor";-import { rowOwner, runAsOwner } from "../access/permissions";+import { currentActor, runAs, type Actor } from "../access/actor";+import { AccountOffError, ownerActor, rowOwner } from "../access/permissions";import { db } from "../db";import { getGeneration } from "../generations";import { offeredDefault } from "../model-access";@@ -1288,16 +1288,28 @@ const MODELS: Record<AssistThread["agent"], ModelCall> = { claude, ollama, offli/*** Run the agent until it ends its turn or waits for approval. Call it right after addMessage or* answerApproval: it claims the thread synchronously, so the "running" status they saved stays valid.- */-/**- * Carry the chat on until the agent stops (or asks for approval). The turn acts for the chat's author (§7.10), whoever's- * request or schedule carried it on: tools it runs, generations it starts and what it spends are theirs.+ * The turn acts for the chat's author (docs/research/accounts-8.md §7.11), whoever's request or schedule carried it+ * on: the tools it runs, the generations it starts and what they spend are theirs.*/export async function run(id: string, model?: ModelCall): Promise<void> {if (runs.has(id)) return;const row = db().prepare("SELECT * FROM assist_threads WHERE id = ?").get(id) as Row | undefined;if (!row) return;- return runAsOwner(rowOwner(row), () => turn(id, model));+ let owner: Actor;+ try {+ owner = ownerActor(rowOwner(row));+ } catch (e) {+ if (!(e instanceof AccountOffError)) throw e;+ // The chat's author was turned off: say so in the chat instead of leaving it "running".+ const s = load(id);+ if (s) {+ push(s, { role: "notice", tone: "error", text: e.message });+ s.thread.status = "idle";+ save(s);+ }+ return;+ }+ return runAs(owner, () => turn(id, model));}async function turn(id: string, model?: ModelCall): Promise<void> {diff --git a/src/server/faceless.ts b/src/server/faceless.tsindex 8906915d..cac29cf3 100644--- a/src/server/faceless.ts+++ b/src/server/faceless.ts@@ -79,7 +79,7 @@ import type { Engine, Generation, GenerationRequest } from "@/lib/catalog/types"import { DocxError, docxText } from "./assist/docx";import { PdfError, pdfText } from "./assist/pdf";import { asSystem } from "./access/actor";-import { rowOwner, runAsOwner } from "./access/permissions";+import { AccountOffError, rowOwner, runAsOwner } from "./access/permissions";import { db } from "./db";import { listElements } from "./elements";import { cancelGeneration, chooseRoute, createGenerations, getGeneration, previewChained } from "./generations";@@ -1159,7 +1159,8 @@ function sweep(): void {// Stage two starts as the person who started the episode.runAsOwner(rowOwner(r), () => settle(toEpisode(r)));} catch (e) {- console.warn(`[faceless] couldn't continue ${r.id}: ${(e as Error).message}`);+ if (e instanceof AccountOffError) updateEpisodeRow(r.id, { status: "failed", error: e.message });+ else console.warn(`[faceless] couldn't continue ${r.id}: ${(e as Error).message}`);}}}diff --git a/src/server/swap-studio.ts b/src/server/swap-studio.tsindex 3070677b..3c4f4d94 100644--- a/src/server/swap-studio.ts+++ b/src/server/swap-studio.ts@@ -47,7 +47,7 @@ import type { Engine, Generation, PixelPoint } from "@/lib/catalog/types";import { ACCESS_PLACE } from "@/lib/model-access";import { createPipeline } from "./chains";import { asSystem } from "./access/actor";-import { rowOwner, runAsOwner } from "./access/permissions";+import { AccountOffError, rowOwner, runAsOwner } from "./access/permissions";import { db } from "./db";import { cancelGeneration, getGeneration, previewChained } from "./generations";import { isOffered, offeredLoras } from "./model-access";@@ -350,6 +350,8 @@ export function ensureSwapStudioRunner(): void {// Waiting takes launch as the person who started the project.runAsOwner(rowOwner(r), () => advanceProject(r.id));} catch (e) {+ // Its owner was turned off: the takes wait (their steps fail with the reason) until they're back.+ if (e instanceof AccountOffError) continue;console.error(`[swap-studio] ${r.id}:`, (e as Error).message);}}diff --git a/tests/runners-actor.test.ts b/tests/runners-actor.test.tsindex fd29edcd..e330141d 100644--- a/tests/runners-actor.test.ts+++ b/tests/runners-actor.test.ts@@ -134,6 +134,18 @@ describe("Assist", () => {expect(seen[0]).toEqual({ userId: "u_owner", via: "runner" });});+ it("ends a chat whose author was turned off with the plan's words, and leaves it idle", async () => {+ const t = agent.createThread({ engine: "cloud", agent: "claude", title: "Off" });+ agent.addMessage(t.id, "Make an ad");+ updatePerson("u_owner", { status: "disabled" });+ const seen: unknown[] = [];+ await agent.run(t.id, done(seen));+ expect(seen).toEqual([]);+ const { thread } = agent.getThread(t.id)!;+ expect(thread.status).toBe("idle");+ expect(thread.items.at(-1)).toMatchObject({ role: "notice", tone: "error", text: "Paused: the account that started this is off." });+ });+it("runs a scheduled task as the person who owns it, from the server's sweep", async () => {const T = (s: string) => Date.parse(s);const s = sched.createSchedule(