Add opt-in recovery for exact-empty CUA responses#55
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Stale harness queue blocks recovery
- CuaAgentHarness now clears its cached pending-queue flag at each before_agent_start so stale queue snapshots cannot suppress empty-response recovery in later runs.
Or push these changes by commenting:
@cursor push 557a29fbb0
Preview (557a29fbb0)
diff --git a/packages/agent/src/agent.ts b/packages/agent/src/agent.ts
--- a/packages/agent/src/agent.ts
+++ b/packages/agent/src/agent.ts
@@ -533,6 +533,7 @@
if (recovery && recovery.maxAttempts > 0) {
this.on("before_agent_start", () => {
this.emptyResponseRecoveryAttempts = 0;
+ this.hasPendingActiveQueue = false;
return undefined;
});
this.subscribe(async (event, signal) => {
diff --git a/packages/agent/test/agent.test.ts b/packages/agent/test/agent.test.ts
--- a/packages/agent/test/agent.test.ts
+++ b/packages/agent/test/agent.test.ts
@@ -767,6 +767,24 @@
expect(scripted.calls()).toBe(4);
});
+ it("clears stale queue snapshots before a new prompt starts", async () => {
+ const scripted = createScriptedModels([undefined, "finished"]);
+ const harness = new CuaAgentHarness({
+ ...(await createHarnessServices()),
+ browser,
+ client,
+ model: "openai:gpt-5.5",
+ models: scripted.models,
+ emptyResponseRecovery: recovery,
+ });
+
+ (harness as unknown as { hasPendingActiveQueue: boolean }).hasPendingActiveQueue = true;
+ const response = await harness.prompt("finish the task");
+
+ expect(scripted.calls()).toBe(2);
+ expect(response.content).toEqual([{ type: "text", text: "finished" }]);
+ });
+
it("makes exactly one additional call per configured attempt", async () => {
const scripted = createScriptedModels([undefined, undefined, undefined]);
const harness = new CuaAgentHarness({You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 08fdeff. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
CuaAgentandCuaAgentHarnesswith caller-supplied follow-up textfollowUp()queue so queued caller work takes precedence and recovery remains a distinct billed model turnnextTurnbehavior, and queue-state reset between promptsTesting
npm run typechecknpm test --workspace @onkernel/cua-agent -- --exclude '**/*.live.test.ts'(160 passed)npm test --workspace @onkernel/cua-cli(82 passed, 5 skipped)git diff --checkNote
Medium Risk
Changes agent turn completion and can trigger extra billed provider calls when enabled; default-off and queue/abort guards limit blast radius.
Overview
Adds optional empty response recovery on
CuaAgentandCuaAgentHarnessviaemptyResponseRecovery: { followUp, maxAttempts }. When omitted ormaxAttempts: 0, behavior stays the same as pi: an assistant turn with empty content andstopReason: "stop"ends the run.With recovery enabled, a
turn_endmatching that exact-empty pattern queues a configured user message through pi'sfollowUp(), keeps the empty assistant message in history, and runs another provider turn untilmaxAttemptsis hit. Recovery resets each top-level prompt; it skips when the run is aborted, caller queues already have steer/follow-up work, or the response is not exact-empty (whitespace/thinking blocks, non-stopreasons, tool-use turns).Constructor validation rejects blank
followUpand invalidmaxAttempts. README documents cost, defaults, and history semantics.CuaEmptyResponseRecoveryOptionsis exported; tests cover both agent and harness paths.Reviewed by Cursor Bugbot for commit 080b30d. Bugbot is set up for automated code reviews on this repo. Configure here.