Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Replay the environment note verbatim again (#1184)

Joshua France45667a952418
diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.ts
index 8002fd657..426efc194 100644
--- a/src/core/orchestrator.ts
+++ b/src/core/orchestrator.ts
@@ -2598,11 +2598,10 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
const sender = !automatedTurn && input.text.trim() ? senderNote(actor.displayName) : "";
const unscreenedNote = inputUnscreened || inbound.unscreened.length ? unscreenedNotice("inbound content") : "";
const turnEnvironment = environmentNote(
- [manifest, principalDelivered, sender, unscreenedNote, input.conversationHeader?.trim()]
+ [manifest, principalDelivered, sender, unscreenedNote, input.conversationHeader?.trim(), volatileContext]
.filter((s) => s && s.trim())
.join("\n\n"),
);
- const turnVolatile = environmentNote(volatileContext);
const baseText = input.proactiveOpener && !input.text.trim() ? PROACTIVE_OPENER_PROMPT : input.text;
const pausedTurnUserEntry = input.approval
? [...visibleHistory].reverse().find((e) => e.type === "user" && !isOverheardEntry(e))
@@ -2855,7 +2854,6 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
...(!partial && messageTs ? { triggerTs: messageTs } : {}),
...(!partial && entryTs ? { entryTs } : {}),
...(turnEnvironment ? { environment: turnEnvironment } : {}),
- ...(turnVolatile ? { volatileContext: turnVolatile } : {}),
...(extras.priorTurns?.length ? { priorTurns: extras.priorTurns } : {}),
...(extras.overheard?.length ? { overheard: extras.overheard } : {}),
...(extras.attachments?.length ? { attachments: extras.attachments } : {}),
diff --git a/src/harness/claude-harness.ts b/src/harness/claude-harness.ts
index 29adef4a6..8a8e033ee 100644
--- a/src/harness/claude-harness.ts
+++ b/src/harness/claude-harness.ts
@@ -216,9 +216,7 @@ function promptText(turn: HarnessTurnInput): string {
: seedPriorTurns(turn.priorTurns ?? [])
.map((message) => message.text)
.join("\n");
- return [replay, prior, turn.input, turn.environment, turn.volatileContext]
- .filter((value) => value?.trim())
- .join("\n\n");
+ return [replay, prior, turn.input, turn.environment].filter((value) => value?.trim()).join("\n\n");
}
function userMessage(text: string, images: HarnessTurnInput["images"] = []): SDKUserMessage {
diff --git a/src/harness/codex-harness.ts b/src/harness/codex-harness.ts
index becab2680..09dd6ade1 100644
--- a/src/harness/codex-harness.ts
+++ b/src/harness/codex-harness.ts
@@ -358,14 +358,14 @@ export function codexReasoningEffort(value: string | undefined): "low" | "medium
}
export function codexTurnInputText(
- turn: Pick<HarnessTurnInput, "history" | "priorTurns" | "input" | "environment" | "volatileContext">,
+ turn: Pick<HarnessTurnInput, "history" | "priorTurns" | "input" | "environment">,
): string {
const prior = turn.history.length
? ""
: seedPriorTurns(turn.priorTurns ?? [])
.map((message) => message.text)
.join("\n");
- return [prior, turn.input, turn.environment, turn.volatileContext].filter((item) => item?.trim()).join("\n\n");
+ return [prior, turn.input, turn.environment].filter((item) => item?.trim()).join("\n\n");
}
export function createCodexHarness(opts: CodexHarnessOptions = {}): Harness {
diff --git a/src/harness/harness.ts b/src/harness/harness.ts
index 3d2ab63ce..42ad45e65 100644
--- a/src/harness/harness.ts
+++ b/src/harness/harness.ts
@@ -78,7 +78,6 @@ export interface HarnessTurnInput {
triggerTs?: string;
entryTs?: string;
environment?: string;
- volatileContext?: string;
priorTurns?: ConversationTurn[];
overheard?: OverheardEntryPayload[];
attachments?: AttachmentMeta[];
diff --git a/src/harness/mock-harness.ts b/src/harness/mock-harness.ts
index d05bb8181..d38e92840 100644
--- a/src/harness/mock-harness.ts
+++ b/src/harness/mock-harness.ts
@@ -102,9 +102,7 @@ export function createMockHarness(): Harness {
},
scopeLabel: turn.scopeLabel,
});
- const modelPrompt = [turn.input, turn.environment, turn.volatileContext]
- .filter((s) => s && s.trim())
- .join("\n\n");
+ const modelPrompt = [turn.input, turn.environment].filter((s) => s && s.trim()).join("\n\n");
turn.recordModelCall({
model: "mock",
@@ -331,7 +329,7 @@ export function createMockHarness(): Harness {
} else if (command0 === "!histcount") {
reply = `history:${turn.history.length}`;
} else if (command0 === "!sysprompt") {
- reply = [turn.systemPrompt, turn.environment, turn.volatileContext].filter((s) => s && s.trim()).join("\n\n");
+ reply = [turn.systemPrompt, turn.environment].filter((s) => s && s.trim()).join("\n\n");
} else if (command0 === "!wallclock") {
reply = `wallclock:${turn.turnWallClockMs ?? 0}`;
} else if (command0 === "!surfacename") {
diff --git a/src/harness/opencode-harness.ts b/src/harness/opencode-harness.ts
index 947d5db32..acafdf882 100644
--- a/src/harness/opencode-harness.ts
+++ b/src/harness/opencode-harness.ts
@@ -967,7 +967,7 @@ export function createOpenCodeHarness(opts: OpenCodeHarnessOptions = {}): Harnes
}
}
};
- const prompt = [turn.input, turn.environment, turn.volatileContext].filter((item) => item?.trim()).join("\n\n");
+ const prompt = [turn.input, turn.environment].filter((item) => item?.trim()).join("\n\n");
const promptParts: Array<Record<string, unknown>> = [
{ type: "text", text: prompt },
...(turn.images ?? []).map((image, index) => ({
diff --git a/src/harness/pi-harness.ts b/src/harness/pi-harness.ts
index f511cc6d0..efe6fab9a 100644
--- a/src/harness/pi-harness.ts
+++ b/src/harness/pi-harness.ts
@@ -711,21 +711,6 @@ export function stoppedPartialTapeMessage(
};
}
-export function withoutVolatileContext(message: unknown, sent: string, durable: string): unknown {
- if (sent === durable || !durable.trim()) return message;
- const m = message as { content?: unknown };
- if (typeof m?.content === "string") return m.content === sent ? { ...m, content: durable } : message;
- if (!Array.isArray(m?.content)) return message;
- return {
- ...(message as Record<string, unknown>),
- content: m.content.map((block) =>
- (block as { type?: unknown; text?: unknown })?.type === "text" && (block as { text?: unknown }).text === sent
- ? { ...(block as object), text: durable }
- : block,
- ),
- };
-}
-
export function stripImageBytes(message: unknown, images?: readonly { artifactId?: string }[]): unknown {
const m = message as { content?: unknown };
if (!m || !Array.isArray(m.content)) return message;
@@ -1831,8 +1816,7 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {
if (pausedGoalAtStart) return goalPausedNote(pausedGoalAtStart);
return "";
})();
- const durablePrompt = [goalNote, turn.input, turn.environment].filter((s) => s && s.trim()).join("\n\n");
- const modelPrompt = [durablePrompt, turn.volatileContext].filter((s) => s && s.trim()).join("\n\n");
+ const modelPrompt = [goalNote, turn.input, turn.environment].filter((s) => s && s.trim()).join("\n\n");
entry.ref.llmCapture = [];
entry.ref.modelCalls = 0;
entry.ref.modelDispatch = [];
@@ -1865,13 +1849,6 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {
entryCreatedAt: steer!.entryCreatedAt,
};
};
- const tapedTrigger = (message: unknown): unknown => {
- const taped = withoutVolatileContext(message, modelPrompt, durablePrompt);
- if (taped === message && durablePrompt.trim() && modelPrompt !== durablePrompt) {
- console.error(`[pi] taped trigger kept its volatile context session=${turn.session.id}`);
- }
- return taped;
- };
const tapeMessage = async (message: unknown): Promise<void> => {
if (!turn.tape || tapeError) return;
const role = (message as { role?: string }).role;
@@ -1885,10 +1862,7 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {
const rec: NewTapeRecord = {
kind: "message",
harness: "pi",
- payload: stripImageBytes(
- isTrigger ? tapedTrigger(message) : message,
- isTrigger ? turn.images : undefined,
- ),
+ payload: stripImageBytes(message, isTrigger ? turn.images : undefined),
scopeLabel: resultScope ?? turn.scopeLabel,
...(isTrigger
? {
diff --git a/test/pi-harness-environment-notes.test.ts b/test/pi-harness-environment-notes.test.ts
deleted file mode 100644
index 72a579477..000000000
--- a/test/pi-harness-environment-notes.test.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import assert from "node:assert/strict";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
-import { test } from "node:test";
-import { stableCwd, withoutVolatileContext } from "../src/harness/pi-harness.ts";
-
-test("the cwd pi appends to the system prompt is one constant path per harness", () => {
- assert.equal(stableCwd("pi"), join(tmpdir(), "pi-cwd"));
- assert.equal(stableCwd("pi"), stableCwd("pi"));
-});
-
-const durable = "what's on today?\n\n<environment>\nThis message is from @alice.\n</environment>";
-const volatile = "<environment>\n## The user's local time\nMonday 9am\n</environment>";
-const sent = `${durable}\n\n${volatile}`;
-
-test("the taped trigger message keeps the durable note and drops the volatile one", () => {
- assert.deepEqual(withoutVolatileContext({ role: "user", content: sent }, sent, durable), {
- role: "user",
- content: durable,
- });
- const image = { type: "image", data: "abc", mimeType: "image/png" };
- assert.deepEqual(
- withoutVolatileContext({ role: "user", content: [{ type: "text", text: sent }, image] }, sent, durable),
- { role: "user", content: [{ type: "text", text: durable }, image] },
- );
-});
-
-test("messages that are not the trigger text, or would become empty, pass through by reference", () => {
- const other = { role: "user", content: "steer: stop" };
- assert.equal(withoutVolatileContext(other, sent, durable), other);
- const noVolatile = { role: "user", content: durable };
- assert.equal(withoutVolatileContext(noVolatile, durable, durable), noVolatile);
- const onlyVolatile = { role: "user", content: volatile };
- assert.equal(withoutVolatileContext(onlyVolatile, volatile, ""), onlyVolatile);
-});
diff --git a/test/pi-harness-freshness.test.ts b/test/pi-harness-freshness.test.ts
index be9cda2c2..b6eeed660 100644
--- a/test/pi-harness-freshness.test.ts
+++ b/test/pi-harness-freshness.test.ts
@@ -2,6 +2,7 @@ import { test } from "node:test";
import assert from "node:assert/strict";
import { readdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
+import { join } from "node:path";
import { countTokens } from "../src/util/tokens.ts";
import { createPiHarness, stableCwd } from "../src/harness/pi-harness.ts";
import type { HarnessTurnInput } from "../src/harness/harness.ts";
@@ -52,6 +53,11 @@ test("every turn composes the freshly resolved system prompt", async () => {
assert.equal(recorded[1]!.inputTokens, countTokens(second) + countTokens("hi"));
});
+test("the cwd pi appends to the system prompt is one constant path per harness", () => {
+ assert.equal(stableCwd("pi"), join(tmpdir(), "pi-cwd"));
+ assert.equal(stableCwd("pi"), stableCwd("pi"));
+});
+
test("each turn removes its agent directory and reuses one constant cwd", async () => {
const prefix = `pi-turn-${process.pid}`;
const harness = createPiHarness({ tempDirPrefix: prefix });
diff --git a/test/system-prompt-order.test.ts b/test/system-prompt-order.test.ts
index f3afa7b22..4c19c133c 100644
--- a/test/system-prompt-order.test.ts
+++ b/test/system-prompt-order.test.ts
@@ -18,7 +18,6 @@ import { createModelGateway } from "../src/model/model-gateway.ts";
import { createAuditLog } from "../src/audit/audit-log.ts";
import { createRateLimiter } from "../src/ratelimit/rate-limiter.ts";
import { createMockHarness } from "../src/harness/mock-harness.ts";
-import type { HarnessTurnInput } from "../src/harness/harness.ts";
import { createCronStore, type CronStore } from "../src/cron/cron-store.ts";
import { createDeployStore } from "../src/deploy/deploy-store.ts";
import { createDockerDeployProvider } from "../src/deploy/docker-deploy-provider.ts";
@@ -97,7 +96,6 @@ function buildOrchestrator(
skills?: SkillStore;
skillBundles?: SkillBundleStore;
securityScreener?: SecurityScreener;
- harness?: ReturnType<typeof createMockHarness>;
managedGroups?: Pick<ManagedGroupDirectory, "recognizes" | "members" | "version" | "withVersion" | "slackChannel">;
isCurrentSharedScopeMember?: IsCurrentSharedScopeMember;
} = {},
@@ -482,11 +480,7 @@ test("the system prompt is byte-identical across two turns a minute apart; the c
`"## ${title}" must not be in the system prompt`,
);
}
- assert.match(
- environmentOf(first.reply ?? ""),
- /<environment>\n## The user's local time/,
- "the clock opens its own environment note, separate from the durable per-message facts",
- );
+ assert.match(environmentOf(first.reply ?? ""), /## The user's local time/);
assert.notEqual(environmentOf(second.reply ?? ""), environmentOf(first.reply ?? ""), "the clock moved a minute");
assert.equal(
systemOf(second.reply ?? ""),
@@ -495,36 +489,6 @@ test("the system prompt is byte-identical across two turns a minute apart; the c
);
});
-test("the harness receives the clock and memory as volatile context; the durable note keeps the sender", async () => {
- const mock = createMockHarness();
- const received: HarnessTurnInput[] = [];
- const harness = {
- ...mock,
- turns: {
- ...mock.turns,
- runTurn: (turn: HarnessTurnInput) => {
- received.push(turn);
- return mock.turns.runTurn(turn);
- },
- },
- };
- const { orchestrator: orch, memory } = buildOrchestrator({ harness });
- await memory.replace(scopeId("personal", "U1"), "- remembers the chartreuse mug");
-
- const res = await orch.handleTurn(
- dm("dm:U1:volatile-split", "hello", {
- actor: { ...actor, displayName: "Alice" },
- timezone: "America/New_York",
- }),
- );
- assert.equal(res.status, "ok");
- const turn = received.at(-1)!;
- assert.match(turn.environment ?? "", /This message is from @Alice/);
- assert.doesNotMatch(turn.environment ?? "", /The user's local time|chartreuse/);
- assert.match(turn.volatileContext ?? "", /^<environment>\n## The user's local time/);
- assert.match(turn.volatileContext ?? "", /chartreuse/);
-});
-
test("the cached prefix survives skill-store reordering + a recordUse-style metadata update", async () => {
const mkSkill = (name: string, lastUsedAt?: number) => ({
skill: { manifest: { name, description: `does ${name}` }, lastUsedAt },