Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(coding-agent): resume active goals after manual compaction (#2122)

Seth Kartenbcdcd6e65e10
diff --git a/packages/coding-agent/.changes/goal-continuation-after-compaction.md b/packages/coding-agent/.changes/goal-continuation-after-compaction.md
new file mode 100644
index 0000000000..125acd5420
--- /dev/null
+++ b/packages/coding-agent/.changes/goal-continuation-after-compaction.md
@@ -0,0 +1 @@
+- Fixed active goals stalling after manual compaction.
diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts
index 90733d4d72..eec21e2341 100644
--- a/packages/coding-agent/src/core/agent-session.ts
+++ b/packages/coding-agent/src/core/agent-session.ts
@@ -7572,7 +7572,8 @@ export class AgentSession {
this._disconnectFromAgent();
if (!options.skipAbort) await this.abort();
let didCompact = false;
- this._compactionAbortController = new AbortController();
+ const compactionAbort = new AbortController();
+ this._compactionAbortController = compactionAbort;
let resolveCompactionOperation: () => void = () => {};
const compactionOperation = new Promise<void>((resolve) => {
resolveCompactionOperation = resolve;
@@ -7595,7 +7596,7 @@ export class AgentSession {
apiKey,
headers,
customInstructions,
- signal: this._compactionAbortController.signal,
+ signal: compactionAbort.signal,
});
this._emit({
@@ -7637,13 +7638,21 @@ export class AgentSession {
this._scheduleSessionInputPump();
if (didCompact) {
this._discardPendingAutoRefine({ cancelPostCompactionContinue: true });
+ if (this._goalState.status === "active" && !compactionAbort.signal.aborted) {
+ this._goalContinuationAwaitsRlmWork ||= !this.agent.hasQueuedMessages();
+ this.resumeQueuedWork();
+ if (this.agent.hasQueuedMessages()) this._schedulePostCompactionContinue();
+ }
if (hadPostCompactionContinue) {
this._schedulePostCompactionContinue(continueAfterSessionInput);
}
// Queued agent or session-owned inputs resume the loop; defer refine
// behind them instead of interleaving it before their turns.
this._scheduleAutoRefineAfterCompaction(
- hadPostCompactionContinue || this.agent.hasQueuedMessages() || this.unfinishedActionCount > 0,
+ this._goalContinuationAwaitsRlmWork ||
+ hadPostCompactionContinue ||
+ this.agent.hasQueuedMessages() ||
+ this.unfinishedActionCount > 0,
);
}
}
diff --git a/packages/coding-agent/test/suite/agent-session-goal.test.ts b/packages/coding-agent/test/suite/agent-session-goal.test.ts
index e806ac04d7..20e9ceb0c9 100644
--- a/packages/coding-agent/test/suite/agent-session-goal.test.ts
+++ b/packages/coding-agent/test/suite/agent-session-goal.test.ts
@@ -161,6 +161,23 @@ describe("AgentSession goals", () => {
return harness;
}
+ it("resumes an active goal after manual compaction", async () => {
+ const harness = await createGoalHarness();
+ const internals = harness.session as unknown as { _performCompaction(): Promise<unknown> };
+ vi.spyOn(internals, "_performCompaction").mockResolvedValue({ summary: "compacted" });
+ harness.session.handleGoalHostRequest("goal.create", { objective: "finish the task" });
+ harness.setResponses([
+ fauxAssistantMessage(fauxToolCall("ipython", COMPLETE_GOAL_CELL), { stopReason: "toolUse" }),
+ fauxAssistantMessage("Goal complete."),
+ ]);
+
+ await harness.session.compact();
+ await harness.session.waitForHeadlessIdle();
+
+ expect(harness.session.goalState.status).toBe("complete");
+ expect(harness.getPendingResponseCount()).toBe(0);
+ });
+
it("keeps continuing until the model completes the goal through ipython", async () => {
const harness = await createGoalHarness();
harness.setResponses([