fix(environments): warn when heartbeat signals shutdown on first beat - #1786
Open
priyanka25aug wants to merge 1 commit into
Open
fix(environments): warn when heartbeat signals shutdown on first beat#1786priyanka25aug wants to merge 1 commit into
priyanka25aug wants to merge 1 commit into
Conversation
Author
|
@craigie-ant @raghu-giatec — tagging you both since this directly addresses the issue you reported and diagnosed. @craigie-ant, given you've already traced the root cause on the issue, would appreciate your review when you have a moment — happy to adjust anything that doesn't fit the codebase conventions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
ant beta:worker poll --on-work spawn.sh, ifspawn.shexits immediately after launching a background container — e.g.kubectl applyordocker run -d— the poller releases the work-item lease before the spawned worker connects. The first heartbeat then returnsstate: stopping,_heartbeat_loopsilently callsstop.set()and returns, and the session is permanently stuck atstop_reason: requires_actionwith no output to explain why.This is the issue described in #1779: the failure is deterministic once you understand the cause, but the SDK gives the user nothing to go on — no warning, no pointer to the blocking requirement.
Fix
src/anthropic/lib/environments/_worker.py— the hand-written carve-out, not Stainless-generated code.1.
_heartbeat_loop: detect and warn on first-beat shutdownAdd a
heartbeat_countcounter. Whenstate: stopping/lease_extended: falsearrives on the very first successful heartbeat, emitlog.warningwith an explicit message:docker runforeground vs-d,kubectl waitvskubectl apply)All subsequent shutdowns continue to use
log.info(normal end-of-session).2.
handle_itemdocstring: add aNote:sectionDocuments the blocking requirement inline where users reading the API are most likely to encounter it, complementing any docs-side updates.
Testing
The change is a logging-only diagnostic path; existing behaviour for normal session teardown (
heartbeat_count > 1) is unchanged. The newlog.warningbranch fires only whenheartbeat_count == 1at shutdown, which is the exact condition that previously produced a silent hang.Fixes #1779