Skip to content

fix: broken invariants in agent-loop, "400 No tool output found" #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions codex-cli/src/utils/agent/agent-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ export class AgentLoop {
return;
}

// Reset the current stream to allow new requests
this.currentStream = null;
log(
`AgentLoop.cancel() invoked – currentStream=${Boolean(
this.currentStream,
Expand All @@ -132,6 +130,9 @@ export class AgentLoop {
this.currentStream as { controller?: { abort?: () => void } } | null
)?.controller?.abort?.();

// Reset the current stream to allow new requests
this.currentStream = null;

this.canceled = true;

// Abort any in-progress tool calls
Expand Down Expand Up @@ -859,13 +860,16 @@ export class AgentLoop {
this.onItem(item);
}
}
// guarading clear
// because we may still enter this after abort
this.pendingAborts.clear();
}

// At this point the turn finished without the user invoking
// `cancel()`. Any outstanding function‑calls must therefore have been
// satisfied, so we can safely clear the set that tracks pending aborts
// to avoid emitting duplicate synthetic outputs in subsequent runs.
this.pendingAborts.clear();
// this.pendingAborts.clear();
// Now emit system messages recording the per‑turn *and* cumulative
// thinking times so UIs and tests can surface/verify them.
// const thinkingEnd = Date.now();
Expand Down