fix(core): hide instruction updates a revert left behind (#63667)

This commit is contained in:
Aiden Cline
2026-11-13 00:07:59 -06:00
committed by GitHub
Unverified
parent e36f0c8fda
commit b645291e9c
3 changed files with 40 additions and 1 deletions
+6 -1
View File
@@ -226,10 +226,15 @@ const messageEntries = Effect.fnUntraced(function* (
// epoch: the baseline supersedes the chronological updates before it. Forks seed their baseline
// at sequence 0 but retain parent sequences, so the copied checkpoint still retires them.
const native = entries.findLast((entry) => isNativeCompaction(entry.message))
// The instruction baseline covers every update before its epoch. A committed revert that removes an
// update clears the state, so the next baseline is rendered fresh and covers every surviving update.
const epoch = (yield* InstructionState.epochStart(db, sessionID)) ?? Number.POSITIVE_INFINITY
// Skipped native checkpoints are not textual summaries. Their original transcript remains available.
return entries.filter(
(entry) =>
!(entry.message.type === "system" && native && entry.seq < native.seq) && replayable(entry.message, boundary),
!(entry.message.type === "system" && native && entry.seq < native.seq) &&
!(entry.message.type === "system" && entry.message.metadata?.notice === "instructions" && entry.seq < epoch) &&
replayable(entry.message, boundary),
)
})
@@ -176,6 +176,14 @@ export const current = Effect.fn("InstructionState.current")(function* (
return (yield* find(db, sessionID))?.current_values
})
/** Where the current baseline starts; updates before it are already folded into the baseline. */
export const epochStart = Effect.fn("InstructionState.epochStart")(function* (
db: DatabaseService,
sessionID: SessionSchema.ID,
) {
return (yield* find(db, sessionID))?.epoch_start
})
export const preview = Effect.fn("InstructionState.preview")(function* (
db: DatabaseService,
sessionID: SessionSchema.ID,
+26
View File
@@ -2059,6 +2059,32 @@ describe("SessionRunnerLLM", () => {
yield* s.runPrompt("Fourth")
expect(s.requests.at(-1)?.system.map((part) => part.text)).toEqual([defaultSystem, fakeIdentity, "Latest context"])
// The surviving "Changed context" update predates the fresh baseline and would contradict it.
expect(messageRoles(s.requests.at(-1))).toEqual(["user", "user"])
expect((yield* s.context).some((message) => message.type === "system")).toBe(false)
})
scenario("hides an update a revert left behind once the source is removed", function* (s) {
s.systemRemoved = true
yield* s.runPrompt("First")
s.systemRemoved = false
s.systemBaseline = "Entered mode"
const second = yield* s.runPrompt("Second")
s.systemRemoved = true
yield* s.runPrompt("Third")
// The removal is delivered with "Third"; the "Entered mode" update survives before "Second".
yield* s.bus.publish(SessionEvent.RevertEvent.Committed, { sessionID, to: second.id })
yield* s.runPrompt("Fourth")
const last = s.requests.at(-1)!
expect(systemTexts(last)).toEqual([])
expect(userTexts(last)).toEqual(["First", "Fourth"])
expect(last.system.map((part) => part.text).join("\n")).not.toContain("Entered mode")
// Clients still see every message; only the model context hides the stale update.
expect((yield* s.messages).filter((message) => message.type === "system")).toMatchObject([
{ text: "Entered mode" },
])
})
scenario("uses the selected model family prompt when the agent does not override it", function* (s) {