From 91239a68393f3656f6b50ea5467cc5b101ca658a Mon Sep 17 00:00:00 2001 From: onweekend Date: Sun, 25 Oct 2026 03:04:58 -0700 Subject: [PATCH 1/2] fix(mastra): keep idle streams open for background approvals --- patches/@mastra__core.patch | 28 ++- pnpm-lock.yaml | 82 ++++----- .../chat/foreground-suspend-idle.test.ts | 168 ++++++++++-------- 3 files changed, 164 insertions(+), 114 deletions(-) diff --git a/patches/@mastra__core.patch b/patches/@mastra__core.patch index f358c0d..28c4fa9 100644 --- a/patches/@mastra__core.patch +++ b/patches/@mastra__core.patch @@ -1,5 +1,5 @@ diff --git a/dist/agent-BMi0F5ou.cjs b/dist/agent-BMi0F5ou.cjs -index fadfaa7621f4f5bcdd6bed34f974b8d1bdf7e246..b523e9d523c97497adee0d1e35d4ad83a7b06a73 100644 +index fadfaa7621f4f5bcdd6bed34f974b8d1bdf7e246..7ba76e0ed3bd967f28af3973d3f7813f199b7cca 100644 --- a/dist/agent-BMi0F5ou.cjs +++ b/dist/agent-BMi0F5ou.cjs @@ -31393,10 +31393,15 @@ var SaveQueueManager = class SaveQueueManager { @@ -111,8 +111,20 @@ index fadfaa7621f4f5bcdd6bed34f974b8d1bdf7e246..b523e9d523c97497adee0d1e35d4ad83 const terminalKey = taskId && TERMINAL_BG_CHUNKS.has(chunk.type) ? `${taskId}:${chunk.type}` : void 0; if (terminalKey && processedTerminalKeys.has(terminalKey)) continue; updateIdleTimer(); +@@ -31753,7 +31809,10 @@ async function runIdleLoop(agent, streamOptions, deps, firstTurn, streamForConti + if (!taskId) continue; + if (chunk.type === "background-task-running" || chunk.type === "background-task-resumed") runningTaskIds.add(taskId); + else if (TERMINAL_BG_CHUNKS.has(chunk.type)) { +- runningTaskIds.delete(taskId); ++ // A suspended background task still awaits resume and a final result. ++ // Keep its subscription alive regardless of when the foreground finishes. ++ if (chunk.type === "background-task-suspended") runningTaskIds.add(taskId); ++ else runningTaskIds.delete(taskId); + pendingCompletions.push(chunk); + processIfIdle(); + } diff --git a/dist/agent-CEHR0Wd8.js b/dist/agent-CEHR0Wd8.js -index 3a27f1c85b2639362979195cb0ca6fd81f5ce227..69126aa9c04946774241c0060671709d8075b35f 100644 +index 3a27f1c85b2639362979195cb0ca6fd81f5ce227..a2aed40cc9a74b3d61525c8067e0f934a8a45d95 100644 --- a/dist/agent-CEHR0Wd8.js +++ b/dist/agent-CEHR0Wd8.js @@ -31391,10 +31391,15 @@ var SaveQueueManager = class SaveQueueManager { @@ -224,3 +236,15 @@ index 3a27f1c85b2639362979195cb0ca6fd81f5ce227..69126aa9c04946774241c0060671709d const terminalKey = taskId && TERMINAL_BG_CHUNKS.has(chunk.type) ? `${taskId}:${chunk.type}` : void 0; if (terminalKey && processedTerminalKeys.has(terminalKey)) continue; updateIdleTimer(); +@@ -31751,7 +31807,10 @@ async function runIdleLoop(agent, streamOptions, deps, firstTurn, streamForConti + if (!taskId) continue; + if (chunk.type === "background-task-running" || chunk.type === "background-task-resumed") runningTaskIds.add(taskId); + else if (TERMINAL_BG_CHUNKS.has(chunk.type)) { +- runningTaskIds.delete(taskId); ++ // A suspended background task still awaits resume and a final result. ++ // Keep its subscription alive regardless of when the foreground finishes. ++ if (chunk.type === "background-task-suspended") runningTaskIds.add(taskId); ++ else runningTaskIds.delete(taskId); + pendingCompletions.push(chunk); + processIfIdle(); + } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 77e7b06..73de432 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,7 +6,7 @@ settings: patchedDependencies: '@mastra/core': - hash: f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8 + hash: 430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f path: patches/@mastra__core.patch importers: @@ -311,7 +311,7 @@ importers: devDependencies: '@mastra/core': specifier: 1.66.0 - version: 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3) + version: 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3) '@rollup/plugin-node-resolve': specifier: ^16.0.3 version: 16.0.3(rollup@2.79.2) @@ -1067,31 +1067,31 @@ importers: version: 0.1.3 '@mastra/ai-sdk': specifier: 1.10.2 - version: 1.10.2(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) + version: 1.10.2(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) '@mastra/core': specifier: 1.66.0 - version: 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + version: 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) '@mastra/evals': specifier: 1.10.1 - version: 1.10.1(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(vitest@4.0.16) + version: 1.10.1(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(vitest@4.0.16) '@mastra/hono': specifier: 1.7.8 - version: 1.7.8(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(hono@4.13.7)(zod@4.4.3) + version: 1.7.8(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(hono@4.13.7)(zod@4.4.3) '@mastra/loggers': specifier: 1.3.1 - version: 1.3.1(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) + version: 1.3.1(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) '@mastra/mcp': specifier: 1.17.3 - version: 1.17.3(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(express@4.21.2)(hono@4.13.7)(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.4.3) + version: 1.17.3(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(express@4.21.2)(hono@4.13.7)(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.4.3) '@mastra/memory': specifier: 1.29.0 - version: 1.29.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) + version: 1.29.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) '@mastra/observability': specifier: 1.17.7 - version: 1.17.7(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) + version: 1.17.7(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) '@mastra/pg': specifier: 1.25.0 - version: 1.25.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) + version: 1.25.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) '@prisma/adapter-pg': specifier: 7.2.0 version: 7.2.0 @@ -1233,7 +1233,7 @@ importers: version: 12.1.1(eslint@9.35.0(jiti@2.7.0)) mastra: specifier: 1.29.0 - version: 1.29.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(rxjs@7.8.2)(typescript@5.9.3)(zod@4.4.3) + version: 1.29.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(rxjs@7.8.2)(typescript@5.9.3)(zod@4.4.3) prettier: specifier: ^3.6.2 version: 3.6.2 @@ -14612,16 +14612,16 @@ snapshots: '@mariozechner/clipboard-win32-x64-msvc': 0.3.9 optional: true - '@mastra/ai-sdk@1.10.2(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3)': + '@mastra/ai-sdk@1.10.2(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3)': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) zod: 4.4.3 '@mastra/client-js@1.45.0(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3)': dependencies: '@ai-sdk/ui-utils': 1.2.11(zod@4.4.3) '@lukeed/uuid': 2.0.1 - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3) '@mastra/schema-compat': 1.3.9(zod@4.4.3) canonicalize: 1.0.8 jose: 6.2.3 @@ -14638,7 +14638,7 @@ snapshots: - utf-8-validate - workflow - '@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)': + '@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)': dependencies: '@a2a-js/sdk-v0_3': '@a2a-js/sdk@0.3.14(express@4.21.2)' '@a2a-js/sdk-v1': '@a2a-js/sdk@1.0.1(express@4.21.2)' @@ -14683,7 +14683,7 @@ snapshots: - utf-8-validate - workflow - '@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3)': + '@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@5.2.1)(rxjs@7.8.2)(zod@4.4.3)': dependencies: '@a2a-js/sdk-v0_3': '@a2a-js/sdk@0.3.14(express@5.2.1)' '@a2a-js/sdk-v1': '@a2a-js/sdk@1.0.1(express@5.2.1)' @@ -14728,14 +14728,14 @@ snapshots: - utf-8-validate - workflow - '@mastra/deployer@1.66.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(typescript@5.9.3)(zod@4.4.3)': + '@mastra/deployer@1.66.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(typescript@5.9.3)(zod@4.4.3)': dependencies: '@babel/core': 8.0.1 '@babel/preset-typescript': 8.0.1(@babel/core@8.0.1) '@babel/traverse': 8.0.4 '@hono/node-ws': 1.3.0(@hono/node-server@2.0.1(hono@4.13.7))(hono@4.13.7) - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) - '@mastra/server': 1.66.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/server': 1.66.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) '@optimize-lodash/rollup-plugin': 5.1.0(rollup@4.62.4) '@rollup/plugin-commonjs': 29.0.2(rollup@4.62.4) '@rollup/plugin-esm-shim': 0.1.8(rollup@4.62.4) @@ -14766,9 +14766,9 @@ snapshots: - utf-8-validate - zod - '@mastra/evals@1.10.1(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(vitest@4.0.16)': + '@mastra/evals@1.10.1(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(vitest@4.0.16)': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) compromise: 14.15.0 keyword-extractor: 0.0.28 sentiment: 5.0.2 @@ -14776,11 +14776,11 @@ snapshots: optionalDependencies: vitest: 4.0.16(@opentelemetry/api@1.9.0)(@types/node@24.10.2)(@vitest/ui@4.0.16)(jiti@2.7.0)(jsdom@26.1.0(canvas@3.2.0))(lightningcss@1.32.0)(sass@1.93.2)(terser@5.18.1)(tsx@4.21.0)(yaml@2.9.0) - '@mastra/hono@1.7.8(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(hono@4.13.7)(zod@4.4.3)': + '@mastra/hono@1.7.8(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(hono@4.13.7)(zod@4.4.3)': dependencies: '@hono/node-ws': 1.3.0(@hono/node-server@2.0.1(hono@4.13.7))(hono@4.13.7) - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) - '@mastra/server': 1.66.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/server': 1.66.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3) fetch-to-node: 2.1.0 hono: 4.13.7 ws: 8.21.3 @@ -14790,15 +14790,15 @@ snapshots: - utf-8-validate - zod - '@mastra/loggers@1.3.1(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))': + '@mastra/loggers@1.3.1(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) pino: 10.3.1 pino-pretty: 13.1.3 - '@mastra/mcp@1.17.3(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(express@4.21.2)(hono@4.13.7)(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.4.3)': + '@mastra/mcp@1.17.3(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(express@4.21.2)(hono@4.13.7)(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.4.3)': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) '@modelcontextprotocol/client': 2.0.0 '@modelcontextprotocol/core': 2.0.0 '@modelcontextprotocol/ext-apps': 1.7.3(@modelcontextprotocol/sdk@1.29.0(zod@4.4.3))(react-dom@19.2.7(react@19.2.7))(react@19.2.7)(zod@4.4.3) @@ -14817,9 +14817,9 @@ snapshots: - supports-color - zod - '@mastra/memory@1.29.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))': + '@mastra/memory@1.29.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) '@mastra/schema-compat': 1.3.9(zod@4.4.3) async-mutex: 0.5.0 diff: 8.0.4 @@ -14832,14 +14832,14 @@ snapshots: transitivePeerDependencies: - supports-color - '@mastra/observability@1.17.7(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3)': + '@mastra/observability@1.17.7(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3)': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) zod: 4.4.3 - '@mastra/pg@1.25.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))': + '@mastra/pg@1.25.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) async-mutex: 0.5.0 pg: 8.23.0 pg-connection-string: 2.14.0 @@ -14853,9 +14853,9 @@ snapshots: zod: 4.4.3 zod-from-json-schema: 0.5.2 - '@mastra/server@1.66.0(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3)': + '@mastra/server@1.66.0(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(zod@4.4.3)': dependencies: - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) hono: 4.13.7 zod: 4.4.3 @@ -20520,15 +20520,15 @@ snapshots: marked@18.0.5: {} - mastra@1.29.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(rxjs@7.8.2)(typescript@5.9.3)(zod@4.4.3): + mastra@1.29.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(rxjs@7.8.2)(typescript@5.9.3)(zod@4.4.3): dependencies: '@babel/parser': 8.0.4 '@babel/types': 8.0.4 '@clack/prompts': 1.7.0 '@expo/devcert': 1.2.1 - '@mastra/core': 1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) - '@mastra/deployer': 1.66.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(typescript@5.9.3)(zod@4.4.3) - '@mastra/loggers': 1.3.1(@mastra/core@1.66.0(patch_hash=f21cb84ff4233ffe18eb6fc4d2ad9b1f04059ebd301542dd95cdce6d0286f3c8)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) + '@mastra/core': 1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3) + '@mastra/deployer': 1.66.0(@hono/node-server@2.0.1(hono@4.13.7))(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3))(typescript@5.9.3)(zod@4.4.3) + '@mastra/loggers': 1.3.1(@mastra/core@1.66.0(patch_hash=430176af18f3a75e4d59caec8c938bb4ec338ff10a131d0ef503c8cbd006c61f)(ai@6.0.282(zod@4.4.3))(express@4.21.2)(rxjs@7.8.2)(zod@4.4.3)) archiver: 8.0.0 commander: 14.0.3 dotenv: 17.3.1 diff --git a/servers/server/tests/mastra/chat/foreground-suspend-idle.test.ts b/servers/server/tests/mastra/chat/foreground-suspend-idle.test.ts index 94cf144..1b04138 100644 --- a/servers/server/tests/mastra/chat/foreground-suspend-idle.test.ts +++ b/servers/server/tests/mastra/chat/foreground-suspend-idle.test.ts @@ -30,82 +30,108 @@ const modelReply = (tool?: string) => ({ }); describe("Mastra untilIdle 的前台挂起边界", () => { - it("后台工具自身的审批继续走后台恢复,不被当成前台挂起关闭", async () => { - let first = true; - const agent = new Agent({ - id: "background-approval-test", - name: "background-approval-test", - instructions: "x", - model: new MockLanguageModelV3({ - doStream: async () => { - const tool = first ? "collect" : undefined; - first = false; - return modelReply(tool); - } - }) as never, - memory: new Memory({ options: { lastMessages: 20 } }), - tools: { - collect: createTool({ - id: "collect", - description: "collect", - inputSchema: z.object({}), - background: { enabled: true }, - suspendSchema: z.object({ type: z.literal("approval") }), - resumeSchema: z.object({ approved: z.boolean() }), - execute: async (_, context) => { - if (context?.agent?.resumeData) { - return { url: "http://example.com/asset.jpg" }; + it.each(["before", "after"] as const)( + "后台审批在前台结束 %s 到达时,保持流直到后台恢复完成", + async (order) => { + let releaseBackground!: () => void; + let releaseForeground!: () => void; + const background = new Promise((resolve) => { + releaseBackground = resolve; + }); + const foreground = new Promise((resolve) => { + releaseForeground = resolve; + }); + let first = true; + const agent = new Agent({ + id: "background-approval-test", + name: "background-approval-test", + instructions: "x", + model: new MockLanguageModelV3({ + doStream: async () => { + const tool = first ? "collect" : undefined; + first = false; + if (!tool && order === "before") { + await foreground; } - return context?.agent?.suspend?.({ type: "approval" }) as never; + return modelReply(tool); } - }) - } - }); - const storage = new InMemoryStore(); - const mastra = new Mastra({ agents: { agent }, storage, backgroundTasks: { enabled: true } }); - const abort = new AbortController(); - const chunks: Array<{ type: string; payload?: { taskId?: string } }> = []; - let drain: Promise | undefined; - try { - const initial = await agent.stream("收集素材", { - memory: { thread: "bg-approval", resource: "r" }, - untilIdle: true, - abortSignal: abort.signal - }); - drain = (async () => { - for await (const chunk of initial.fullStream) { - chunks.push(chunk as never); + }) as never, + memory: new Memory({ options: { lastMessages: 20 } }), + tools: { + collect: createTool({ + id: "collect", + description: "collect", + inputSchema: z.object({}), + background: { enabled: true }, + suspendSchema: z.object({ type: z.literal("approval") }), + resumeSchema: z.object({ approved: z.boolean() }), + execute: async (_, context) => { + if (context?.agent?.resumeData) { + return { url: "http://example.com/asset.jpg" }; + } + if (order === "after") { + await background; + } + return context?.agent?.suspend?.({ type: "approval" }) as never; + } + }) } - })(); - await vi.waitFor(() => expect(chunks.some((chunk) => chunk.type === "background-task-suspended")).toBe(true), { - timeout: 3000 }); - const taskId = chunks.find((chunk) => chunk.type === "background-task-suspended")!.payload!.taskId!; - const workflows = await storage.getStore("workflows"); - await vi.waitFor(async () => + const storage = new InMemoryStore(); + const mastra = new Mastra({ agents: { agent }, storage, backgroundTasks: { enabled: true } }); + const abort = new AbortController(); + const chunks: Array<{ type: string; payload?: { taskId?: string } }> = []; + let drain: Promise | undefined; + try { + const initial = await agent.stream("收集素材", { + memory: { thread: "bg-approval", resource: "r" }, + untilIdle: true, + abortSignal: abort.signal + }); + drain = (async () => { + for await (const chunk of initial.fullStream) { + chunks.push(chunk as never); + } + })(); + if (order === "after") { + await vi.waitFor(() => expect(chunks.some((chunk) => chunk.type === "finish")).toBe(true), { timeout: 3000 }); + releaseBackground(); + } + await vi.waitFor(() => expect(chunks.some((chunk) => chunk.type === "background-task-suspended")).toBe(true), { + timeout: 3000 + }); + releaseForeground(); + await vi.waitFor(() => expect(chunks.some((chunk) => chunk.type === "finish")).toBe(true), { timeout: 3000 }); + const taskId = chunks.find((chunk) => chunk.type === "background-task-suspended")!.payload!.taskId!; + const workflows = await storage.getStore("workflows"); + await vi.waitFor(async () => + expect( + ( + (await workflows!.loadWorkflowSnapshot({ workflowName: "__background-task", runId: taskId })) as { + status?: string; + } + )?.status + ).toBe("suspended") + ); expect( - ( - (await workflows!.loadWorkflowSnapshot({ workflowName: "__background-task", runId: taskId })) as { - status?: string; - } - )?.status - ).toBe("suspended") - ); - expect( - await Promise.race([ - drain.then(() => "closed"), - new Promise((resolve) => setTimeout(() => resolve("waiting"), 50)) - ]) - ).toBe("waiting"); - await mastra.backgroundTaskManager!.resume(taskId, { approved: true }); - await drain; - expect(chunks.some((chunk) => chunk.type === "background-task-completed")).toBe(true); - } finally { - abort.abort(); - await drain?.catch(() => {}); - await mastra.shutdown(); - } - }, 15000); + await Promise.race([ + drain.then(() => "closed"), + new Promise((resolve) => setTimeout(() => resolve("waiting"), 50)) + ]) + ).toBe("waiting"); + await mastra.backgroundTaskManager!.resume(taskId, { approved: true }); + await drain; + expect(chunks.some((chunk) => chunk.type === "background-task-completed")).toBe(true); + } finally { + releaseBackground(); + releaseForeground(); + abort.abort(); + await drain?.catch(() => {}); + await mastra.shutdown(); + } + }, + 15000 + ); it.each([1, 2])( "后台任务未完成时释放审批恢复队列,%s 个后台结果回填后仍保留编辑回执", From 60345d8af5261e4ffd83c52d9399c14610b5f7e7 Mon Sep 17 00:00:00 2001 From: onweekend Date: Sun, 25 Oct 2026 03:22:18 -0700 Subject: [PATCH 2/2] ci: deploy main automatically after publishing images --- .github/workflows/release.yml | 4 +++- docker/README.md | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a16df6e..9963226 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,7 +60,9 @@ jobs: cache-to: type=gha,mode=max,scope=funbi-${{ matrix.target }} deploy: - if: github.event_name == 'workflow_dispatch' && inputs.deploy && github.ref == 'refs/heads/main' + if: >- + github.ref == 'refs/heads/main' && + (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.deploy)) needs: publish runs-on: ubuntu-latest timeout-minutes: 60 diff --git a/docker/README.md b/docker/README.md index 8008e8b..bef4601 100644 --- a/docker/README.md +++ b/docker/README.md @@ -45,7 +45,7 @@ docker compose logs --tail 100 api ai worker | 操作 | 工作流行为 | | --- | --- | | 创建或更新 PR | 检查数据库迁移、类型、测试、两个 Linux 镜像构建及 server 运行工具;不发布镜像 | -| 合并到 main | 检查通过后,将 server / web 镜像推送到 GHCR;不更新服务器 | +| 合并或推送到 main | 检查通过后,将 server / web 镜像推送到 GHCR,再自动备份、迁移并更新服务器 | | 手动运行 Release,deploy 不勾选 | 检查并发布镜像 | | 手动运行 Release,选择 main 并勾选 deploy | 检查、发布镜像、备份数据库、迁移并更新服务器 | @@ -64,7 +64,9 @@ docker compose logs --tail 100 api ai worker `deploy-registry.sh` 只拉取 server / web 镜像,使用服务器已有的 PostgreSQL、Redis 和 MinIO。更新前在 `backups/<时间>-/` 保存 PostgreSQL 自定义格式备份、原 `.env` 和 Compose 文件。迁移失败时保持旧应用;应用或 HTTP 健康检查失败时恢复原配置并重建旧版应用。**数据库不会自动回滚**,不兼容的迁移需要根据备份人工恢复。MinIO 数据和 AI 工作区继续保留在原命名卷。 -首次使用时,先把工作流合并到 main,再打开 GitHub **Actions → Release → Run workflow**,选择 main,勾选 deploy 后运行。后续仍采用这个手动发布步骤。 +将工作流合并到 main 后,本次合并以及后续 main 更新都会自动执行检查、发布镜像并部署。检查或任一镜像发布失败时,部署不会开始。同一分支的发布串行执行,避免并发更新服务器。 + +需要手动重发时,打开 GitHub **Actions → Release → Run workflow**,选择 main,勾选 deploy 后运行。不勾选时仅检查并发布镜像。 手动备份可以在服务器部署目录运行对应版本中的脚本: