Skip to content

fix(rivetkit): drop a queued ActorConn action when its signal aborts - #6030

Closed
sAchin-680 wants to merge 2 commits into
rivet-dev:mainfrom
sAchin-680:fix/actor-conn-action-abort-signal
Closed

sAchin-680 wants to merge 2 commits into
rivet-dev:mainfrom
sAchin-680:fix/actor-conn-action-abort-signal

Conversation

@sAchin-680

@sAchin-680 sAchin-680 commented Nov 25, 2026 •

Copy link
Copy Markdown

Closes #6010

ActorConnRaw.action() already accepted signal in its options type but ignored it. While a connection reopens, an action waits in the message queue and is sent after the reopen. A caller with its own deadline (an HTTP request timing out, an interrupted Effect) may already have given up and retried elsewhere, so the queued action could run late or twice.

The signal is now honoured:

  • Already aborted: action() rejects with signal.reason. Nothing is queued or sent.
  • Aborted while queued: the message is removed from the queue and the promise rejects with signal.reason, so it is never sent after the reopen. Other queued actions are unaffected.
  • Aborted after send: only the caller's promise rejects; the action may still run, so its outcome is unknown, as today. The in-flight entry stays so the late response is absorbed instead of logging No in flight response.
  • Settled before abort: no-op. The abort listener is removed when the call settles, so a long-lived signal shared across calls does not accumulate listeners.

For a deadline, use signal: AbortSignal.timeout(ms) rather than a separate timeout option.

Also adds a short "Timeouts and Cancellation" section to the actions docs showing how to pass a signal on handles and connections.

Notes

  • @rivetkit/effect needs no change. It calls actions through ActorHandle (HTTP) and already passes the fiber's abort signal (packages/effect/src/Client.ts).
  • Existing behaviour, not changed here: when a reconnect attempt is refused with a structured close or error (for example guard.service_unavailable), the close handler already rejects every queued action via #rejectPendingPromises. So actions currently stay queued only between retry attempts, during an attempt that succeeds, or during an attempt that hangs until the connect timeout. This change matters in those windows. It also composes with fix(rivetkit): reconnect on depot.unavailable instead of giving up #5998, which only touches lifecycle-errors.ts.
  • The server echoes action IDs and does not require them to be contiguous, so a dropped message leaving a gap in IDs is harmless.

Testing

tsc --noEmit passes and Biome is clean for the changed file. I couldn't find client unit tests in the repo to extend, so I verified with a temporary vitest suite (13 cases) that drives ActorConnRaw with a fake driver and WebSocket. It covers each case above, plus:

  • an abort from an onOpen handler just before the queue flushes
  • a failed send that re-queues the message
  • a shared signal across several calls, including listener cleanup
  • an abort after send followed by a late response, a server action error, or a dropped socket
  • an abort after the connection was closed or disposed

All 13 pass, with no unhandled rejections. Against the previous code, 9 fail; the other 4 check no-op cases. I'm happy to add the suite to the repo if you point me to where client tests should live.

`ActorConnRaw.action()` already took a `signal` option but never actually used it. While a connection is reopening, actions sit in a queue and get sent once it's back, even if the caller has already given up (and maybe retried somewhere else). So the same action could end up running late, or twice.

Now the signal is respected:
- If it's already aborted, the call rejects with `signal.reason` and nothing gets queued.
- If it aborts while the action is still waiting in the queue, the message is pulled out and never sent.
- If it aborts after the message went out, only the caller's promise rejects. The action may still run on the actor, so its response is quietly ignored when it comes back.

Closes rivet-dev#6010
@sAchin-680
sAchin-680 force-pushed the fix/actor-conn-action-abort-signal branch from 575791f to 6ee9d89 Compare November 25, 2026 16:20
@RivetAgent

RivetAgent commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Looks good—no high-confidence issues found in the cancellation logic or accompanying documentation.

No issues found. Checked for bugs and CLAUDE.md compliance; no CLAUDE.md files were present in the checkout.

Review limited to the local diff and surrounding code; GitHub PR metadata was unavailable because CLI authentication was not configured.

Copy prompt to fix all
Fix all actionable findings in the latest Ironworks code review on PR rivet-dev/rivet#6030. Inspect every referenced location, address each finding without changing unrelated behavior, run the relevant tests, and summarize what changed.

@sAchin-680

Copy link
Copy Markdown
Author

Hey @NathanFlurry, this PR makes ActorConn.action() respect the signal option from #6010. If the caller gives up while the action is still queued during a reconnect, it now gets dropped instead of sent later. It's a small change in one file. Would appreciate a look when you have time.

@creatifcoding thanks for the clear write-up on the issue.

Adds a short "Timeouts and Cancellation" section to the actions page. It shows how to pass a `signal` to `.action()` on handles and connections, what happens when it aborts, and links to the existing section on canceling work inside the actor.
@eersnington

eersnington commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

thank you, but this will be superseded as we found it to be a general problem in ts, rust and swift sdk. a patch will release soon!

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.

rivetkit client: let ActorConn.action() take an AbortSignal (or timeout) that drops its queued message when the caller gives up

3 participants