Skip to content
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: 9 additions & 11 deletions langgraph/src/channels/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ export async function createCheckpoint<Value>(
channelVersions: { ...checkpoint.channelVersions },
versionsSeen: { ...checkpoint.versionsSeen },
};
for (const k in channels) {
if (newCheckpoint.channelValues[k] === undefined) {
try {
newCheckpoint.channelValues[k] = await channels[k].checkpoint();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if ("name" in error && error.name === EmptyChannelError.name) {
// no-op
} else {
throw error; // Rethrow unexpected errors
}
for (const k of Object.keys(channels)) {
try {
newCheckpoint.channelValues[k] = await channels[k].checkpoint();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.name === EmptyChannelError.name) {
// no-op
} else {
throw error; // Rethrow unexpected errors
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions langgraph/src/channels/binop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ export class BinaryOperatorAggregate<Value> extends BaseChannel<
this.value = initialValueFactory?.();
}

public empty(_?: Value): BinaryOperatorAggregate<Value> {
public empty(checkpoint?: Value): BinaryOperatorAggregate<Value> {
const empty = new BinaryOperatorAggregate(
this.operator,
this.initialValueFactory
);
if (checkpoint) {
empty.value = checkpoint;
}
return empty;
}

Expand Down Expand Up @@ -61,7 +64,7 @@ export class BinaryOperatorAggregate<Value> extends BaseChannel<
}

public checkpoint(): Value {
if (!this.value) {
if (this.value === undefined) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for consistency with the rest of the file

throw new EmptyChannelError();
}
return this.value;
Expand Down
2 changes: 1 addition & 1 deletion langgraph/src/tests/pregel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ it("should process two inputs to two outputs validly", async () => {
expect(await app.invoke(2)).toEqual([3, 3]);
});

it.skip("should handle checkpoints correctly", async () => {
it("should handle checkpoints correctly", async () => {
const addOne = jest.fn(
(x: { total: number; input: number }): number => x.total + x.input
);
Expand Down