Skip to content

fix(core): bound session shell output before it reaches the model - #51890

Open
Veld101 wants to merge 1 commit into
anomalyco:v2from
Veld101:shell-output-bound
Open

Veld101 wants to merge 1 commit into
anomalyco:v2from
Veld101:shell-output-bound

Conversation

@Veld101

@Veld101 Veld101 commented Sep 28, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #45099

Supersedes #50660 (that one targets dev; the missing bound is present on v2 too).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Session shell output was injected into the next model request in full, up to the capture limit, bypassing the 50 KiB bound applied to normal tool output. A large shell command (for example a bun typecheck run with extensive diagnostics) could produce a request that exceeded the model context window, fail as provider.unknown, and leave the session stranded until a manual compaction.

On v2 the shell message reaches the model in packages/core/src/session/runner/to-llm-message.ts, where the shell case interpolated message.output?.output verbatim. This bounds it there, mirroring ToolOutput.MAX_BYTES (50 KiB): the full captured output stays in the session record for the user, while the model receives a bounded preview with a clear truncation marker.

Truncation is byte-aware and iterates by code point, so multi-byte UTF-8 content is not split into replacement characters at the boundary.

This ports the fix from the dev-targeted #50660 onto v2.

How did you verify your code works?

  • bun test test/session-runner-message.test.ts from packages/core - 30 pass, including two new cases: a 60 KiB ASCII shell output is bounded and carries [truncated: N bytes omitted], and a multi-byte (é) output never contains a replacement character at the boundary.
  • bun typecheck in packages/core; bun run lint - 0 warnings / 0 errors.

Note: bun run check still cannot complete in my Windows checkout because packages/app/src/custom-elements.d.ts is a git symlink (mode 120000) materialized as a text file (core.symlinks=false), which fails @opencode/app#typecheck with TS1128. That is unrelated to this change and passes on a normal checkout.

Screenshots / recordings

Not applicable; no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant