Langgraph Postgres and Redis checkpointers break when running in CloudFlare Workers #358

Open
opened 2026-02-15 18:16:11 -05:00 by yindo · 0 comments
Owner

Originally created by @piraka9011 on GitHub (Sep 22, 2025).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).

Example Code

// worker/index.ts
import { PostgresSaver } from '@langchain/langgraph-checkpoint-postgres';
import { Annotation, END, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';

export default {
  async fetch(req): Promise<Response> {
    const DATABASE_URL = 'postgresql://postgres:postgres@localhost:5432/postgres';
    const GraphAnnotation = Annotation.Root({...MessagesAnnotation.spec});
    const checkpointer = PostgresSaver.fromConnString(DATABASE_URL);
    await checkpointer.setup();
    const workflow = new StateGraph(GraphAnnotation)
    const compiled = workflow.compile({ checkpointer: checkpointer });
  }
} satisfies ExportedHandler;

Error Message and Stack Trace (if applicable)

Error: The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response. Refer to: https://developers.cloudflare.com/workers/observability/errors/
    at async Object.fetch (file:///home/cloudflare-workers/node_modules/.pnpm/miniflare@4.20250823.1/node_modules/miniflare/dist/src/workers/core/entry.worker.js:4346:22)

Description

Hi! This isn't a bug in LangGraphJS directly, but the way the API is designed results in the following issue.

When using LangGraphJS with persistence (Postgres or Redis) in a CloudFlare Worker environment, the Worker runtime terminates requests because it notices that LG still needs to upload the persisted data to the database.
The workers SDK provides a ctx.waitUntil() method that "extends the lifetime of your Worker, allowing you to perform work without blocking returning a response, and that may continue after a response is returned."
However there is no API available in LG to tell the workers to wait until the persistence is complete.

Is there an API/method we can use to inform the Workers Runtime to wait until the persistence is complete, or any work around for this scenario? Thanks!

System Info

  • Package Info:
    • "@langchain/langgraph": "0.4.9",
    • "@langchain/langgraph-checkpoint-postgres": "0.1.2",
    • "@langchain/langgraph-checkpoint-redis": "0.0.1",
  • Platform: Linux
  • Node version: 22
  • Package Manager: pnpm 10.16.1
Originally created by @piraka9011 on GitHub (Sep 22, 2025). ### Checked other resources - [x] I added a very descriptive title to this issue. - [x] I searched the LangGraph.js documentation with the integrated search. - [x] I used the GitHub search to find a similar question and didn't find it. - [x] I am sure that this is a bug in LangGraph.js rather than my code. - [x] The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package). ### Example Code ```typescript // worker/index.ts import { PostgresSaver } from '@langchain/langgraph-checkpoint-postgres'; import { Annotation, END, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph'; export default { async fetch(req): Promise<Response> { const DATABASE_URL = 'postgresql://postgres:postgres@localhost:5432/postgres'; const GraphAnnotation = Annotation.Root({...MessagesAnnotation.spec}); const checkpointer = PostgresSaver.fromConnString(DATABASE_URL); await checkpointer.setup(); const workflow = new StateGraph(GraphAnnotation) const compiled = workflow.compile({ checkpointer: checkpointer }); } } satisfies ExportedHandler; ``` ### Error Message and Stack Trace (if applicable) ``` Error: The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response. Refer to: https://developers.cloudflare.com/workers/observability/errors/ at async Object.fetch (file:///home/cloudflare-workers/node_modules/.pnpm/miniflare@4.20250823.1/node_modules/miniflare/dist/src/workers/core/entry.worker.js:4346:22) ``` ### Description Hi! This isn't a bug in LangGraphJS directly, but the way the API is designed results in the following issue. When using LangGraphJS with persistence (Postgres or Redis) in a CloudFlare Worker environment, the Worker runtime terminates requests because it notices that LG still needs to upload the persisted data to the database. The workers SDK provides a [`ctx.waitUntil()`](https://developers.cloudflare.com/workers/runtime-apis/context/#waituntil) method that "extends the lifetime of your Worker, allowing you to perform work without blocking returning a response, and that may continue after a response is returned." However there is no API available in LG to tell the workers to wait until the persistence is complete. Is there an API/method we can use to inform the Workers Runtime to wait until the persistence is complete, or any work around for this scenario? Thanks! ### System Info * Package Info: * "@langchain/langgraph": "0.4.9", * "@langchain/langgraph-checkpoint-postgres": "0.1.2", * "@langchain/langgraph-checkpoint-redis": "0.0.1", * Platform: Linux * Node version: 22 * Package Manager: pnpm 10.16.1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#358