fix(ctx_shell): detach long foreground runs to a pollable job before the host abort (#1106) - #1119
Closed
andig wants to merge 1 commit into
Closed
fix(ctx_shell): detach long foreground runs to a pollable job before the host abort (#1106)#1119andig wants to merge 1 commit into
andig wants to merge 1 commit into
Conversation
…the host abort (yvgude#1106) The MCP host aborts a ctx_shell tool call that stays in the foreground past ~120s and hands back a task id from its own namespace, which background_action=status cannot resolve ("not found"). The child keeps running but its output is only recoverable via a truncated notification. Add a foreground soft cap (default 110s, override LEAN_CTX_SHELL_FG_CAP_MS) below the host abort: every foreground command now runs as a managed job and is waited on inline up to the cap. Fast commands return their output inline exactly as before; a command that outlasts the cap is left running and its real shell_* job id is returned, so the caller can always poll or cancel it. This sidesteps the host abort rather than trying to unify the two id namespaces (impossible from the daemon side). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
|
Cherry-picked to main as ef16916. Thank you for the contribution! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #1106 (and the follow-up in the comment: auto-backgrounded ids that
background_action=statusreports asnot found).Root cause
The 120s handoff is the MCP host aborting the tool call, not lean-ctx. When it fires it mints a task id in its own namespace; lean-ctx's registry is keyed by
shell_*blake3 ids and never sees that id, sobackground_action=statusgenuinely can't resolve it. The two namespaces belong to two processes and can't be unified from the daemon side.should_auto_backgroundonly pre-empts attimeout_ms >= 300_000+cargo test, so any other long command (or a lowertimeout_ms) runs foreground and gets stranded by the host abort.Fix
Add a foreground soft cap below the host abort (default 110s, override
LEAN_CTX_SHELL_FG_CAP_MS). Every non-explicitly-backgrounded command now runs as a managed job and is waited on inline up to the cap:shell_*id is returned so the caller can alwaysbackground_action=status/cancelit.This sidesteps the host abort instead of trying to reconcile the id namespaces.
Notes / caveats
LEAN_CTX_SHELL_FG_CAP_MSfor hosts with a lower cap.Test
New
background_shelltests: fast run returnsFinishedinline; slow run returnsDetached { job_id }with ashell_*id thatstatusresolves.cargo test --lib background_shell— 4 passed, compiled againstmain.🤖 Generated with Claude Code