Skip to content

How can I deploy a new worker version without abandoning tasks the old version owns?

During deployment, stop claiming new local work, let safe in-flight operations finish within the shutdown window, and preserve unresolved actions for the next worker. Deployment termination does not cancel AISwapLab jobs. Your application's shutdown path must record enough ownership and acceptance evidence for safe continuation.

OPERATE AN API INTEGRATIONAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Separate admission from execution; Bound graceful completion; Verify takeover behavior.
Workflow diagram: Separate admission from execution → Bound graceful completion → Verify takeover behavior. Read the article for evidence and limits.

Shutdown is a workflow event

A process can receive termination while awaiting a response or writing a completed asset. Abrupt replacement may leave ambiguous local state. A drain protocol reduces that gap and makes unavoidable interruption an explicit recoverable condition.

What to do next

  1. 01

    Separate admission from execution

    Add a draining state that disables new claims without deleting existing work. Remove the instance from request admission where appropriate, while keeping its current action identities and ownership tokens available to the shutdown handler.

  2. 02

    Bound graceful completion

    Allow operations that can finish safely to complete within the platform's grace period. Do not start new long operations during shutdown, and do not mark remote work failed merely because the process must exit.

  3. 03

    Verify takeover behavior

    Terminate a test worker before dispatch, during a remote wait and during local delivery. Confirm a replacement reads durable evidence and resumes the correct stage without creating a new creative action or accepting stale writes.

A concrete example

Illustrative example: a worker receives termination while tracking a known running job. It stops claiming new tasks, persists its latest observation and exits. A replacement later claims the same local action and continues observation rather than submitting another generation.

Run the local counterexample

Local runtime fixture, executed November 16, 2026. No AISwapLab request, payment or model generation was made.

Recorded runtime: Python 3.12.10; SQLite 3.49.1. Run the complete script below using that runtime or record the version and changed behavior in your own environment. The script uses synthetic data and temporary resources only.

python
from concurrent.futures import ThreadPoolExecutor
from threading import Event
import json
gate=Event();started=Event();pool=ThreadPoolExecutor(max_workers=1)
def active():
    started.set()
    if not gate.wait(3):raise RuntimeError('fixture release missing')
    return 'running callable completed'
try:
    running=pool.submit(active)
    if not started.wait(2):raise RuntimeError('worker not started')
    pending=pool.submit(lambda:'must not start')
    pool.shutdown(wait=False,cancel_futures=True)
    observed={'pendingCancelled':pending.cancelled(),'runningCancelReturn':running.cancel(),
      'runningCancelled':running.cancelled(),'runningDoneBeforeRelease':running.done()}
finally:
    gate.set();pool.shutdown(wait=True,cancel_futures=True)
observed['runningResult']=running.result();print(json.dumps(observed))

Actual output from this run

json
{
  "pendingCancelled": true,
  "runningCancelReturn": false,
  "runningCancelled": false,
  "runningDoneBeforeRelease": false,
  "runningResult": "running callable completed"
}

Use the result within its scope

Shutdown cancelled the queued future, but cancel on the running future returned false. That callable finished only after its local gate was released. A drain plan must classify queued and in-flight work rather than assume cancel_futures terminates everything. Preserve the identities of in-flight tasks and reconcile their stage after process replacement.

This is Python ThreadPoolExecutor behavior, not an operating-system termination test or proof of an AISwapLab cancellation API.

Before you call it ready

  • Draining prevents new claims.
  • Grace periods match platform configuration.
  • Replacement retains original action identities.

When to stop or choose another method

Stop rolling deployments that assume process termination means external generation stopped; prove the interrupted stages recover from durable evidence.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation