Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(serve): answered stdio requests count as boot progress

garrytan5c1057c0fff8
diff --git a/src/mcp/server.ts b/src/mcp/server.ts
index 129bd37d48..31560138cc 100644
--- a/src/mcp/server.ts
+++ b/src/mcp/server.ts
@@ -1,3 +1,4 @@
+import { noteForwardProgress } from '../core/forward-progress.ts';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
@@ -193,6 +194,10 @@ export async function trackStdioRpc<T>(work: () => Promise<T>): Promise<T> {
return await work();
} finally {
_stdioRpcsInFlight--;
+ // A completed request is forward progress: serve's boot deadline must not
+ // stop a server that is answering its client while a boot phase waits on
+ // the engine behind those requests.
+ noteForwardProgress();
}
}
diff --git a/test/serve-stdio-lifecycle.test.ts b/test/serve-stdio-lifecycle.test.ts
index ec774a5d98..cc661f0ddf 100644
--- a/test/serve-stdio-lifecycle.test.ts
+++ b/test/serve-stdio-lifecycle.test.ts
@@ -715,6 +715,23 @@ describe('boot-readiness deadline (#3273)', () => {
expect(h.logs.some(l => l.includes('boot did not complete'))).toBe(false);
});
+ // The 52k-document serve kept answering tool calls while its boot waited on
+ // the engine behind them; completed requests are progress too.
+ test('a boot phase waiting behind answered tool calls is not killed', async () => {
+ const { trackStdioRpc } = await import('../src/mcp/server.ts');
+ const h = makeHarness();
+ h.opts.startMcpServer = async (_engine, startOpts) => {
+ startOpts?.onBootPhase?.('mcp_connect');
+ startOpts?.onBootPhase?.('persistence_consumer');
+ for (let i = 0; i < 12; i++) await trackStdioRpc(() => new Promise(r => setTimeout(r, 20)));
+ };
+ h.opts.bootTimeoutMs = 60;
+ await runServe(h.engine as unknown as BrainEngine, [], h.opts);
+ await new Promise(r => setTimeout(r, 100));
+ expect(h.engine.disconnectCalls).toBe(0);
+ expect(h.logs.some(l => l.includes('boot did not complete'))).toBe(false);
+ });
+
test('a boot that stops advancing still exits one window after its last progress, naming the phase', async () => {
const h = makeHarness();
h.opts.startMcpServer = async (_engine, startOpts) => {