Skip to content

feat: implement zombie turn management with internal API endpoints and add terminationGracePeriodSeconds - #1099

Open
thesujai wants to merge 3 commits into
mainfrom
feat/controller-loop-zombie-turn
Open

thesujai wants to merge 3 commits into
mainfrom
feat/controller-loop-zombie-turn

Conversation

@thesujai

@thesujai thesujai commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #

Changes

How was this tested?

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, python/trueforge_sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Medium Risk
Automatically cancels turns based on staleness, which can end agent work if thresholds are wrong or activity is not recorded; Helm default termination grace jumps from ~35s to 300s unless overridden.

Overview
Adds an abandoned-turn closer so long-idle running turns do not stay stuck forever. The controller runs a new periodic loop that calls internal HTTP APIs to list stale running turns (last activity older than ABANDONED_TURN_STALE_MS, default 15m) and close them in batches (ABANDONED_TURN_CLOSE_BATCH / ABANDONED_TURN_CLOSER_INTERVAL_MS), emitting turn.done with CancellationReason.Abandoned.

Session stores gain listStaleRunningTurns (Postgres/SQLite/in-memory) keyed off last event time or turn.created_at. Service-key routes live at /api/internal/turns/abandoned and /close-abandoned, wired through cancelSessionTurn like other cancellations. OpenAPI and TS/Python SDKs are regenerated for client.internal.turns.

Helm now sets pod terminationGracePeriodSeconds from server.terminationGracePeriodSeconds (default 300) instead of gracefulTimeoutSeconds + 5, with docs/env examples for the new knobs.

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

@changeset-bot

changeset-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e77649f

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

This PR includes changesets to release 4 packages
Name Type
@truefoundry/trueforge-sdk Patch
@truefoundry/trueforge-core Patch
@truefoundry/trueforge Patch
@truefoundry/trueforge-ui 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

@thesujai thesujai changed the title feat: implement zombie turn management with internal API endpoints feat: implement zombie turn management with internal API endpoints and add terminationGracePeriodSeconds Oct 19, 2026

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

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e77649f. Configure here.

Comment thread packages/trueforge/src/db/postgres/session-store/queries/turns.ts

This branch has not been deployed

No deployments
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