Skip to content

fix(sdks/ts): recover from inactive listener stream on heartbeat rejection - #4867

Closed
RealBhupesh wants to merge 1 commit into
hatchet-dev:mainfrom
RealBhupesh:fix/ts-sdk-listener-stream-recovery
Closed

RealBhupesh wants to merge 1 commit into
hatchet-dev:mainfrom
RealBhupesh:fix/ts-sdk-listener-stream-recovery

Conversation

@RealBhupesh

Copy link
Copy Markdown

Summary

Fixes #4824 — when the engine loses a worker's ListenV2 stream but unary heartbeats still reach the server, the TypeScript SDK now self-heals instead of entering a permanent zombie state.

  • Detect: heartbeat worker tracks consecutive FailedPrecondition rejections whose message is worker stream is not active; after 3 consecutive failures, posts a stream_inactive IPC message
  • Reconnect: ActionListener aborts the current ListenV2 with a reconnect-specific reason (distinct from shutdown), stops the heartbeat thread, and the existing actions() loop re-establishes via getListenClient() / listenV2. Capped at 10 reconnects with 3s backoff
  • Surface: worker status flips to UNHEALTHY during reconnect; /health returns 503 when unhealthy (also fixes TypeScript SDK: worker /health always returns HTTP 200, even when UNHEALTHY — breaks Kubernetes liveness probes #4823 for K8s httpGet probes)

No engine changes.

Test plan

Made with Cursor

…ction

When the engine loses a worker's ListenV2 stream but unary heartbeats still
reach the server, the TypeScript SDK now detects consecutive
FailedPrecondition rejections and re-establishes the listener. Workers are
marked UNHEALTHY during reconnect, and /health returns 503 so orchestrators
can restart stuck replicas.

Fixes hatchet-dev#4824
@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

@RealBhupesh is attempting to deploy a commit to the Hatchet Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for taking the time to open this pull request! ❤️

To keep our review queue focused, we only accept pull requests that are linked to an issue the Hatchet team has already triaged, labelled accepted, and assigned to you.

We couldn't find a linked issue that's both accepted and assigned to you, so we're closing this PR for now. This isn't a reflection of the quality of your work — it just helps us make sure effort goes into changes we're ready to merge, and that two people don't unknowingly build the same thing.

What to do next:

  1. Open (or find) an issue describing the change, and comment there to say you'd like to take it on.
  2. Wait for a maintainer to add the accepted label and assign the issue to you.
  3. Link the issue from this PR using a closing keyword (e.g. Closes #123) in the description, then reopen the PR.
    Thanks again for contributing to Hatchet! 🪓

@RealBhupesh

Copy link
Copy Markdown
Author

No concerns with the implementation here — this was closed automatically by the close-unaccepted-prs workflow because #4824 is not yet labelled accepted and assigned (per CONTRIBUTING.md). That's expected for first-time contributors on this repo.

Status: implementation is complete on RealBhupesh:fix/ts-sdk-listener-stream-recovery (commit 62662bb). I've asked maintainers on #4824 to add the accepted label and assign the issue; I'll reopen this PR as soon as that's in place.

@ubajwa-sketch — your verbal go-ahead is noted; we just need the formal triage step so the bot stops closing it. Thanks for offering to test against your repro once review starts.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds TypeScript worker self-recovery when heartbeats indicate that the ListenV2 stream is inactive and makes worker health affect the HTTP health-check status.

  • Detects repeated inactive-stream heartbeat failures in the heartbeat worker.
  • Aborts and re-establishes the action listener while updating worker health.
  • Returns HTTP 503 when the worker is unhealthy.
  • Adds focused tests for error detection, reconnect behavior, abort classification, and health responses.

Confidence Score: 4/5

The reconnect-attempt cap must be corrected before merging because repeated successful recoveries can continue indefinitely instead of stopping after the configured limit.

The new recovery path resets its attempt counter after every successful listener establishment, so repeated inactive streams never reach the advertised failure threshold; the SDK release metadata requirement is also unmet.

Files Needing Attention: sdks/typescript/src/clients/dispatcher/action-listener.ts and the TypeScript SDK release metadata

Reviews (1): Last reviewed commit: "fix(sdks/ts): recover from inactive list..." | Re-trigger Greptile


await this.heartbeat.start();
await this.heartbeat.start(() => this.handleStreamInactive());
this.streamInactiveReconnects = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Reconnect cap never accumulates

When the listener repeatedly becomes inactive after successful reconnections, getListenClient() resets streamInactiveReconnects before the next failure, so the counter never exceeds the configured limit and the worker reconnects indefinitely instead of surfacing the terminal error.

Suggested change
this.streamInactiveReconnects = 0;

Comment on lines +14 to +24
import {
isListenerReconnectAbort,
isListenerShutdownAbort,
LISTENER_RECONNECT_REASON,
LISTENER_SHUTDOWN_REASON,
} from './listener-abort';
import { WorkerStatus, workerStatus } from '@hatchet/v1/client/worker/health-server';

const DEFAULT_ACTION_LISTENER_RETRY_INTERVAL = 5000; // milliseconds
const DEFAULT_ACTION_LISTENER_RETRY_COUNT = 20;
const DEFAULT_STREAM_INACTIVE_RECONNECT_COUNT = 10;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 SDK release metadata missing

This changes published TypeScript SDK recovery and health behavior without the required version bump and changelog entry, leaving release tooling and consumers without a versioned record of the change.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk-ts Related to the Typescript SDK

Projects

None yet

1 participant