惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
WordPress大学
WordPress大学
雷峰网
雷峰网
小众软件
小众软件
D
DataBreaches.Net
V
Visual Studio Blog
博客园 - Franky
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
博客园 - 聂微东
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
云风的 BLOG
云风的 BLOG

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(codex): unsubscribe app-server thread after runs (#84...
ai-hpc · 2026-05-22 · via Recent Commits to openclaw:main

@@ -0,0 +1,197 @@

1+

import fs from "node:fs/promises";

2+

import os from "node:os";

3+

import path from "node:path";

4+

import {

5+

resetAgentEventsForTest,

6+

type EmbeddedRunAttemptParams,

7+

} from "openclaw/plugin-sdk/agent-harness-runtime";

8+

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

9+

import type { CodexAppServerClientFactory } from "./client-factory.js";

10+

import type { CodexServerNotification } from "./protocol.js";

11+

import { runCodexAppServerAttempt } from "./run-attempt.js";

12+

import { createCodexTestModel } from "./test-support.js";

13+14+

let tempDir: string;

15+16+

function createParams(sessionFile: string, workspaceDir: string): EmbeddedRunAttemptParams {

17+

return {

18+

prompt: "hello",

19+

sessionId: "session-1",

20+

sessionKey: "agent:main:session-1",

21+

sessionFile,

22+

workspaceDir,

23+

runId: "run-1",

24+

provider: "codex",

25+

modelId: "gpt-5.4-codex",

26+

model: createCodexTestModel("codex"),

27+

thinkLevel: "medium",

28+

disableTools: true,

29+

timeoutMs: 5_000,

30+

authStorage: {} as never,

31+

authProfileStore: { version: 1, profiles: {} },

32+

modelRegistry: {} as never,

33+

} as EmbeddedRunAttemptParams;

34+

}

35+36+

function threadStartResult(threadId = "thread-1") {

37+

return {

38+

thread: {

39+

id: threadId,

40+

sessionId: "session-1",

41+

forkedFromId: null,

42+

preview: "",

43+

ephemeral: false,

44+

modelProvider: "openai",

45+

createdAt: 1,

46+

updatedAt: 1,

47+

status: { type: "idle" },

48+

path: null,

49+

cwd: tempDir || "/tmp/openclaw-codex-test",

50+

cliVersion: "0.125.0",

51+

source: "unknown",

52+

agentNickname: null,

53+

agentRole: null,

54+

gitInfo: null,

55+

name: null,

56+

turns: [],

57+

},

58+

model: "gpt-5.4-codex",

59+

modelProvider: "openai",

60+

serviceTier: null,

61+

cwd: tempDir || "/tmp/openclaw-codex-test",

62+

instructionSources: [],

63+

approvalPolicy: "never",

64+

approvalsReviewer: "user",

65+

sandbox: { type: "dangerFullAccess" },

66+

permissionProfile: null,

67+

reasoningEffort: null,

68+

};

69+

}

70+71+

function turnStartResult(turnId = "turn-1") {

72+

return {

73+

turn: {

74+

id: turnId,

75+

status: "inProgress",

76+

items: [],

77+

error: null,

78+

startedAt: null,

79+

completedAt: null,

80+

durationMs: null,

81+

},

82+

};

83+

}

84+85+

describe("Codex app-server main thread cleanup", () => {

86+

beforeEach(async () => {

87+

resetAgentEventsForTest();

88+

vi.stubEnv("OPENCLAW_TRAJECTORY", "0");

89+

vi.stubEnv("CODEX_API_KEY", "");

90+

vi.stubEnv("OPENAI_API_KEY", "");

91+

tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-run-cleanup-"));

92+

});

93+94+

afterEach(async () => {

95+

resetAgentEventsForTest();

96+

vi.restoreAllMocks();

97+

vi.unstubAllEnvs();

98+

await fs.rm(tempDir, { recursive: true, force: true });

99+

});

100+101+

it("unsubscribes the main Codex thread after a completed turn", async () => {

102+

const sessionFile = path.join(tempDir, "session.jsonl");

103+

const workspaceDir = path.join(tempDir, "workspace");

104+

const requests: Array<{ method: string; params: unknown }> = [];

105+

let notify: (notification: CodexServerNotification) => Promise<void> = async () => undefined;

106+

const request = vi.fn(async (method: string, params?: unknown) => {

107+

requests.push({ method, params });

108+

if (method === "thread/start") {

109+

return threadStartResult();

110+

}

111+

if (method === "turn/start") {

112+

return turnStartResult();

113+

}

114+

return {};

115+

});

116+117+

const clientFactory: CodexAppServerClientFactory = async () => {

118+

return {

119+

request,

120+

addNotificationHandler: (handler: typeof notify) => {

121+

notify = handler;

122+

return () => undefined;

123+

},

124+

addRequestHandler: () => () => undefined,

125+

} as never;

126+

};

127+128+

const run = runCodexAppServerAttempt(createParams(sessionFile, workspaceDir), {

129+

clientFactory,

130+

});

131+

await vi.waitFor(() => expect(requests.map((entry) => entry.method)).toContain("turn/start"), {

132+

interval: 1,

133+

timeout: 5_000,

134+

});

135+

await notify({

136+

method: "turn/completed",

137+

params: {

138+

threadId: "thread-1",

139+

turnId: "turn-1",

140+

turn: { id: "turn-1", status: "completed" },

141+

},

142+

});

143+144+

const result = await run;

145+

expect(result.aborted).toBe(false);

146+

expect(request).toHaveBeenCalledWith(

147+

"thread/unsubscribe",

148+

{ threadId: "thread-1" },

149+

{ timeoutMs: 5_000 },

150+

);

151+

expect(requests.map((entry) => entry.method)).toEqual([

152+

"thread/start",

153+

"turn/start",

154+

"thread/unsubscribe",

155+

]);

156+

});

157+158+

it("unsubscribes the main Codex thread when turn start fails", async () => {

159+

const sessionFile = path.join(tempDir, "session.jsonl");

160+

const workspaceDir = path.join(tempDir, "workspace");

161+

const requests: Array<{ method: string; params: unknown }> = [];

162+

const request = vi.fn(async (method: string, params?: unknown) => {

163+

requests.push({ method, params });

164+

if (method === "thread/start") {

165+

return threadStartResult();

166+

}

167+

if (method === "turn/start") {

168+

throw new Error("turn start exploded");

169+

}

170+

return {};

171+

});

172+173+

const clientFactory: CodexAppServerClientFactory = async () => {

174+

return {

175+

request,

176+

addNotificationHandler: () => () => undefined,

177+

addRequestHandler: () => () => undefined,

178+

} as never;

179+

};

180+181+

await expect(

182+

runCodexAppServerAttempt(createParams(sessionFile, workspaceDir), {

183+

clientFactory,

184+

}),

185+

).rejects.toThrow("turn start exploded");

186+

expect(requests.map((entry) => entry.method)).toEqual([

187+

"thread/start",

188+

"turn/start",

189+

"thread/unsubscribe",

190+

]);

191+

expect(request).toHaveBeenCalledWith(

192+

"thread/unsubscribe",

193+

{ threadId: "thread-1" },

194+

{ timeoutMs: 5_000 },

195+

);

196+

});

197+

});