Skip to content

fix(start-sdk): add ready-check hysteresis for dependents and log display-null failures - #4853

Open
only21mil wants to merge 3 commits into
Start9Labs:masterfrom
only21mil:fix/sdk-ready-check-hysteresis
Open

only21mil wants to merge 3 commits into
Start9Labs:masterfrom
only21mil:fix/sdk-ready-check-hysteresis

Conversation

@only21mil

@only21mil only21mil commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In HealthDaemon, a single non-success ready-check poll on a required daemon (probe timeout or thrown exec) immediately paused every dependent via changeRunning(false): SIGTERM, drain, and relaunch. On slow hosts under boot load, one probe blip tore dependents down mid-boot in a loop while the required daemon stayed healthy. setHealth() also returned before console.error when display was null, leaving dependency-driven pauses unlogged.

Fixes #3803.

Change

  • Track dependentsReady separately from raw _health (addWatcher() still fires on raw changes). After success, dependents tolerate 2 consecutive failure polls (READY_FAILURE_THRESHOLD = 3, poll-count based; success resets); loading, disabled, and starting pause immediately.
  • Pause dependents immediately on process crash/exit (onExit), failed start(), upstream dependency loss, terminal statusTrigger(..., { <status>: Infinity }) statuses, or a trigger that ends or throws with a failure pending.
  • Invalidate stale in-flight probes with probeEpoch across session resets, exits, and upstream loss, and drop late results from probes whose session a non-blocking stop aborted; catch effects.setHealth() rejections and keep lifecycle order across late health writes; keep Daemons.runUntilSuccess() on strict raw success.
  • Normalize synchronous throws and non-Error values (including unstringifiable objects) from ready.fn() and custom triggers without stopping polling or breaking term().
  • Log Health Check <id> failed: after withGracePeriod() for display: null checks, still skipping effects.setHealth(); EXIT_SUCCESS is unchanged.

Verification

All checks below were executed by an AI agent.

  • Compiled dist reproduction (Daemons.of, postgres with display: null, dependent immich-server):
    • Before (bf3c13a23): exited 1; 1 failed poll paused immich-server with 0 failure logs, and 1 thrown check paused it again with 0 logs.
    • After (0518fa0cc): exited 0; both blips logged Health Check postgres failed: without pausing immich-server, 3 failures paused it, recovery resumed it, loading/disabled/starting and SIGSEGV paused it immediately.
  • DaemonLifecycle.test.ts (6dc9c6746 vs e91471094): 12/18 new tests fail; 6 guard unchanged behavior. A 19th test covers a hung ready.fn(signal) across pause, resume, and active hysteresis.
  • On 0518fa0cc (adopted proposal/4853 b16e85d0e; 4/4 new non-failure tests fail on 62d25cd87): make start-sdk-test (542/542 core, 63/63 scripts, 440/440 Jest, 2/2 docs), sdk check/bundle, container-runtime-test (39/39), release-notes-test (201/201), check-version, and Prettier 3.8.3 passed.

Not checked

  • A Raspberry Pi 4 boot of the Immich s9pk on StartOS hardware.

model: gemini-4-neon, gpt-6.1-sol

Generated with Gemini 4 Neon in T3 Code Nightly

review effort: 'xhigh'

…ready-check-hysteresis

# Conflicts:
#	projects/start-sdk/lib/mainFn/HealthDaemon.ts
#	projects/start-sdk/lib/test/DaemonLifecycle.test.ts

@MattDHill MattDHill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The core change is sound: crash, exit, start-failure and upstream-loss still pause dependents immediately, the probeEpoch guards hold, runUntilSuccess stays strict, and catching effects.setHealth rejections fixes a real bug (one rejection ended the health loop on master). The DaemonLifecycle, health, trigger and Daemons suites pass, 125/125. One change before merge:

The threshold counts polls, not time, and covers every non-success result (HealthDaemon.ts, setHealth / READY_FAILURE_THRESHOLD = 3). Under defaultTrigger, loading and disabled poll every 30 s, so a dependency that reports loading after succeeding keeps its dependents up for about 60 s, and a check on cooldownTrigger(60_000) tolerates 2–3 minutes of failure. The ~2 s blip tolerance this is after only holds for failure/starting at the default 1 s retry, and a daemon that deliberately reports loading isn't a blip. Please limit the tolerance to failure (or failure/starting), or bound it by elapsed time, and have the fragment say which applies.

Also:

  • This changes what requires means for every package (dependents keep running against a failing dependency for a while), so it needs a maintainer's sign-off on the design.
  • Nit: the fragment's third bullet ("instead of stopping health checks") describes the old behavior.
  • Heads-up: conflicts with #4848 in DaemonLifecycle.test.ts.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes on 62d25cd8792c4fa2aea86f8ed8238a873d150f77.

[P2] Restrict transient tolerance to failure results — projects/start-sdk/lib/mainFn/HealthDaemon.ts, setHealth(). I agree with Matt's finding: the counter also tolerates loading, disabled, and starting. After a successful check, disabled therefore leaves dependent processes running, and loading under defaultTrigger takes another ~60 seconds to pause them. Those are explicit non-ready states, not necessarily failed-probe blips.

The proposal takes the failure-only alternative Matt offered:

  • Preserve the three-poll threshold for failure; pause immediately on other non-success results.
  • Extend the raw-watcher regression to cover loading, disabled, and both forms of starting, including recovery after the pause.
  • Record the readiness contract in the exported Ready documentation and packaging guide, and make the fragment explicitly poll-count based. Slower custom triggers or checks can still extend failure tolerance; this is not a wall-clock deadline.
  • Correct the fragment's throw-handling wording and remove the stale cadence summary beside Ready.

Maintainer sign-off on the changed requires semantics is still needed. I found no additional independent correctness regression in the lifecycle/probe invalidation paths.

Proposed changes: 62d25cd...proposal/4853

The reviewed head merges cleanly with current master (c6eb52a7f). Static review only: the proposal's tests and checks have not been run. The current PR checks are metadata-only.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
@only21mil

Copy link
Copy Markdown
Contributor Author

Note

🤖 Gemini 4 Neon responding on behalf of Victor

Adopted proposal/4853 (b16e85d0e) unchanged in 0518fa0cc, restricting the 3-poll hysteresis to failure results so loading, disabled, and starting (including waiting: true) pause dependents immediately, documenting the poll-count contract on Ready and in projects/start-sdk/docs/src/main.md, and updating the changelog fragment wording. Verified on 0518fa0cc after confirming all 4 new non-failure cases in DaemonLifecycle.test.ts fail against 62d25cd87's HealthDaemon.ts: make -C projects/start-sdk check, bundle, check-fmt, pinned Prettier 3.8.3 on all 5 touched files, focused Jest (128/128), make start-sdk-test (542/542 start-core, 63/63 scripts, 440/440 Jest, 2/2 editor docs), make container-runtime-test (39/39), the compiled dist/ repro covering failure tolerance plus immediate pause on loading/disabled/starting and crash, node scripts/changelog.mjs check-version projects/start-sdk, make release-notes-test (201/201), and a clean git merge-tree against origin/master. Maintainer sign-off on the requires semantics remains with the maintainers.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK: one failed ready-check poll of a required daemon pauses all dependents — no hysteresis, so slow hosts kill dependents mid-boot in a loop

3 participants