Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checkpoint-sqlite): don't return undefined namespace from put #634

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions libs/checkpoint-sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,14 @@ CREATE TABLE IF NOT EXISTS writes (
throw new Error("Empty configuration supplied.");
}

if (!config.configurable?.thread_id) {
throw new Error("Missing thread_id field in config.configurable.");
const thread_id = config.configurable?.thread_id;
const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
const parent_checkpoint_id = config.configurable?.checkpoint_id;

if (!thread_id) {
throw new Error(
`Missing "thread_id" field in passed "config.configurable".`
);
}

const preparedCheckpoint: Partial<Checkpoint> = copyCheckpoint(checkpoint);
Expand All @@ -417,10 +423,10 @@ CREATE TABLE IF NOT EXISTS writes (
);
}
const row = [
config.configurable?.thread_id?.toString(),
config.configurable?.checkpoint_ns,
thread_id,
checkpoint_ns,
checkpoint.id,
config.configurable?.checkpoint_id,
parent_checkpoint_id,
type1,
serializedCheckpoint,
serializedMetadata,
Expand All @@ -434,8 +440,8 @@ CREATE TABLE IF NOT EXISTS writes (

return {
configurable: {
thread_id: config.configurable?.thread_id,
checkpoint_ns: config.configurable?.checkpoint_ns,
thread_id,
checkpoint_ns,
checkpoint_id: checkpoint.id,
},
};
Expand Down
1 change: 1 addition & 0 deletions libs/checkpoint-sqlite/src/tests/checkpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe("SqliteSaver", () => {
expect(runnableConfig).toEqual({
configurable: {
thread_id: "1",
checkpoint_ns: "",
checkpoint_id: checkpoint1.id,
},
});
Expand Down
52 changes: 22 additions & 30 deletions libs/checkpoint-validation/src/spec/put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,37 +177,29 @@ export function putTests<T extends BaseCheckpointSaver>(
});
});

it_skipForSomeModules(initializer.checkpointerName, {
// TODO: SqliteSaver stores with undefined namespace instead of empty namespace
// see: https://github.com/langchain-ai/langgraphjs/issues/592
"@langchain/langgraph-checkpoint-sqlite":
"TODO: SqliteSaver stores config with no checkpoint_ns instead of default namespace",
})(
"should default to empty namespace if the checkpoint namespace is missing from config.configurable",
async () => {
const missingNamespaceConfig: RunnableConfig = {
configurable: { thread_id },
};

const { checkpoint, metadata } = initialCheckpointTuple({
thread_id,
checkpoint_id: checkpoint_id1,
checkpoint_ns: "",
});
it("should default to empty namespace if the checkpoint namespace is missing from config.configurable", async () => {
const missingNamespaceConfig: RunnableConfig = {
configurable: { thread_id },
};

const { checkpoint, metadata } = initialCheckpointTuple({
thread_id,
checkpoint_id: checkpoint_id1,
checkpoint_ns: "",
});

const returnedConfig = await checkpointer.put(
missingNamespaceConfig,
checkpoint,
metadata!,
{}
);

expect(returnedConfig).not.toBeUndefined();
expect(returnedConfig?.configurable).not.toBeUndefined();
expect(returnedConfig?.configurable?.checkpoint_ns).not.toBeUndefined();
expect(returnedConfig?.configurable?.checkpoint_ns).toEqual("");
}
);
const returnedConfig = await checkpointer.put(
missingNamespaceConfig,
checkpoint,
metadata!,
{}
);

expect(returnedConfig).not.toBeUndefined();
expect(returnedConfig?.configurable).not.toBeUndefined();
expect(returnedConfig?.configurable?.checkpoint_ns).not.toBeUndefined();
expect(returnedConfig?.configurable?.checkpoint_ns).toEqual("");
});

it_skipForSomeModules(initializer.checkpointerName, {
// TODO: all of the checkpointers below store full channel_values on every put, rather than storing deltas
Expand Down
Loading