Skip to content

Commit 664fb01

Browse files
committed
Fix AgentWatch core typecheck regressions
1 parent a66c99b commit 664fb01

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎apps/server/src/agentWatch.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ function parseExitCodeFromLog(logPath: string): number | undefined {
6969
if (!match || match.length === 0) {
7070
return undefined;
7171
}
72-
const latest = match[match.length - 1];
72+
const latest = match.at(-1);
73+
if (!latest) {
74+
return undefined;
75+
}
7376
const parsed = Number.parseInt(latest.slice(EXIT_MARKER_PREFIX.length), 10);
7477
return Number.isInteger(parsed) ? parsed : undefined;
7578
} catch {
@@ -220,7 +223,10 @@ export class AgentWatch {
220223

221224
if (!isProcessAlive(job.pid)) {
222225
job.finishedAt = now;
223-
job.exitCode = parseExitCodeFromLog(job.logPath);
226+
const exitCode = parseExitCodeFromLog(job.logPath);
227+
if (exitCode !== undefined) {
228+
job.exitCode = exitCode;
229+
}
224230
}
225231
}
226232
}
@@ -232,7 +238,11 @@ export class AgentWatch {
232238

233239
const conditions: AgentWatchCondition[] = [];
234240

235-
if (status === "running" && outputFreshnessMs !== undefined && outputFreshnessMs > job.staleAfterMs) {
241+
if (
242+
status === "running" &&
243+
outputFreshnessMs !== undefined &&
244+
outputFreshnessMs > job.staleAfterMs
245+
) {
236246
conditions.push({
237247
code: "stale_output",
238248
message: `No terminal output for ${outputFreshnessMs}ms (threshold ${job.staleAfterMs}ms).`,
@@ -292,7 +302,9 @@ export class AgentWatch {
292302
if (toolName === "agentwatch.poll") {
293303
return this.poll({
294304
...(typeof args?.jobId === "string" ? { jobId: args.jobId } : {}),
295-
...(typeof args?.includeHealthy === "boolean" ? { includeHealthy: args.includeHealthy } : {}),
305+
...(typeof args?.includeHealthy === "boolean"
306+
? { includeHealthy: args.includeHealthy }
307+
: {}),
296308
});
297309
}
298310

‎apps/server/src/codexAppServerManager.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,6 @@ describe("respondToUserInput", () => {
748748
});
749749
});
750750

751-
752-
753751
describe("handleServerRequest tool calls", () => {
754752
it("routes item/tool/call to AgentWatch and writes a JSON-RPC result", () => {
755753
const manager = new CodexAppServerManager();
@@ -767,6 +765,7 @@ describe("handleServerRequest tool calls", () => {
767765
pendingApprovals: new Map(),
768766
pendingUserInputs: new Map(),
769767
};
768+
type TestContext = typeof context;
770769

771770
const writeMessage = vi
772771
.spyOn(manager as unknown as { writeMessage: (...args: unknown[]) => void }, "writeMessage")
@@ -782,7 +781,7 @@ describe("handleServerRequest tool calls", () => {
782781

783782
(
784783
manager as unknown as {
785-
handleServerRequest: (context: typeof context, request: Record<string, unknown>) => void;
784+
handleServerRequest: (context: TestContext, request: Record<string, unknown>) => void;
786785
}
787786
).handleServerRequest(context, {
788787
jsonrpc: "2.0",

‎apps/server/src/codexAppServerManager.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ export interface CodexAppServerManagerEvents {
515515

516516
export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEvents> {
517517
private readonly sessions = new Map<ThreadId, CodexSessionContext>();
518+
private readonly agentWatch = new AgentWatch();
518519

519520
private runPromise: (effect: Effect.Effect<unknown, never>) => Promise<unknown>;
520521
constructor(services?: ServiceMap.ServiceMap<never>) {
@@ -1219,7 +1220,8 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
12191220
}
12201221

12211222
if (request.method === "item/tool/call") {
1222-
const toolName = this.readString(request.params, "toolName") ?? this.readString(request.params, "name");
1223+
const toolName =
1224+
this.readString(request.params, "toolName") ?? this.readString(request.params, "name");
12231225
const rawArgs =
12241226
this.readObject(request.params, "arguments") ??
12251227
this.readObject(request.params, "input") ??

0 commit comments

Comments
 (0)