fix(session): bound shell output to 50 KiB preview for LLM (fixes #45099) - #45942
Open
optamus-ai wants to merge 1 commit into
Open
fix(session): bound shell output to 50 KiB preview for LLM (fixes #45099)#45942optamus-ai wants to merge 1 commit into
optamus-ai wants to merge 1 commit into
Conversation
…malyco#45099) Session shell commands could persist ~1 MiB via shell output and inject the entire output into the next model request through to-llm-message.ts, bypassing the normal 50 KiB ToolOutputStore limit. This could exceed context, fail as provider.unknown and strand the session. Apply the existing 50 KiB tool-output cap to session shell LLM insertion: truncate shell output with head/tail preview and marker, preserving full output separately. Mirrors ToolOutputStore boundedPreview behavior, keeps security/timeout/permission unchanged, and ensures compaction token estimation remains valid. Regression: large shell output (1 MiB) now produces bounded LLM message (~51 KiB) instead of oversized. Closes anomalyco#45099
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found one potentially related PR: fix(core): cap session shell output (PR #45136) This PR appears to address the same or very similar issue—capping session shell output—and was likely opened around the same time or addressing the same #45099 issue. You should check if PR #45136 is already merged or if it's an alternative approach to the same problem. |
6 tasks
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.
Issue for this PR
Closes #45099
Type of change
What does this PR do?
Fixes session shell output bypassing the 50 KiB tool-output limit and stranding sessions.
Root cause:
packages/core/src/session/runner/to-llm-message.ts:141inserted the entire persistedmessage.output(up to ~1 MiB via shell capture) directly into the next model request asShell command: ${command}\n\n${output}. Normal tool output is bounded to50*1024viaToolOutputStore(MAX_BYTES) with preview, but session shell bypassed that.ToolOutputStorelimits, compaction token estimation (compaction.ts:86TOOL_OUTPUT_MAX_CHARS), and model contextcontext - bufferthen used stale token counts from prior model response, not the added 1 MiB shell, so provider could reject asprovider.unknownand session could not auto-recover.Changes (minimal, uses existing contracts):
to-llm-message.ts: bound shell output to50*1024bytes for LLM insertion with head/tail preview and marker[Preview: shell output truncated from ${bytes} bytes to 51200 bytes — full output retained separately], mirroringToolOutputStoreboundedPreviewlogic. Fullmessage.outputremains persisted separately; compactiontruncatestill applies.Preserved:
assertHttpUrl/PermissionV2/security, timeout, content-type,isImageAttachment/isTextualMime,ToolOutputStorelimits,SessionCompactiontoken estimation.How did you verify your code works?
1 MiBshell output ("x".repeat(1048576)) truncated to~51 KiB(51309bytes) with head/tail preserved and marker,50 KiBsmall stays unchanged (node test).to-llm-message.tsnow produces boundedShell commandLLM message, cannot create oversized model-facing shell message.git diff— 1 file, 30 insertions, 2 deletions,Buffer.byteLengthUTF-8 aware.git clone --depth 1,checkout -b optamus/fix-session-shell-45099,commit 3507256,pushtooptamus-ai/opencode,gh pr create— historydf35e84preserved.Screenshots / recordings
N/A — non-UI shell output truncation.
Checklist