Skip to content

fix: keep on-demand servers alive while tools are running - #1164

Merged
samanhappy merged 1 commit into
samanhappy:mainfrom
yunfeizhu:fix/on-demand-active-calls
Sep 10, 2026
Merged

samanhappy merged 1 commit into
samanhappy:mainfrom
yunfeizhu:fix/on-demand-active-calls

Conversation

@yunfeizhu

Copy link
Copy Markdown
Contributor

A tool call that starts shortly before an on-demand server's idle deadline can be interrupted by the previous call's timer. A short concurrent call can also arm that timer while another call is still running, leaving the caller with a connection error after the tool has already performed a write.

Track active calls on the on-demand runtime, cancel idle shutdown before waking or using it, and start the idle period when the last call finishes. Release the count in finally so failed calls can still be reclaimed. Preserve the runtime object across configuration reloads so callers and timers share the same state, and keep discovery priming from closing a child that a tool call is using.

Fixes #1163.

Validation

  • On-demand suite: 22 tests pass, including both tool-call paths, overlapping calls, rejected calls, error results, configuration reloads, explicit closure, and discovery priming.
  • pnpm lint, pnpm build, and node scripts/verify-dist.js pass.
  • The real stdio reproduction from On-demand idle shutdown closes stdio servers during active tool calls #1163 now returns successfully: the call near the idle deadline completes in about 703ms, and the overlapping call completes in about 1702ms. Both deliver their results after writing the local record.
  • pnpm dev starts and connects the test upstream; /health returns HTTP 200. After discovery priming puts the upstream to sleep, the health payload reports it as disconnected/degraded.
  • pnpm test:ci --maxWorkers=2: 1468 passed, 15 failed. The same 15 failures reproduce in an unchanged checkout of fb60844f975e02de08f42b8849e927428b34fe6f. They include transport tests where the local DNS resolves example.com to 198.18.0.11, which the existing SSRF check blocks. No additional test failures were introduced.

@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@fb60844). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1164   +/-   ##
=======================================
  Coverage        ?   52.47%           
=======================================
  Files           ?      214           
  Lines           ?    17215           
  Branches        ?     4247           
=======================================
  Hits            ?     9034           
  Misses          ?     6782           
  Partials        ?     1399           
Flag Coverage Δ
unittests 52.47% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@samanhappy
samanhappy merged commit 260de33 into samanhappy:main Sep 10, 2026
3 checks passed
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.

On-demand idle shutdown closes stdio servers during active tool calls

2 participants