Skip to content

fix(agent-core): cap background shell output to match foreground#1372

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix/cap-background-shell-output
Jul 4, 2026
Merged

fix(agent-core): cap background shell output to match foreground#1372
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix/cap-background-shell-output

Conversation

@sailist

@sailist sailist commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No related issue. This is a follow-up to #1285, which capped foreground shell output at 16 MiB but left background (detached) commands exempt.

Problem

Background (detached) shell commands were not subject to the 16 MiB output ceiling that protects foreground commands. A runaway background command — for example one that prints tens of millions of lines — would stream its entire output into the persisted output.log and the in-memory disk-write chain with no bound, which can fill the disk or crash the process with an out-of-memory error. Foreground commands have been force-terminated at 16 MiB since #1285; background commands should behave the same.

What changed

  • Apply the 16 MiB output ceiling uniformly to foreground and background commands, so a background command that exceeds the limit is now terminated (SIGTERM → grace → SIGKILL) with the same guidance to redirect large output to a file.
  • Stop enqueuing output to the on-disk write chain once the ceiling trips for a background command, matching the existing foreground safeguard.
  • Rename the limit constant and stop-reason helper to drop the foreground-only wording, and update the related tests to cover background tasks.

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 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e8777fc

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

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/acp-adapter Patch
@moonshot-ai/migration-legacy Patch
@moonshot-ai/server Patch

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 4, 2026

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

commit: e8777fc

@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: 385e6a7ec7

ℹ️ 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 on lines +647 to +649
if (!entry.outputLimitTripped && entry.outputSizeBytes > MAX_TASK_OUTPUT_BYTES) {
entry.outputLimitTripped = true;
void this.stop(entry.taskId, foregroundOutputLimitReason());
void this.stop(entry.taskId, outputLimitReason());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict the output cap to process tasks

Because appendOutput is the common sink for AgentBackgroundTask and QuestionBackgroundTask as well as shell processes, this unqualified cap now also fires for detached subagent/user-question results. Those tasks append their completed result in one call and then settle as completed, so a >16 MiB result sets outputLimitTripped, returns before appendTaskOutput, and leaves TaskOutput/notifications without a persisted full log even though the task completed. Please scope the shell-output ceiling to process tasks, or keep non-shell task results persisted.

Useful? React with 👍 / 👎.

Background (detached) shell commands were exempt from the 16 MiB output
ceiling, so a runaway background command could fill the disk or crash
the process. Apply the same cap to background shell commands and stop
feeding the disk write chain once it trips. Scope the ceiling to
process tasks so subagent and user-question results, which are appended
once and must be persisted, are left untouched.
@sailist sailist force-pushed the fix/cap-background-shell-output branch from 385e6a7 to e8777fc Compare July 4, 2026 10:41
@sailist sailist merged commit d111c02 into MoonshotAI:main Jul 4, 2026
10 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 4, 2026
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