Skip to content

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

Rust

test(coding-agent): pin the RSI review findings within the test-line budget (#2501)

Sebastian Müller238a3610f062
diff --git a/packages/coding-agent/test/daemon-supervisor-monitor.test.ts b/packages/coding-agent/test/daemon-supervisor-monitor.test.ts
index db31629250..7598fbbcb5 100644
--- a/packages/coding-agent/test/daemon-supervisor-monitor.test.ts
+++ b/packages/coding-agent/test/daemon-supervisor-monitor.test.ts
@@ -4235,7 +4235,7 @@ describe("daemon worker supervisor monitoring", () => {
return { supervisor, log };
}
- it("marks each busy worker session interrupted independently", async () => {
+ it("marks each busy worker session interrupted independently, even when one notice is refused", async () => {
// A stale pid whose journaled start id no longer matches is left alone.
const { root, worker } = recoveryFixture({
sessions: [
@@ -4244,7 +4244,7 @@ describe("daemon worker supervisor monitoring", () => {
],
orphan: { pid: 987_654, processStartId: "reused-process" },
});
- const markInterrupted = vi.fn(async () => undefined);
+ const markInterrupted = vi.fn().mockRejectedValueOnce(new Error("session file is gone"));
const kill = vi.spyOn(process, "kill").mockReturnValue(true);
const { supervisor } = recoverySupervisor(worker, { markInterrupted });
diff --git a/packages/coding-agent/test/session-manager/file-operations.test.ts b/packages/coding-agent/test/session-manager/file-operations.test.ts
index 81499c3af9..634e7ab292 100644
--- a/packages/coding-agent/test/session-manager/file-operations.test.ts
+++ b/packages/coding-agent/test/session-manager/file-operations.test.ts
@@ -818,8 +818,8 @@ describe("readSessionInfo incremental scans", () => {
])("counts %s from its header", async (_case, body, messageCount, allMessagesText) => {
expect(await scan(body)).toMatchObject({ messageCount, allMessagesText });
});
- it("drops a damaged session whose first entry is a tool result", async () => {
- expect(await scan(tool())).toBeNull();
+ it("drops a damaged session whose first entry is a tool result, even when a header follows", async () => {
+ expect(await scan(line(msg("t1", null, "toolResult", "x")) + line(header))).toBeNull();
expect(await SessionManager.listAll(undefined, tempDir)).toEqual([]);
});
});
diff --git a/packages/coding-agent/test/session-manager/leaf-branch-cache.test.ts b/packages/coding-agent/test/session-manager/leaf-branch-cache.test.ts
index 4163038a8c..0968c1618a 100644
--- a/packages/coding-agent/test/session-manager/leaf-branch-cache.test.ts
+++ b/packages/coding-agent/test/session-manager/leaf-branch-cache.test.ts
@@ -112,24 +112,7 @@ describe("SessionManager leaf branch cache", () => {
expectChainMatches(session, [firstId, secondId, thirdId, fourthId, fifthId]);
});
- it("drops the cached branch when a failed append is rolled back", () => {
- const session = persistedSession();
- const firstId = session.appendMessage(userMsg("one"));
- expect(ids(session)).toEqual([firstId]); // populates the cache
-
- vi.spyOn(session, "_persist").mockImplementationOnce(() => {
- throw new Error("disk full");
- });
- expect(() => session.appendCustomMessageEntryWithRollback("note", "unsaved", false)).toThrow("disk full");
-
- expect(session.getLeafId()).toBe(firstId);
- expectChainMatches(session, [firstId]);
- // The next append starts from the rolled-back leaf and stays coherent.
- const secondId = session.appendCustomMessageEntry("note", "saved", false);
- expectChainMatches(session, [firstId, secondId]);
- });
-
- it("never leaves a rolled-back append in a branch array a caller already holds", () => {
+ it("rolls a failed append back out of a held branch array and recovers on the next append and reload", () => {
const session = persistedSession();
const firstId = session.appendMessage(userMsg("one"));
const held = session.getBranch(); // the live cached array
@@ -154,5 +137,11 @@ describe("SessionManager leaf branch cache", () => {
expect(heldAgain.map((entry) => entry.id)).toEqual([firstId]);
expectChainMatches(session, [firstId]);
+
+ // The next append starts from the rolled-back leaf and stays coherent (its assistant entry also writes the file).
+ const secondId = session.appendMessage(assistantMsg("two"));
+ expectChainMatches(session, [firstId, secondId]);
+ session.setSessionFile(session.getSessionFile()!); // same path, same leaf id, fresh entry objects
+ expectChainMatches(session, [firstId, secondId]); // the served objects are the reloaded ones
});
});
diff --git a/packages/coding-agent/test/suite/agent-session-prompt.test.ts b/packages/coding-agent/test/suite/agent-session-prompt.test.ts
index e421455026..156e023e9f 100644
--- a/packages/coding-agent/test/suite/agent-session-prompt.test.ts
+++ b/packages/coding-agent/test/suite/agent-session-prompt.test.ts
@@ -914,6 +914,8 @@ describe("Harness digest at cold boundaries", () => {
);
}
+ type DigestPeek = { _harnessDigestWithFingerprint(): { digest: string } };
+
it("keeps untouched sessions empty and injects the digest at the first committed turn", async () => {
const harness = await createHarness({ persistSession: true });
harnesses.push(harness);
@@ -1038,7 +1040,7 @@ describe("Harness digest at cold boundaries", () => {
expect(digest).not.toContain("one string");
});
- it("skips digest re-delivery on resume when only query terms drifted and the state is unchanged", async () => {
+ it("keeps one digest block across resumes and compaction: fingerprint dedupe, replaced on state change", async () => {
// Hermetic store: the ambient developer harness would crowd the ranked window.
isolatedAgentDir("pi-digest-resume");
const harness = await createHarness({ persistSession: true });
@@ -1072,35 +1074,39 @@ describe("Harness digest at cold boundaries", () => {
const after = digestMessages(resumed);
expect(after).toHaveLength(1);
expect(getMessageText(after[0])).toBe(digestTextBefore);
- const freshDigest = (
- resumed.session as unknown as {
- _harnessDigestWithFingerprint(): { digest: string; stateFingerprint: string };
- }
- )._harnessDigestWithFingerprint().digest;
+ const freshDigest = (resumed.session as unknown as DigestPeek)._harnessDigestWithFingerprint().digest;
expect(HARNESS_DIGEST_PREFIX + freshDigest + HARNESS_DIGEST_SUFFIX).not.toBe(getMessageText(after[0]));
resumed.session.dispose();
- });
-
- it("appends a fresh digest on resume after disk state changed, replacing the old copy", async () => {
- // Empty global store: digest content must reflect only the local test entry.
- // The unchanged-disk resume dedupe is pinned by the fingerprint test above.
- isolatedAgentDir("pi-digest-agent");
- const harness = await createHarness({ persistSession: true });
- harnesses.push(harness);
- harness.setResponses([fauxAssistantMessage("hi")]);
- await harness.session.prompt("hello");
- const sessionFile = harness.sessionManager.getSessionFile();
- harness.session.dispose();
- const localDir = getLocalHarnessStateDir(harness.sessionManager.getSessionArtifactDir());
- const state = loadHarnessState(localDir, "local");
+ // Changed disk state: the fresh digest replaces the stale copy instead of stacking.
seedMemory(state, "resume_test_memory", "Resume test memory", "Written between resumes.");
saveHarnessState(localDir!, state);
-
- const resumedStale = await createHarness({ existingSessionFile: sessionFile });
- harnesses.push(resumedStale);
- const digests = digestMessages(resumedStale);
- expect(digests).toHaveLength(1); // the fresh digest replaced the stale copy instead of stacking
+ const settings = { compaction: { keepRecentTokens: 1 } }; // lets compact() below cut at the last reply
+ const refreshed = await createHarness({ existingSessionFile: sessionFile, settings });
+ harnesses.push(refreshed);
+ const digests = digestMessages(refreshed);
+ expect(digests).toHaveLength(1);
expect(getMessageText(digests[0])).toContain("[local:resume_test_memory] Resume test memory");
+
+ // Compaction moves the digest and its fingerprint onto the summary head. Only "ack" stays
+ // in context, so the next resume's render drifts again and only the fingerprint can dedupe.
+ refreshed.setResponses([fauxAssistantMessage("summary"), fauxAssistantMessage("turn summary")]);
+ await refreshed.session.compact();
+ const snapshot = (refreshed.session.messages[0] as { harnessDigest?: string }).harnessDigest;
+ refreshed.session.dispose();
+ const compacted = await createHarness({ existingSessionFile: sessionFile });
+ harnesses.push(compacted);
+ expect(digestMessages(compacted)).toHaveLength(0);
+ expect(compacted.session.messages[0]).toMatchObject({ role: "compactionSummary", harnessDigest: snapshot });
+ expect((compacted.session as unknown as DigestPeek)._harnessDigestWithFingerprint().digest).not.toBe(snapshot);
+
+ // Changed disk state after compaction: the fresh digest replaces the snapshot instead of stacking on it.
+ seedMemory(state, "late_note", "Late note", "Written after compaction.");
+ saveHarnessState(localDir!, state);
+ compacted.session.dispose();
+ const replaced = await createHarness({ existingSessionFile: sessionFile });
+ harnesses.push(replaced);
+ expect(digestMessages(replaced)).toHaveLength(1);
+ expect(replaced.session.messages[0]).toMatchObject({ role: "compactionSummary", harnessDigest: undefined });
});
});