Skip to content

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

Rust

fix(coding-agent): surface seeded --goal objective to the model (#593)

Sebastian Müller1793cbc783fa
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 804544d535..9846857b90 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -3,6 +3,7 @@
## [Unreleased]
- Fixed daemon parse rejections dropping the command id, which left older clients waiting for a timeout instead of seeing the protocol error.
+- Fixed `--goal` sessions never showing the objective to the model, which made seeded goals invisible to first turns and continuations.
- Changed large daemon session loads to stream JSONL history and avoid retaining a second full-file copy in memory.
- Changed the agents view to render explicit session names in bold and the "(no messages)" placeholder in italics.
- Fixed the blank line between the recap and the working hint so they render directly above each other.
diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts
index 6ce031d38f..1ad1d3c4fd 100644
--- a/packages/coding-agent/src/core/agent-session.ts
+++ b/packages/coding-agent/src/core/agent-session.ts
@@ -1248,6 +1248,9 @@ export class AgentSession {
// or restart/rehydration of a session that already has messages or a goal.
if (this._rlmDepth === 0 && config.initialGoal && this._isBranchSeedable()) {
this._goalState = this._startGoal(config.initialGoal.objective, config.initialGoal.tokenBudget);
+ // Goal context is the model's only source of goal visibility; action
+ // admission is unavailable mid-construction, so ride the next turn.
+ this._pendingNextTurnMessages.push(createGoalContextMessage(this._goalState, "continuation"));
}
this._restoreLateIpythonSentAgentMessages();
if (this._goalState.status === "active") {
@@ -1622,6 +1625,9 @@ export class AgentSession {
}
private _clearQueuedGoalContexts(): void {
+ this._pendingNextTurnMessages = this._pendingNextTurnMessages.filter(
+ (message) => message.customType !== GOAL_CONTEXT_CUSTOM_TYPE,
+ );
this.agent.removeQueuedMessages(
(message) => message.role === "custom" && message.customType === GOAL_CONTEXT_CUSTOM_TYPE,
);
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 d5bb7b0c97..29528f0362 100644
--- a/packages/coding-agent/test/suite/agent-session-goal.test.ts
+++ b/packages/coding-agent/test/suite/agent-session-goal.test.ts
@@ -902,6 +902,33 @@ describe("initial goal seeding from config", () => {
const branch = harness.sessionManager.getBranch();
const goalEntry = branch.find((e) => e.type === "custom" && e.customType === GOAL_STATE_CUSTOM_TYPE);
expect(goalEntry).toBeDefined();
+
+ // The seeded goal context must reach the model before its first reply.
+ harness.setResponses([fauxAssistantMessage("ack")]);
+ await harness.session.prompt("hello");
+ const messages = harness.session.messages;
+ const firstContextIndex = messages.findIndex(
+ (message) => message.role === "custom" && message.customType === "goal_context",
+ );
+ const firstAssistantIndex = messages.findIndex((message) => message.role === "assistant");
+ expect(firstContextIndex).toBeGreaterThanOrEqual(0);
+ expect(firstContextIndex).toBeLessThan(firstAssistantIndex);
+ expect(getMessageText(messages[firstContextIndex])).toContain("Write tests");
+ expect(currentAgentContext(harness).messages).toContain(messages[firstContextIndex]);
+ });
+
+ it("drops the seeded goal context when the goal is cleared before the first prompt", async () => {
+ const harness = await createHarness({
+ persistSession: true,
+ initialGoal: { objective: "Write tests", tokenBudget: 50000 },
+ });
+ harnesses.push(harness);
+
+ harness.setResponses([fauxAssistantMessage("ack")]);
+ await harness.session.prompt("/goal clear");
+ expect(harness.session.goalState.status).toBe("idle");
+ await harness.session.prompt("hello");
+ expect(goalContextMessages(harness)).toHaveLength(0);
});
it("does not seed initialGoal for subagent sessions (rlmDepth > 0)", async () => {