perf(langgraph): short-circuit interrupt detection to speed up tick (#1624)

This commit is contained in:
David Duong
2025-09-09 15:44:39 +02:00
committed by GitHub
parent 27934c0535
commit a527fc7aeb
2 changed files with 22 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---
Improve tick performance by detecting interrupts faster within a tick.
+17 -8
View File
@@ -54,6 +54,7 @@ import {
PREVIOUS,
CACHE_NS_WRITES,
CONFIG_KEY_RESUME_MAP,
START,
} from "../constants.js";
import {
Call,
@@ -116,15 +117,23 @@ export function shouldInterrupt<N extends PropertyKey, C extends PropertyKey>(
const seen = checkpoint.versions_seen[INTERRUPT] ?? {};
let anyChannelUpdated = false;
for (const chan in checkpoint.channel_versions) {
if (
!Object.prototype.hasOwnProperty.call(checkpoint.channel_versions, chan)
)
continue;
if (checkpoint.channel_versions[chan] > (seen[chan] ?? nullVersion)) {
anyChannelUpdated = true;
break;
if (
(checkpoint.channel_versions[START] ?? nullVersion) >
(seen[START] ?? nullVersion)
) {
anyChannelUpdated = true;
} else {
for (const chan in checkpoint.channel_versions) {
if (
!Object.prototype.hasOwnProperty.call(checkpoint.channel_versions, chan)
)
continue;
if (checkpoint.channel_versions[chan] > (seen[chan] ?? nullVersion)) {
anyChannelUpdated = true;
break;
}
}
}