Skip to content

Sessions and agents: catch up with sdk-sessions - #326

Open
igalshilman wants to merge 24 commits into
restatedev:mainfrom
igalshilman:claude/catch-up-with-sdk-sessions
Open

igalshilman wants to merge 24 commits into
restatedev:mainfrom
igalshilman:claude/catch-up-with-sdk-sessions

Conversation

@igalshilman

Copy link
Copy Markdown
Contributor

Brings restate.sessions and restate.agents level with sdk-sessions (TypeScript), which they follow. Each item below is one commit and stands on its own.

Fixes

  • A LangGraph graph of your own, after a crash between a step's writes and its checkpoint: the retry took the run for finished and answered from half-applied state. It now resumes from the stored writes, without running the step's tasks again.
  • The built-in LangGraph agent and a blank model reply: the blank message was stored and sent back in the next request, which a provider may refuse. It is stored as it came and sent as (no answer).
  • An invocation that prompts more than once: the records of its Restate tool calls are kept apart per prompt, so a later prompt's identical call is a call of its own, and a closed turn reports only its own calls.

Fewer commits

  • Restate tool calls: that a call answered, and that its record is forgotten, ride the commit that stores the tool's result (ride_commit, flush_riders in restate.sessions.internal). Only the record of a new call still commits before the call is made, and a transaction under way carries it.
  • LangGraph's checkpointer: a task's writes are stored in the transaction of the checkpoint that follows them at once. A task that finished while its siblings still run has its writes stored on their own, as before. An aput_writes returns once its rows are stored.

Parity

  • Shared core 8.7.3.
  • One heartbeat timer across back-to-back working scopes; RESTATE_SESSIONS_HEARTBEAT sets the interval.
  • RESTATE_SQL_L0_BYTES.

Tests

New tests for each item; tests/agents_commits.py pins what a turn costs in commits for each framework, with plain tools and with Restate tools, and checks at every commit that no tool result is stored beside a call record that is not marked done.

…e compiled statements

Also 8.7.2: a transaction that changed the schema drops the kept statements when it ends.
… result

Sessions: ride_commit and flush_riders, internal. A write that rides the next commit of a database,
and an urgent one that is written alone once no commit has started within a number of event-loop iterations.
…calls' records are tested at their own level

@pullfrog pullfrog Bot 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.

Important

The new heartbeat timer waits a full interval from when a working scope opens, not from the attempt's last write. As a result the silence can now reach almost twice the interval, which could get attempts shut down in deployments that shorten Restate's inactivity timeout. Details inline.

Approach: sound. Each parity item lives where the existing mechanism does: riders in Attempt's transaction path, writes batched inside the checkpointer, and prompt scoping in the calls ledger. Each comes with focused in-process tests.

Reviewed changes

Reviewed every source change and the new and changed tests. I ran the in-process suites for sessions, riders, calls, LangGraph writes, crash and commits: 167 passed.

  • Shared core 8.7.3 and RESTATE_SQL_L0_BYTES: state_options() in src/sessions.rs reads the L0 share once and passes it to every sql::Database::open.
  • Heartbeat timer: one TimerHandle now serves back-to-back working scopes, and RESTATE_SESSIONS_HEARTBEAT (ms) sets the interval.
  • Riders: ride_commit / flush_riders let bookkeeping ride the next commit's transaction. An urgent rider is written on its own after URGENT_HOPS loop iterations if no commit comes. AttemptDatabase.execute turns into a transaction while a rider is pending.
  • Call records: that a call answered, and that its record is forgotten, now ride the commit that stores the result. Matching and outcomes are scoped per prompt via for_prompt.
  • LangGraph checkpointer: aput_writes rows wait as pending, so the next aput stores them in its own transaction, or they are stored alone after _HOPS iterations.
  • LangGraph resume: snapshot.tasks replaces snapshot.next, so a run whose last step's writes were stored without its checkpoint goes on from those writes.
  • Blank replies: the built-in LangGraph agent sends blank AIMessages and empty answers as (no answer).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread python/restate/sessions/_driver.py Resolved
…interval, and once for scopes opened together

@pullfrog pullfrog Bot 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.

✅ No new issues found. The heartbeat concern from the prior review is fixed and covered by tests.

Reviewed changes

Reviewed the one commit since the prior review, which reworks when the first heartbeat of a run of working scopes is sent. tests/sessions_driver.py -m "not server": 90 passed.

  • First beat timed from the last write: _start_heartbeats now arms the first beat for _wrote_at + every, or beats at once if that time has passed. The silence again stays within one interval, as the working docstring promises.
  • One beat for scopes opened together: _heartbeat sets _wrote_at after a successful act. A scope reopened in the same iteration after a long silence therefore no longer beats a second time.
  • Tests: added works_after_silence plus two tests. One checks that a scope opened part way into a silence beats when the silence reaches the interval. The other checks that scopes opened back to back after a long silence send a single beat.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

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.

1 participant