Skip to content

fix(graph): make PostgresSaver latest checkpoint deterministic#4753

Open
GaoSSR wants to merge 1 commit into
alibaba:mainfrom
GaoSSR:fix-postgres-checkpoint-sequence
Open

fix(graph): make PostgresSaver latest checkpoint deterministic#4753
GaoSSR wants to merge 1 commit into
alibaba:mainfrom
GaoSSR:fix-postgres-checkpoint-sequence

Conversation

@GaoSSR

@GaoSSR GaoSSR commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Describe what this PR does / why we need it

PostgresSaver currently orders checkpoints by saved_at when loading checkpoint history and the latest checkpoint. In concurrent writes, two checkpoints can share the same timestamp, so the database can return either row first.

This PR makes PostgreSQL checkpoint ordering deterministic by using an auto-increment sequence column, matching the MySQL saver behavior.

Does this pull request fix one issue?

NONE

Describe how you did it

  • Add a checkpoint_seq sequence column to GraphCheckpoint and create it for existing tables when tables are initialized.
  • Order checkpoint history and latest-checkpoint queries by checkpoint_seq DESC instead of saved_at DESC.
  • Add an index for checkpoint lookups by thread and sequence.
  • Add regression coverage that forces tied saved_at values and verifies list/get return the newest inserted checkpoint.

Describe how to verify it

  • CI=true ./mvnw -pl spring-ai-alibaba-graph-core -Dtest=PostgresSaverTest#testPostgresSaverOrdersCheckpointsByInsertSequenceWhenSavedAtTies test
  • CI=true ./mvnw -pl spring-ai-alibaba-graph-core -Dtest=PostgresSaverTest test
  • git diff --check

Special notes for reviews

The sequence is only used for deterministic ordering. Existing saved_at values remain unchanged, and CreateOption.CREATE_NONE still does not modify existing schemas.

@github-actions github-actions Bot added the area/graph SAA Grpah module label Jun 25, 2026
@GaoSSR GaoSSR force-pushed the fix-postgres-checkpoint-sequence branch from 3e9131b to 73250fa Compare June 25, 2026 16:58
@GaoSSR

GaoSSR commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the test job is failing in spring-ai-alibaba-agent-framework on two timeout cancellation tests:

  • AgentToolNodeAsyncExecutionTest$StateUpdateOnTimeoutTests.stateUpdates_shouldBeCleared_onTimeoutWithCancellableTool
  • CancellableAsyncToolCallbackTest$TimeoutScenarioTests.tool_shouldStopGracefully_whenCheckingCancellation

The same failures are present on a recent main Build and Test run: https://github.com/alibaba/spring-ai-alibaba/actions/runs/27903896284

The spring-ai-alibaba-graph-core module passed in this PR run.

Order PostgreSQL checkpoints by an auto-increment sequence instead of saved_at so same-timestamp writes return the real latest checkpoint.

Add a regression test that forces tied saved_at values and verifies list/get both return checkpoints in insert order.
@GaoSSR GaoSSR force-pushed the fix-postgres-checkpoint-sequence branch from 73250fa to 326ada8 Compare July 10, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/graph SAA Grpah module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant