Skip to content

Commit

Permalink
Refactor task execution, fix pending writes and resuming from error s…
Browse files Browse the repository at this point in the history
…tate
  • Loading branch information
jacoblee93 committed Aug 22, 2024
1 parent a226918 commit a93ed61
Show file tree
Hide file tree
Showing 9 changed files with 384 additions and 239 deletions.
15 changes: 0 additions & 15 deletions langgraph/src/checkpoint/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ export interface ReadonlyCheckpoint extends Readonly<Checkpoint> {
>;
}

export function getChannelVersion(
checkpoint: ReadonlyCheckpoint,
channel: string
): number {
return checkpoint.channel_versions[channel] ?? 0;
}

export function getVersionSeen(
checkpoint: ReadonlyCheckpoint,
node: string,
channel: string
): number {
return checkpoint.versions_seen[node]?.[channel] ?? 0;
}

export function deepCopy<T>(obj: T): T {
if (typeof obj !== "object" || obj === null) {
return obj;
Expand Down
9 changes: 5 additions & 4 deletions langgraph/src/checkpoint/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MemorySaver extends BaseCheckpointSaver {
async getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined> {
const thread_id = config.configurable?.thread_id;
const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
const checkpoint_id = config.configurable?.checkpoint_id;
let checkpoint_id = config.configurable?.checkpoint_id;

if (checkpoint_id) {
const saved = this.storage[thread_id]?.[checkpoint_ns]?.[checkpoint_id];
Expand Down Expand Up @@ -71,10 +71,11 @@ export class MemorySaver extends BaseCheckpointSaver {
} else {
const checkpoints = this.storage[thread_id]?.[checkpoint_ns];
if (checkpoints !== undefined) {
const maxThreadTs = Object.keys(checkpoints).sort((a, b) =>
// eslint-disable-next-line prefer-destructuring
checkpoint_id = Object.keys(checkpoints).sort((a, b) =>
b.localeCompare(a)
)[0];
const saved = checkpoints[maxThreadTs];
const saved = checkpoints[checkpoint_id];
const [checkpoint, metadata, parentCheckpointId] = saved;
const writes =
this.writes[_generateKey(thread_id, checkpoint_ns, checkpoint_id)] ??
Expand All @@ -98,7 +99,7 @@ export class MemorySaver extends BaseCheckpointSaver {
config: {
configurable: {
thread_id,
checkpoint_id: maxThreadTs,
checkpoint_id,
checkpoint_ns,
},
},
Expand Down
Loading

0 comments on commit a93ed61

Please sign in to comment.