Skip to content

feat: auto-background timed-out foreground bash commands#1591

Open
liruifengv wants to merge 4 commits into
mainfrom
fix-bg-task
Open

feat: auto-background timed-out foreground bash commands#1591
liruifengv wants to merge 4 commits into
mainfrom
fix-bg-task

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — no linked issue; the problems are explained below.

Problem

Two related issues around background tasks:

  1. A foreground Bash command that hits its timeout (default 60s, max 300s) is killed outright, losing all progress on long-running commands.
  2. The agent frequently calls TaskOutput with block=true to wait for background task results, which re-blocks the main thread and defeats the purpose of background execution.

What changed

  • Timed-out foreground Bash commands now move to the background instead of being killed. On timeout the task is detached (reusing the ctrl+b detach path) and re-armed with the 600s default background deadline; a second timeout still kills it. The tool call returns immediately and completion arrives as the usual background-task notification. Controlled by a new config option [background] bash_auto_background_on_timeout (default true; set to false to restore kill-on-timeout). Agents without background tooling keep the kill behavior, since a detached task would be unobservable there.
  • TaskOutput prompts tightened to keep background tasks non-blocking. The tool description is repositioned as a snapshot reader (dropping "explicitly wait for completion" as a primary use), the block parameter description carries the discouragement, the Bash tool description steers away from blocking on just-launched tasks, and a blocking wait that times out now appends an in-result next_step nudge telling the agent not to block again.
  • Config reference updated in docs/en and docs/zh; changesets included (minor for the timeout behavior, patch for the prompt tuning).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f2cd847

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@f2cd847
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f2cd847

commit: f2cd847

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ea94be2b5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/tools/builtin/shell/bash.md
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2cd8472ed

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/agent/background/index.ts
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.

1 participant