fix(core): agent-session idle close must not fire during unsolicited background turns#1515
Open
lyq3 wants to merge 1 commit into
Open
fix(core): agent-session idle close must not fire during unsolicited background turns#1515lyq3 wants to merge 1 commit into
lyq3 wants to merge 1 commit into
Conversation
The idle-close timer added in chenhg5#1338 is only cancelled by foreground turns: unsolicited background activity (background task completions relayed by the unsolicited reader) neither cancels nor resets it, so a session doing background work past the timeout gets its live agent killed mid-stream, and a completed background turn never restarts the idle clock. Cancel the timer when the unsolicited reader marks a turn active, and reschedule it after the turn completes cleanly (after eventsNeedResync is cleared, since scheduling is refused while a resync is pending) — mirroring the existing foreground begin/end pairing. Also adds a real-agent blackbox E2E for agent_session_idle_timeout_mins (process reaped, next message resumes with context intact) and usage docs (EN/zh) for the option. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Follow-up to #1338 (found while comparing it with the now-closed #1492).
问题 / Problem
#1338 的空闲关闭定时器只被前台回合取消/重置:
The idle-close timer from #1338 is only cancelled/rescheduled by foreground turns. A session relaying unsolicited background events keeps counting down and gets its live agent killed mid-work; a cleanly-finished background turn never restarts the idle clock.
修复 / Fix
镜像前台回合的 begin/end 配对(核心 2 处调用):
cancelAgentSessionIdleClose;scheduleAgentSessionIdleClose—— 放在eventsNeedResync清零之后,因为调度在 resync 未决时会被拒绝。测试 / Testing
TestAgentSessionIdleTimeout_UnsolicitedTurnCancelsClose/_ReschedulesAfterUnsolicitedTurn),已验证无此修复时必失败(误杀复现),修复后通过,含-race;tests/blackbox/p1):真实 Claude Code 进程被回收(/proc 观测)→ 下一条消息 resume 且第一轮埋的暗号完好;agent_session_idle_timeout_mins的中英文使用文档(docs/usage.md / usage.zh-CN.md,Add per-session idle timeout for live agent processes #1338 只更新了 config.example);go vet+ 全量go test ./...全绿(no_web tag)。🤖 Generated with Claude Code