Skip to content

fix(langgraph): add retry for checkpoint write HTTP calls#1711

Merged
EItanya merged 1 commit into
kagent-dev:mainfrom
ningziwen:fix/checkpoint-write-retry
Apr 21, 2026
Merged

fix(langgraph): add retry for checkpoint write HTTP calls#1711
EItanya merged 1 commit into
kagent-dev:mainfrom
ningziwen:fix/checkpoint-write-retry

Conversation

@ningziwen

Copy link
Copy Markdown
Contributor

Motivation

The KAgentCheckpointer makes HTTP POST calls to the Go service to persist LangGraph checkpoints. These calls can fail transiently due to connection timeouts, network interruptions, or the Go service being briefly unavailable during rolling updates. When aput() or aput_writes() fails, LangGraph catches the exception internally and continues execution — the agent responds successfully but the checkpoint is silently lost, causing conversation history to be empty on subsequent reads.

Summary

Add 3-attempt retry with 500ms backoff and explicit 10s timeout to both aput() and aput_writes() in KAgentCheckpointer. If all attempts fail, the error is logged and re-raised so LangGraph can handle it.

Before

# Single HTTP call, no timeout, no retry
response = await self.client.post("/api/langgraph/checkpoints", ...)
response.raise_for_status()

Transient HTTP failure → checkpoint silently lost → GET /api/langgraph/checkpoints?thread_id=... returns empty → conversation history missing.

After

# 3 attempts with 500ms backoff, explicit 10s timeout
for attempt in range(3):
    try:
        response = await self.client.post(..., timeout=10.0)
        response.raise_for_status()
        break
    except Exception as e:
        logger.warning(f"Checkpoint write attempt {attempt+1}/3 failed: {e}")
        await asyncio.sleep(0.5)

Transient failures are retried automatically. Persistent failures are logged with full context before re-raising.

Reproducing steps (before fix)

  1. Deploy a BYO agent with the KAgent checkpointer
  2. Send a chat message via A2A — agent responds successfully
  3. Immediately query GET /api/langgraph/checkpoints?thread_id={session_id}&limit=1
  4. Intermittently returns empty data (~20% of the time under concurrent load)

After fix

Same steps — checkpoint is always present after chat completes.

Testing Plan

  • Existing unit tests pass
  • Manual testing: 10/10 checkpoint writes succeed under concurrent agent creation
  • Unit tests: retry on transient failure, raise after exhaustion, no retry on success
  • E2E test: create agent → chat → verify checkpoint exists

Copilot AI review requested due to automatic review settings April 20, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds retry + timeout handling to LangGraph checkpoint write paths to reduce silent checkpoint loss when transient HTTP failures occur between the Python LangGraph integration and the Go checkpoint service.

Changes:

  • Add 3-attempt retry loop with 500ms backoff and 10s request timeout for aput() and aput_writes() checkpoint POSTs.
  • Add unit tests covering success, retry-on-transient-failure, and exhaustion behavior for both write APIs.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
python/packages/kagent-langgraph/src/kagent/langgraph/_checkpointer.py Implements retry/backoff + per-request timeout for checkpoint and writes POST calls.
python/packages/kagent-langgraph/tests/test_checkpointer.py Adds unit tests validating retry behavior and failure propagation.
python/packages/kagent-langgraph/tests/init.py Test package marker (no functional changes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/packages/kagent-langgraph/src/kagent/langgraph/_checkpointer.py Outdated
Comment thread python/packages/kagent-langgraph/src/kagent/langgraph/_checkpointer.py Outdated
Comment thread python/packages/kagent-langgraph/src/kagent/langgraph/_checkpointer.py Outdated
@ningziwen ningziwen force-pushed the fix/checkpoint-write-retry branch from 2603075 to 4ad7fde Compare April 20, 2026 08:50
EItanya
EItanya previously approved these changes Apr 20, 2026
KAgentCheckpointer HTTP POST calls to persist checkpoints can fail
transiently during rolling updates or network interruptions. LangGraph
catches the exception internally, so the checkpoint is silently lost
and conversation history appears empty on subsequent reads.

Add 3-attempt retry with 500ms backoff and 10s timeout to aput() and
aput_writes(). Only transient errors (network failures, 5xx, 429) are
retried; client errors (4xx) and CancelledError propagate immediately.
Add unit tests for retry behavior.

Signed-off-by: Ziwen Ning <ziwen@ningziwen.com>
@EItanya EItanya merged commit 7516b4c into kagent-dev:main Apr 21, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants