Skip to content

Cancellation fails after a restart in distributed mode - #294

Merged
heerambavi1998 merged 9 commits into
mainfrom
ha/cancel
Aug 17, 2026
Merged

heerambavi1998 merged 9 commits into
mainfrom
ha/cancel

Conversation

@heerambavi1998

@heerambavi1998 heerambavi1998 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cancellation fails after a restart in distributed mode. Fix this by freezing the turn in such scenarios
Closes https://linear.app/truefoundry/issue/AGE-1842/after-a-restart-in-postgres-mode


Note

Medium Risk
Changes distributed session cancellation and durable turn state; unconfirmed freezes may race with a still-running owning executor, though store fencing limits impact.

Overview
Fixes sessions stuck in running after executor restarts or failed distributed cancel (e.g. Postgres/distributed mode).

Session cancel no longer fails with 412/424 when the owning executor is gone or Redis cannot confirm abort. cancelSessionTurn now freezes the turn in the store via SessionHandle.freezeTurn so the session can start a new turn. Confirmed local or peer abort (HTTP 200) still relies on the executor path to persist terminal state; unconfirmed cases log a warning and freeze anyway (the owning replica may still be running; first-terminal-write-wins applies).

Store API: freezeAndGetTurn takes a caller-supplied CancellationReason (barge-in cancelled-for-next-turn vs explicit client-cancelled). SessionHandle.freezeTurn wraps this for cancel and createTurn previous-turn cancellation.

Tests cover freeze-on-missing-local-run, Redis timeout/unreachable, and peer 412.

Reviewed by Cursor Bugbot for commit 2729c09. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2729c09

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@truefoundry/trueforge-core Patch
@truefoundry/trueforge Patch
@truefoundry/local-sandbox Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/trueforge/src/apis/sessions.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c236f79. Configure here.

@heerambavi1998
heerambavi1998 enabled auto-merge (squash) August 17, 2026 12:10
@heerambavi1998
heerambavi1998 merged commit 5b981ab into main Aug 17, 2026
9 checks passed
@heerambavi1998
heerambavi1998 deleted the ha/cancel branch August 17, 2026 13:13
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.

2 participants