Skip to main content
Learn how to ship a change that breaks older versions of a chat agent without leaving a single chat on the old code. Chats are long-lived: each one keeps running the version it started on until something moves it. Before a database migration, a removed tool or a changed API, every chat has to be off the versions that depend on the old behavior. You’ll opt the agent in to moving mid-reply, deploy the fix, set the skew protection threshold from CI, check that no run is left on an older version, and then make the breaking change.
Quick reference

1. Opt the agent in before you need it

Set versionSkew: "follow-mid-turn" on the agent and deploy it on its own, before you deploy the fix. Adding it in the same deploy as the fix is too late: it’s the old run that notices the threshold and hands its reply over, so the option has to be in the version that is already running when the fix ships.
trigger/support-agent.ts
With it, a reply in progress on an older version stops after the step it is on, and the current deployment continues the same reply. Without it, a reply in progress finishes on its old version, and the chat moves at its next message. Both versions need an SDK that supports "follow-mid-turn". If either is older, the reply finishes on its old version, and the check in step 4 lists its run until the run ends. Moving a running turn lists the other requirements.

2. Write the fix so it runs before the change

The fix is deployed first and the breaking change comes last, so the fixed version has to work against things as they are now. For a migration that renames a column, the fix reads the new column when it exists and falls back to the old one. For a removed tool, the fix stops offering the tool while the tool’s backend still answers.

3. Deploy the fix and set the threshold

Deploy the fix, then set the threshold to its version. The deploy authenticates with a personal access token (TRIGGER_ACCESS_TOKEN), but the threshold API needs the environment’s secret key (tr_prod_... for production, from the API keys page): store it as a separate TRIGGER_SECRET_KEY secret. The deploy step sets a deploymentVersion output:
.github/workflows/release-trigger-prod.yml
The response is the environment’s state after the change:
200
Only set the threshold on deploys that need it, for example from a separate workflow you start by hand. A threshold on every deploy moves every chat on every deploy. To move only this agent’s chats, add "task": "support-agent" to the body (a threshold for one task). To set it from the dashboard instead, open Session upgrades under Deployments and choose Upgrade sessions. From here, each chat on an older version moves to the fix:
  • A reply in progress stops after its current step (a running tool finishes first), and the fix continues it. The person chatting sees a pause of a few seconds.
  • A reply to a channel message, such as one from Slack, finishes on its old version, because its answer posts back through that delivery. The chat moves at its next message. Wait for that reply before you cancel its run in step 4.
  • A chat that gets a new message answers it on the fix.
  • A chat nobody messages keeps its old run until the run ends on its own after the agent’s idle timeout.
For the agent’s idle timeout after each reply, a chat’s run stays warm and holds a concurrency slot, the same as a run that is replying. Under a low concurrency limit, warm idle runs can leave no slot for moved chats and new chats, whose runs then queue until an idle run suspends or ends. Canceling idle old runs in step 4 frees their slots.

4. Check that nothing older is running

Before the breaking change, make sure no run on a version below the threshold is still active. This script lists them, and cancels them with --cancel. On the dashboard, the Runs page shows the same list when you filter by Version and by Status (skew protection threshold).
scripts/old-runs.ts
Run it with the environment’s secret key in TRIGGER_SECRET_KEY:
Output
An idle chat’s run counts: it shows as EXECUTING or WAITING while it waits for the next message. Wait for it to end after the agent’s idle timeout, or cancel it with --cancel. Canceling an idle chat run loses nothing: the chat’s next message starts a run on the fix with the whole conversation. Don’t cancel a run that is replying: it hands over when its current step ends, and canceling it loses the reply. Run the script again until it prints:
Output

5. Make the breaking change

Run the migration, remove the tool’s backend, or change the API. Only versions at or above the threshold are running, and every chat that comes back later starts on the current deployment.

Verify it

  • A reply that moved. On the Runs page, filter by the chat’s tag (chat:<chatId>). The run on the older version ends as Completed when its step finishes, and the next run, on the fix, starts a few seconds later and finishes the same reply.
  • A chat that was idle. Send it a message. The answer comes from a run on the fix. If you didn’t cancel the old run, that run ends as canceled with a reason that links the new one.
A reply only hands over between steps, and one on its last step finishes where it is (how a turn moves). A reply with no tool calls has a single step, so it always finishes on its old version and the chat moves at its next message. To see a real handover, send a message that makes the agent call a tool that takes several seconds, and set the threshold while the tool is running.

See also