Repository navigation
fix(pull): clamp the turn limit at claim so a healthy turn never outlives its lease (#2846) - #2941
Merged
Merged
Conversation
…ives its lease (#2846) A pulled turn ran with the timeout copied onto its row at enqueue, while its lease was sized from the agent's timeout at claim. When the agent's timeout was lowered while the job waited, or the row carried no timeout (worker default 900s), a healthy turn could run past its lease and the reaper would hand the same execution to a second worker while the first still ran. claim_next_task now reads the agent timeout once and uses it for both the lease and the turn limit (absent -> the agent timeout). A clamped limit is logged, and a timeout failure on a clamped job names the shortened limit so the operator knows which setting to change. This replaces the lease-renewal heartbeat the design specified and never built: with the clamp a heartbeat has nothing to do for a healthy turn, and for a hung turn it would keep the lease alive forever. TARGET_ARCHITECTURE, MESSAGE_ENVELOPE_SCHEMA (section 3.5, OPEN-4), the reaper docstring and the timeout endpoint's docs are updated to match. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UNS51H87HDMvtBVAZPiekJ
…on (#2846) The timeout note compared against the agent's current timeout, so a timeout lowered mid-run produced a false "shortened" claim; it now states the two numbers instead. The reaper docstring names the runtimes that enforce their own turn limit and the single-process assumption replicas would break. TARGET_ARCHITECTURE's open-question list no longer mentions lease renewal. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01UNS51H87HDMvtBVAZPiekJ
Contributor
|
merge-train 2026-09-22: riding this train. Validated lane B ( |
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.
Summary
claim_next_tasknow reads the agent timeout once and uses it for both the lease and the turn limit. The turn always ends inside its lease.(this job asked for 1800s but the agent's timeout is 600s; raise the agent's timeout to give it longer).Changes
src/backend/services/pull_coordination_service.py: clamp inclaim_next_task(_turn_limit), best-effort note on timeout failures inapply_task_result(_shortened_note, never blocks the terminal write).src/backend/services/lease_reaper_service.py: docstring states when an expired lease means a dead worker.src/backend/routers/agent_config.py:PUT /timeoutdocs: applies to new runs; queued pull jobs are cut to it when they start.docs/planning/TARGET_ARCHITECTURE.md(§Recovery),docs/planning/MESSAGE_ENVELOPE_SCHEMA.md(§3.5, OPEN-4): heartbeat replaced by the clamp.docs/memory/architecture/backend.md: catalog line.Behaviour change on pilot agents only: a legacy schedule whose timeout exceeds the agent's (created before the schedule ceiling existed) now stops at the agent's timeout instead of being re-delivered mid-run; the failure text names the setting to raise.
Test Plan
TestClaimTurnLimitintests/unit/test_1081_pull_endpoints.py: over-cap, absent and within-cap timeouts; turn ends inside the lease; timeout note present/absent; note failure never blocks the terminal write.origin/devcheckout (local Python 3.11 IPv6/SSRF, portal uploads, skill assign, workflow trigger parity); none touch this change.Fixes #2846
🤖 Generated with Claude Code
https://claude.ai/code/session_01UNS51H87HDMvtBVAZPiekJ