#4887·livekit

Initial RTC connection retry can terminate its own agent job when replacing the same participant identity

Author: CampbellMBXJCreated Sep 21, 2026Updated Sep 21, 2026

Summary

A single dispatched agent job appears to terminate itself when its initial RTC connection retries with the same participant identity. The server replaces the original joining participant, treats that removal as the agent leaving its job, and sends JobTermination. The replacement connection then succeeds while the SDK is already shutting down the same job.

We found this sequence in two historical self-hosted incidents. We have not yet produced a standalone reproduction or verified a fix. The initial transport stall remains unexplained; this report concerns the job termination triggered when the subsequent connection replaces the original participant.

Observed behavior

The lifecycle records show this ordering:

  1. One job is assigned and one agent entrypoint starts its initial connection.
  2. The server reports connect timeout after ICE connected; the first agent participant never becomes active.
  3. Approximately 15 seconds after the initial join, a new participant with the same identity replaces the original, which closes with DUPLICATE_IDENTITY.
  4. The same assigned job becomes JS_FAILED; its child process starts shutting down.
  5. About one second later, that same child process/job reports successful connection and starts application work.
  6. The replacement participant then leaves with CLIENT_REQUEST_LEAVE during SDK teardown. The other participant remains connected.

No second successful job assignment or application entrypoint was found in the bounded incident records. The observed ordering supports an initial connection retry, rather than two independently dispatched agents. It also does not implicate worker drain or SIGTERM as the initiating event.

We did not capture the raw server termination frame or parent-to-child shutdown message. That causal link is inferred from the matching job/process lifecycle and the source path below, rather than claimed as a captured packet.

Versions and confidence

  • One historical worker log directly identifies Node Agents SDK 1.4.6.
  • Contemporaneous dependency configuration resolves rtc-node 0.13.29, which pins rtc-ffi-bindings 0.12.60. We did not recover the exact historical native binary.
  • Historical deployment configuration points to server v1.12.0, but we did not independently recover each incident's server image digest.
  • We inspected the relevant server behavior in v1.12.0, v1.13.6, and current source commit 885c869ffafe64e5291dd07b4952620b1bf59787. Source inspection is not a claim that we reproduced the incidents on all three versions.

Source path

  • A fresh same-identity join removes the existing participant with ParticipantCloseReasonDuplicateIdentity: roommanager.go.
  • RemoveParticipant retrieves the agent job by identity, deletes that mapping, calls participantLeft(), and invokes TerminateJob(..., AGENT_LEFT_ROOM) without exempting a same-job replacement: room.go.
  • TerminateJob sends JobTermination before recording JS_FAILED: worker.go. Changing only the final status would still terminate the worker's job.
  • In the corresponding Rust FFI source, initial connection waits up to 15 seconds for PeerConnection establishment and retries using the same URL/token: timeout, connect retry loop.

The server's timeout message is explicitly after ICE connected. It does not establish a failed ICE candidate, DTLS cause, or NAT configuration problem. We do not have packet evidence identifying the initial transport fault.

Proposed reproduction approach — not yet executed

  1. Dispatch one job to a Node Agents worker on a pinned self-hosted server, with one synthetic remote participant present.
  2. Use a test hook or fault injector to stall only the first agent connection after ICE succeeds but before full establishment. Keep the worker alive and the original participant present long enough for the native initial-join retry.
  3. Permit the retry with the same job token/identity to connect successfully; do not dispatch another job or send a shutdown signal.
  4. Observe whether removal of the old participant sends JobTermination to the existing job before its replacement connection completes.

A deterministic server test could additionally simulate replacement of a pending participant belonging to the same running job and assert whether agentClient.TerminateJob is called. We are proposing these tests, not reporting them as passing reproductions.

Expected behavior and possible fix direction

A validated replacement belonging to the same live agent job should retain that job's ownership and running state so a successful retry can continue. A failed replacement or genuine terminal event must still clean up the job.

Could participant replacement preserve/reassociate the existing agentJob, rather than treating the old transport's departure as the job's departure?

An unconditional skip for every DUPLICATE_IDENTITY would be unsafe/incomplete: removal also deletes the job mapping and signals participantLeft(). Identity equality alone does not prove same-job ownership. Any fix should cover:

  • Successful same-job replacement, followed by normal cleanup when its replacement actually leaves.
  • Failed replacement and bounded cleanup.
  • A genuinely different job or worker colliding on an identity.
  • Stale callbacks for the old participant SID.
  • Concurrent room deletion, dispatch deletion, or worker loss.

Related work

#4447 and #4465 address successful shutdown being classified as failure. This report concerns the termination command itself interrupting a retry that subsequently succeeds. The proposed reason/status change in #4465 still calls TerminateJob.

rust-sdks#1426 avoids echoing a client Leave after a server Leave; it does not change the server job-termination path. python-sdks#813 addresses cleanup after cancellation of Python Room.connect; our observed case is a Node initial retry followed by server job termination.