The Open Framework for Building Agents
fix(eve): drop removed state when adopting legacy handoff checkpoints (#4240)
Andrew Barbaf8ef817909e7
diff --git a/.changeset/legacy-state-drop-removed-keys.md b/.changeset/legacy-state-drop-removed-keys.mdnew file mode 100644index 000000000..511ddbf33--- /dev/null+++ b/.changeset/legacy-state-drop-removed-keys.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Sessions from eve 0.68 and earlier now hand off to a newer deployment even when the agent or one of its extensions has since removed a `defineState` key. The removed state is dropped with a warning instead of keeping the session on its old deployment.diff --git a/docs/concepts/execution-model-and-durability.mdx b/docs/concepts/execution-model-and-durability.mdxindex f8a14007e..ecb26ba81 100644--- a/docs/concepts/execution-model-and-durability.mdx+++ b/docs/concepts/execution-model-and-durability.mdx@@ -25,7 +25,7 @@ The Workflow SDK is not inherently tied to Vercel. In local development and in aWhen a Vercel production deployment changes, a new delivery to an idle session hands the session's settled state to the exact deployment that accepted the request. This applies whether the delivery arrives through the session ID or through any channel continuation address the session has claimed. The session keeps its original ID and event stream, while the next model turn uses that deployment's current system-role instructions, model, and tools. Static user-role instructions stay pinned in the durable conversation history and are not seeded again. A successful handoff restarts the session's original configured [`sessionTimeoutMs`](../agent-config#runtime-limits) duration; disabled timeouts stay disabled. Failed or skipped handoffs keep the existing deadline.-Before taking ownership, the target deployment upgrades the checkpoint when an older eve release wrote it, then checks that no pending work remains. A deployment accepts checkpoints from eve 0.66.0 and later, so upgrading eve does not leave long-lived sessions, such as a Slack thread, on their old deployment. An older release cannot read a newer checkpoint: after a rollback, a session that already moved to the newer deployment stays there. Extension state saved before eve 0.69 moves to its mount when exactly one mount uses that extension package and the extension still defines that state. Otherwise eve cannot choose an owner, and the session stays on its current deployment. Idle subagent sessions that eve 0.66–0.68 kept for later reuse are stopped after the handoff. Authored session state remains opaque to this validation.+Before taking ownership, the target deployment upgrades the checkpoint when an older eve release wrote it, then checks that no pending work remains. A deployment accepts checkpoints from eve 0.66.0 and later, so upgrading eve does not leave long-lived sessions, such as a Slack thread, on their old deployment. An older release cannot read a newer checkpoint: after a rollback, a session that already moved to the newer deployment stays there. Extension state saved before eve 0.69 moves to its mount when exactly one mount of that extension package defines that state. State that the target deployment no longer defines, such as a removed `defineState` key, is dropped, and the target deployment's runtime logs show a `dropping unknown context key during deserialization` warning. When two or more mounts of one extension package define that state, eve cannot choose an owner, and the session stays on its current deployment. Idle subagent sessions that eve 0.66–0.68 kept for later reuse are stopped after the handoff. Authored session state remains opaque to this validation.If the target deployment rejects the session, the previous owner keeps it and processes the triggering delivery. When the target deployment cannot read the checkpoint, its Vercel runtime logs show a `session handoff refused` warning with the checkpoint version and the reason. Owners on this release or later also write a `session handoff failed` warning to their own runtime logs, with the target deployment and the reason.diff --git a/docs/extensions.md b/docs/extensions.mdindex 825e95f17..bc5dcf447 100644--- a/docs/extensions.md+++ b/docs/extensions.md@@ -210,11 +210,13 @@ Extension state belongs to the logical mount path (for example, `extensions/crm`### Upgrade from package-scoped extension state-Deployments before eve 0.69 stored extension state under package-prefixed keys, such as `acme-crm.requests`. When a session from one of those deployments hands off to a newer deployment, eve moves each package-prefixed value to the mount that uses that package. eve never resets that state during restore.+Deployments before eve 0.69 stored extension state under package-prefixed keys, such as `acme-crm.requests`. When a session from one of those deployments hands off to a newer deployment, eve moves each package-prefixed value to the mount that uses that package.-- The value moves only when exactly one mount uses the package and the extension still defines that state name. Otherwise eve cannot tell which mount owns the value, so the handoff is rejected and the session stays on its current deployment. Keep that deployment available until the session finishes, or start a new session on the deployment you want to use.+- The value moves when exactly one mount of that package defines that state name.+- When no mount of that package defines that state name, for example because the extension removed it or the package was renamed, eve drops the value. The target deployment's runtime logs show a `dropping unknown context key during deserialization` warning with the key.+- When two or more mounts use the package and define that state name, eve cannot tell which mount owns the value, so the handoff is rejected and the session stays on its current deployment. Keep that deployment available until the session finishes, or start a new session on the deployment you want to use.- Older deployments cannot read sessions saved by a newer release, so a session that already moved does not hand back after a rollback.-- Local context snapshots follow the same rule: an older snapshot restores when every saved state key still has an owner.+- Local context snapshots follow the same rules.### Use an extension in a workspacediff --git a/packages/eve/src/context/serialize.test.ts b/packages/eve/src/context/serialize.test.tsindex 0e7fc0de6..9de76a155 100644--- a/packages/eve/src/context/serialize.test.ts+++ b/packages/eve/src/context/serialize.test.ts@@ -35,65 +35,66 @@ describe("deserializeContext", () => {});describe("state layout admission", () => {- it("rejects unmarked legacy keys before dropping their values", async () => {- const { manifest } = await compileFromMemory({ model: "openai/gpt-5.4" });+ it("rejects reserved mount names in an unmarked legacy context", async () => {const bundle = { compiledArtifactsSource: { kind: "bundled" } } as CompiledBundle;const deserialize = vi.spyOn(BundleKey.codec!, "deserialize").mockResolvedValue(bundle);- const loadManifest = vi- .spyOn(manifestLoader, "loadCompiledManifest")- .mockResolvedValue(manifest);try {- await expect(- deserializeContext({ "eve.bundle": {}, "acme-crm.requests": 4 }),- ).rejects.toThrow("Incompatible context state layout");// Registration in a previous graph must not turn a reserved legacy authored name// into proof that it belongs to the new layout.- new ContextKey("eve:mount.v1:extensions%2Fcrm:requests");+ new ContextKey("eve:mount.v1:extensions%2Freserved:requests");await expect(deserializeContext({"eve.bundle": {},- "eve:mount.v1:extensions%2Fcrm:requests": 4,+ "eve:mount.v1:extensions%2Freserved:requests": 4,}),).rejects.toThrow("Incompatible context state layout");} finally {deserialize.mockRestore();- loadManifest.mockRestore();}});- it("moves legacy extension state to the one mount that owns its package", async () => {+ it("moves legacy extension state to the one mount that still defines it", async () => {const { manifest } = await compileFromMemory({ model: "openai/gpt-5.4" });const bundle = { compiledArtifactsSource: { kind: "bundled" } } as CompiledBundle;+ const mount = (mountId: string) =>+ ({ mountId, packageName: "@acme/crm" }) as (typeof manifest.extensionMounts)[number];+ let mounts = [mount("extensions/crm")];const deserialize = vi.spyOn(BundleKey.codec!, "deserialize").mockImplementation(async () => {- defineMountedState("extensions/crm", "requests", () => 0);+ for (const { mountId } of mounts) defineMountedState(mountId, "requests", () => 0);return bundle;});- const mount = (mountId: string) =>- ({ mountId, packageName: "@acme/crm" }) as (typeof manifest.extensionMounts)[number];const loadManifest = vi.spyOn(manifestLoader, "loadCompiledManifest")- .mockResolvedValue({ ...manifest, extensionMounts: [mount("extensions/crm")] });+ .mockImplementation(async () => ({ ...manifest, extensionMounts: mounts }));+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});try {- expect((await deserializeContext({ "eve.bundle": {} })).get(BundleKey)).toBe(bundle);- const restored = await deserializeContext({ "eve.bundle": {}, "acme-crm.requests": 4 });- expect(- [...restored.entries()].map(([key, value]) => [key.name, value]).filter(([, v]) => v === 4),- ).toEqual([["eve:mount.v1:extensions%2Fcrm:requests", 4]]);- // Two mounts of one package shared the legacy key, so neither can claim it.- loadManifest.mockResolvedValue({- ...manifest,- extensionMounts: [mount("extensions/crm"), mount("extensions/crm-eu")],+ const restored = await deserializeContext({+ "eve.bundle": {},+ "acme-crm.history": 5,+ "acme-crm.requests": 4,});+ // The extension no longer defines `history`, so that value is dropped.+ expect([...restored.entries()].map(([key, value]) => [key.name, value])).toEqual([+ ["eve.bundle", bundle],+ ["eve:mount.v1:extensions%2Fcrm:requests", 4],+ ]);+ expect(warn).toHaveBeenCalledWith(+ expect.stringContaining("dropping unknown context key"),+ expect.objectContaining({ key: "acme-crm.history" }),+ );+ // Two mounts of one package define the legacy key, so neither can claim it.+ mounts = [mount("extensions/crm"), mount("extensions/crm-eu")];await expect(deserializeContext({ "eve.bundle": {}, "acme-crm.requests": 4 }),).rejects.toThrow('Incompatible context state layout for key "acme-crm.requests"');} finally {deserialize.mockRestore();loadManifest.mockRestore();+ warn.mockRestore();}});- it("preserves unchanged application state regardless of prior module registrations", async () => {+ it("drops removed legacy application state but refuses unknown framework state", async () => {const { manifest } = await compileFromMemory({ model: "openai/gpt-5.4" });const bundle = { compiledArtifactsSource: { kind: "bundled" } } as CompiledBundle;const name = "test.legacy.app-owned";@@ -104,17 +105,26 @@ describe("state layout admission", () => {const loadManifest = vi.spyOn(manifestLoader, "loadCompiledManifest").mockResolvedValue(manifest);+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});try {- const restored = await deserializeContext({ "eve.bundle": {}, [name]: 4 });+ const restored = await deserializeContext({+ "eve.bundle": {},+ [name]: 4,+ "test.legacy.removed": { phase: "none" },+ });expect(restored.get(BundleKey)).toBe(bundle);- // The registered key is retained; an unregistered name still refuses the restore.- expect([...restored.entries()].map(([key]) => key.name)).toContain(name);+ expect([...restored.entries()].map(([key]) => key.name)).toEqual(["eve.bundle", name]);+ expect(warn).toHaveBeenCalledWith(+ expect.stringContaining("dropping unknown context key"),+ expect.objectContaining({ key: "test.legacy.removed" }),+ );await expect(- deserializeContext({ "eve.bundle": {}, "test.legacy.unknown": 4 }),- ).rejects.toThrow("Incompatible context state layout");+ deserializeContext({ "eve.bundle": {}, "eve.unmigrated": "none" }),+ ).rejects.toThrow('Incompatible context state layout for key "eve.unmigrated"');} finally {deserialize.mockRestore();loadManifest.mockRestore();+ warn.mockRestore();}});diff --git a/packages/eve/src/context/serialize.ts b/packages/eve/src/context/serialize.tsindex 56929f189..b1dfad849 100644--- a/packages/eve/src/context/serialize.ts+++ b/packages/eve/src/context/serialize.ts@@ -87,9 +87,10 @@ export async function deserializeContext(}/**- * Admits a context written before mount-scoped state (eve 0.68 and earlier)- * only when every value keeps an owner in this deployment. Extension state- * moves to its mount's key when exactly one mount uses its package namespace.+ * Admits a context written before mount-scoped state (eve 0.68 and earlier).+ * Extension state moves to the one mount that still defines it. Authored state+ * nothing defines was removed, so the loader drops it as in the current layout.+ * State that several mounts define refuses rather than guessing an owner.*/async function adoptLegacyStateLayout(data: Record<string, unknown>,@@ -110,20 +111,16 @@ async function adoptLegacyStateLayout(}const owners = mounts.flatMap((mount) => {const prefix = `${legacyPackageStateNamespace(mount.packageName)}.`;- return name.startsWith(prefix)- ? [mountedStateKeyName(mount.mountId, name.slice(prefix.length))]- : [];+ if (!name.startsWith(prefix)) return [];+ const mounted = mountedStateKeyName(mount.mountId, name.slice(prefix.length));+ return resolveKey(mounted) === undefined ? [] : [mounted];});- const [mounted] = owners;- if (- owners.length !== 1 ||- mounted === undefined ||- resolveKey(mounted) === undefined ||- data[mounted] !== undefined- ) {+ // Authored state cannot use `eve.`, so an unknown framework key means a+ // checkpoint migration missed it.+ if (owners.length > 1 || (owners.length === 0 && name.startsWith("eve."))) {throw new IncompatibleStateLayoutError(name);}- adopted[mounted] = value;+ adopted[owners[0] ?? name] = value;}return adopted;}@@ -142,7 +139,7 @@ function legacyPackageStateNamespace(packageName: string): string {export class IncompatibleStateLayoutError extends Error {constructor(key?: string) {super(- `Incompatible context state layout${key === undefined ? "" : ` for key "${key}"`}. Restore this session with its original deployment or start a new session; state with no unambiguous owner in this deployment cannot be carried forward.`,+ `Incompatible context state layout${key === undefined ? "" : ` for key "${key}"`}. This deployment cannot read the saved state. Continue this session on its original deployment or start a new session.`,);this.name = "IncompatibleStateLayoutError";}