Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(screen-caster): stop reporting a clean shutdown as a task error
nirholasb8ba9cdbfef9
diff --git a/services/agent-screen-caster/caster.js b/services/agent-screen-caster/caster.jsindex b5a0db572..bf7865116 100644--- a/services/agent-screen-caster/caster.js+++ b/services/agent-screen-caster/caster.js@@ -94,6 +94,15 @@ export class AgentScreenCaster {this.browser = this.context = this.page = null;}+ /**+ * True once close() has begun. A task whose page call rejects during+ * teardown is expected shutdown, not a failure worth narrating: callers+ * check this before pushing an error activity to the agent's public log.+ */+ get isClosing() {+ return this._closing;+ }+// ── Navigation & actions ───────────────────────────────────────────────────/**diff --git a/services/agent-screen-caster/index.js b/services/agent-screen-caster/index.jsindex cd89299a9..c5e1352e8 100644--- a/services/agent-screen-caster/index.js+++ b/services/agent-screen-caster/index.js@@ -64,6 +64,13 @@ if (!taskPath) fatal(`Unknown task "${task}". Valid tasks: ${Object.keys(TASK_MA// ── Boot ───────────────────────────────────────────────────────────────────────const caster = new AgentScreenCaster({ agentId, bearerToken, pushUrl, frameIntervalMs: frameMs, jpegQuality });+// Register BEFORE the task runs. Registering after the top-level `await run(...)`+// means no handler exists while a task is in flight, so Playwright's own SIGINT+// hook closes the browser first and the task's rejection reads as a real error+// (isClosing still false) instead of a clean shutdown.+process.on('SIGTERM', async () => { await caster.close(); process.exit(0); });+process.on('SIGINT', async () => { await caster.close(); process.exit(0); });+console.log('[agent-screen-caster] starting');console.log(' agentId :', agentId);console.log(' pushUrl :', pushUrl);@@ -89,12 +96,20 @@ caster.startFrameLoop();try {await run(caster, taskArg);} catch (err) {- console.error('[agent-screen-caster] task error:', err?.message || err);- await caster.pushActivity([{- type: 'error',- summary: `Task error: ${err?.message || String(err)}`,- ts: Date.now(),- }]);+ if (caster.isClosing) {+ // SIGINT/SIGTERM closed the browser under the task; the resulting page+ // rejection is clean shutdown, not an error the agent's watchers should see.+ console.log('[agent-screen-caster] task interrupted by shutdown');+ } else {+ console.error('[agent-screen-caster] task error:', err?.message || err);+ await caster.pushActivity([{+ type: 'error',+ summary: `Task error: ${err?.message || String(err)}`,+ ts: Date.now(),+ }]).catch((pushErr) => {+ console.error('[agent-screen-caster] could not report task error:', pushErr?.message || pushErr);+ });+ }} finally {await caster.close();console.log('[agent-screen-caster] shut down');@@ -131,6 +146,3 @@ function loadEnvFile(path) {if (key && !(key in process.env)) process.env[key] = val;}}--process.on('SIGTERM', async () => { await caster.close(); process.exit(0); });-process.on('SIGINT', async () => { await caster.close(); process.exit(0); });diff --git a/tests/agent-screen-caster.test.js b/tests/agent-screen-caster.test.jsindex 9da23c1ef..d9a6588bc 100644--- a/tests/agent-screen-caster.test.js+++ b/tests/agent-screen-caster.test.js@@ -91,6 +91,11 @@ describe('AgentScreenCaster constructor', () => {expect(() => new AgentScreenCaster({ bearerToken: BEARER })).toThrow(/agentId/);expect(() => new AgentScreenCaster({ agentId: AGENT_ID })).toThrow(/bearerToken/);});++ it('starts out not closing, so a task rejection counts as a real error', () => {+ const caster = new AgentScreenCaster({ agentId: AGENT_ID, bearerToken: BEARER });+ expect(caster.isClosing).toBe(false);+ });});describe('isRetryableStatus', () => {@@ -220,5 +225,8 @@ describe('live browser core path', () => {}expect(errors.filter((e) => e.includes('frame push failed'))).toHaveLength(0);expect(caster.page).toBeNull();+ // The entrypoint reads this to tell clean shutdown from a real task error,+ // so a SIGINT never pushes a spurious error into the agent's activity log.+ expect(caster.isClosing).toBe(true);});});