Skip to content

Commit bd8519c

Browse files
nerzhulartslapoguzov
authored andcommitted
Send terminal output deltas instead of accumulation for to avoid perf issues
1 parent fa09ceb commit bd8519c

5 files changed

Lines changed: 11 additions & 19 deletions

File tree

src/CodexEventHandler.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class CodexEventHandler {
3030
private readonly connection: acp.AgentSideConnection;
3131
private readonly sessionState: SessionState;
3232
private failure: RequestError | null = null;
33-
private readonly terminalOutputs: Map<string, string> = new Map();
3433

3534
constructor(connection: acp.AgentSideConnection, sessionState: SessionState) {
3635
this.connection = connection;
@@ -73,7 +72,6 @@ export class CodexEventHandler {
7372
return null;
7473
case "turn/completed":
7574
this.sessionState.currentTurnId = null;
76-
this.terminalOutputs.clear();
7775
return null;
7876
case "thread/tokenUsage/updated":
7977
this.handleTokenUsageUpdated(notification.params);
@@ -197,25 +195,19 @@ export class CodexEventHandler {
197195
}
198196

199197
private createCommandOutputDeltaEvent(event: CommandExecutionOutputDeltaNotification): UpdateSessionEvent {
200-
const accumulated = (this.terminalOutputs.get(event.itemId) ?? "") + event.delta;
201-
this.terminalOutputs.set(event.itemId, accumulated);
202-
203198
return {
204199
sessionUpdate: "tool_call_update",
205200
toolCallId: event.itemId,
206201
_meta: {
207-
terminal_output: {
208-
data: accumulated,
202+
terminal_output_delta: {
203+
data: event.delta,
209204
terminal_id: event.itemId
210205
}
211206
}
212207
}
213208
}
214209

215210
private completeCommandExecutionEvent(item: ThreadItem & { "type": "commandExecution" }): UpdateSessionEvent {
216-
// Clean up accumulator
217-
this.terminalOutputs.delete(item.id);
218-
219211
return {
220212
sessionUpdate: "tool_call_update",
221213
toolCallId: item.id,

src/__tests__/CodexACPAgent/data/terminal-full-flow.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sessionUpdate": "tool_call_update",
88
"toolCallId": "command-flow",
99
"_meta": {
10-
"terminal_output": {
10+
"terminal_output_delta": {
1111
"data": "hello\n",
1212
"terminal_id": "command-flow"
1313
}

src/__tests__/CodexACPAgent/data/terminal-output-delta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sessionUpdate": "tool_call_update",
88
"toolCallId": "command-123",
99
"_meta": {
10-
"terminal_output": {
10+
"terminal_output_delta": {
1111
"data": "file1.txt\nfile2.txt\n",
1212
"terminal_id": "command-123"
1313
}

src/__tests__/CodexACPAgent/data/terminal-output-accumulated.json renamed to src/__tests__/CodexACPAgent/data/terminal-output-multiple-deltas.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"sessionUpdate": "tool_call_update",
88
"toolCallId": "command-accumulate",
99
"_meta": {
10-
"terminal_output": {
10+
"terminal_output_delta": {
1111
"data": "line1\n",
1212
"terminal_id": "command-accumulate"
1313
}
@@ -25,8 +25,8 @@
2525
"sessionUpdate": "tool_call_update",
2626
"toolCallId": "command-accumulate",
2727
"_meta": {
28-
"terminal_output": {
29-
"data": "line1\nline2\n",
28+
"terminal_output_delta": {
29+
"data": "line2\n",
3030
"terminal_id": "command-accumulate"
3131
}
3232
}
@@ -43,8 +43,8 @@
4343
"sessionUpdate": "tool_call_update",
4444
"toolCallId": "command-accumulate",
4545
"_meta": {
46-
"terminal_output": {
47-
"data": "line1\nline2\nline3\n",
46+
"terminal_output_delta": {
47+
"data": "line3\n",
4848
"terminal_id": "command-accumulate"
4949
}
5050
}

src/__tests__/CodexACPAgent/terminal-output-events.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('CodexEventHandler - terminal output events', () => {
250250
);
251251
});
252252

253-
it('should accumulate terminal output across multiple deltas', async () => {
253+
it('should stream multiple terminal output deltas without accumulation', async () => {
254254
const delta1: ServerNotification = {
255255
method: 'item/commandExecution/outputDelta',
256256
params: {
@@ -284,7 +284,7 @@ describe('CodexEventHandler - terminal output events', () => {
284284
await setupAndSendNotifications([delta1, delta2, delta3]);
285285

286286
await expect(mockFixture.getAcpConnectionDump([])).toMatchFileSnapshot(
287-
'data/terminal-output-accumulated.json'
287+
'data/terminal-output-multiple-deltas.json'
288288
);
289289
});
290290
});

0 commit comments

Comments
 (0)