A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix(coding-agent): reject headless idle waiters when a post-compaction continuation cannot start (#1583)
Sebastian Müllerab3db326d161
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex 5fa674df4e..0f7510c5a3 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -2,6 +2,7 @@## [Unreleased]+- Fixed headless completion reporting a clean finish when a post-compaction continuation failed to start: ACP and print-mode idle waiters now see the failure, while interactive idle behavior is unchanged.- Added a pre-imported generic MCP API and shell/TUI commands to manage persistent Streamable HTTP and stdio servers in user settings.- **Breaking**: removed the documented catalog-name override — an `mcpServers` entry named after a built-in integration (e.g. `linear`) no longer repoints the built-in at a custom `url`/`bearerTokenEnvVar`; it now disables the built-in skill and is not served by the generic runtime. Rename the entry (e.g. `linear-proxy`) to keep using a custom endpoint via the generic API. This closes a credential-replay surface where name-keyed tokens could be sent to an override URL.- Fixed agents overlooking enabled generic MCP connections by advertising their names and pre-imported `mcp` API usage in the system prompt.diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.tsindex e790e5073c..ef75fe91d7 100644--- a/packages/coding-agent/src/core/agent-session.ts+++ b/packages/coding-agent/src/core/agent-session.ts@@ -816,6 +816,15 @@ function createAgentMessageDeferred(): AgentMessageDeferred {return deferred;}+/** One-shot settlement for a scheduled post-compaction continuation; a settled failure is never re-exposed to later waiters. */+interface PostCompactionContinuationSettlement extends AgentMessageDeferred {+ settled: boolean;+}++function createPostCompactionContinuationSettlement(): PostCompactionContinuationSettlement {+ return { ...createAgentMessageDeferred(), settled: false };+}+export interface ModelCycleResult {model: Model<any>;thinkingLevel: ThinkingLevel;@@ -1177,7 +1186,7 @@ export class AgentSession {private _turnIntervalAutoRefinePending = false;private _postCompactionContinuationScheduled = false;private _postCompactionContinuationTimer: ReturnType<typeof setTimeout> | undefined;- private _postCompactionContinuationSettlement: AgentMessageDeferred | undefined;+ private _postCompactionContinuationSettlement: PostCompactionContinuationSettlement | undefined;private _postCompactionContinuationMessages: AgentMessage[] = [];private _scheduledPostCompactionContinuationMessages: AgentMessage[] = [];private _queuedAutonomousThresholdContinuations = new WeakMap<AssistantMessage, AgentMessage>();@@ -6655,7 +6664,7 @@ export class AgentSession {}}- /** Wait for normal idle and any continuation already owned by compaction. */+ /** Waits out any owned post-compaction continuation and rejects when one cannot start; {@link waitForIdle} never rejects. */async waitForHeadlessIdle(): Promise<void> {while (true) {await this.waitForIdle();@@ -7333,11 +7342,14 @@ export class AgentSession {return this._rlmDepth === 0 && this._localHarnessStateDir() !== undefined;}- private _settlePostCompactionContinue(): void {- if (this._postCompactionContinuationScheduled || this._postCompactionContinuationTimer) return;+ private _settlePostCompactionContinue(error?: Error): void {+ if (!error && (this._postCompactionContinuationScheduled || this._postCompactionContinuationTimer)) return;const settlement = this._postCompactionContinuationSettlement;+ if (!settlement || settlement.settled) return;+ settlement.settled = true;this._postCompactionContinuationSettlement = undefined;- settlement?.resolve();+ if (error) settlement.reject(error);+ else settlement.resolve();}private _cancelPostCompactionContinue(): void {@@ -7444,7 +7456,9 @@ export class AgentSession {if (this._postCompactionContinuationScheduled) {return;}- this._postCompactionContinuationSettlement ??= createAgentMessageDeferred();+ if (!this._postCompactionContinuationSettlement || this._postCompactionContinuationSettlement.settled) {+ this._postCompactionContinuationSettlement = createPostCompactionContinuationSettlement();+ }this._postCompactionContinuationScheduled = true;this._scheduledPostCompactionContinuationMessages = [...this._postCompactionContinuationMessages];this._postCompactionContinuationTimer = setTimeout(() => {@@ -7504,6 +7518,9 @@ export class AgentSession {const message = error instanceof Error ? error.message : String(error);if (message.includes("already processing")) {this._schedulePostCompactionContinue();+ } else if (!message.includes("continue from")) {+ // "continue from" means the turn already completed; anything else must reject headless idle waiters.+ this._settlePostCompactionContinue(this._asError(error));}}}diff --git a/packages/coding-agent/test/suite/agent-session-compaction-continuation.test.ts b/packages/coding-agent/test/suite/agent-session-compaction-continuation.test.tsindex 259baeb15f..06c9a215e4 100644--- a/packages/coding-agent/test/suite/agent-session-compaction-continuation.test.ts+++ b/packages/coding-agent/test/suite/agent-session-compaction-continuation.test.ts@@ -239,6 +239,38 @@ describe("compaction continuation", () => {expect(harness.session.getLastAssistantText()).toBe("final answer after successful compaction");});+ it("rejects headless idle waiters when a continuation cannot start", async () => {+ vi.useFakeTimers();+ const harness = await createHarness();+ harnesses.push(harness);+ const sessionInternals = harness.session as unknown as {+ _schedulePostCompactionContinue(): void;+ };+ vi.spyOn(harness.session.agent, "continue").mockRejectedValueOnce(new Error("continuation failed"));++ sessionInternals._schedulePostCompactionContinue();+ const idle = harness.session.waitForHeadlessIdle();+ const rejectedIdle = expect(idle).rejects.toThrow("continuation failed");+ await vi.advanceTimersByTimeAsync(100);++ await rejectedIdle;+ });++ it("does not expose a failed continuation to later headless idle waiters", async () => {+ vi.useFakeTimers();+ const harness = await createHarness();+ harnesses.push(harness);+ const sessionInternals = harness.session as unknown as {+ _schedulePostCompactionContinue(): void;+ };+ vi.spyOn(harness.session.agent, "continue").mockRejectedValueOnce(new Error("continuation failed"));++ sessionInternals._schedulePostCompactionContinue();+ await vi.advanceTimersByTimeAsync(100);++ await expect(harness.session.waitForHeadlessIdle()).resolves.toBeUndefined();+ });+// BUG B (end-to-end): unlike the tests above, the threshold compaction here SUCCEEDS.it("e2e: an active goal keeps continuing after a successful threshold compaction", async () => {const sessionRef: { current?: AgentSession } = {};