Skip to content

fix(opencode): batch shell output updates - #37653

Closed
flowluap wants to merge 1 commit into
anomalyco:devfrom
flowluap:shell-output-batching
Closed

fix(opencode): batch shell output updates#37653
flowluap wants to merge 1 commit into
anomalyco:devfrom
flowluap:shell-output-batching

Conversation

@flowluap

@flowluapflowluap commented Jul 18, 2026

Copy link
Copy Markdown

Issue for this PR

Closes#30001

Related to #35543. This PR also coalesces metadata updates and uses a bounded trailing-output drain.

Type of change

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

What does this PR do?

The shell tool currently awaits ctx.metadata for every decoded output chunk. For chatty commands, pipe chunking therefore controls durable update frequency, and process exit can win before trailing pipe output is consumed.

This change consumes output immediately, publishes the newest cumulative preview at most every 100 ms, then allows 100 ms for trailing output and performs a final flush before returning. The cumulative metadata.output contract is unchanged.

How did you verify your code works?

  • bun test test/tool/shell.test.ts: 26 pass
  • bun typecheck
  • 80 paced writes: 2.7x-3.7x fewer metadata updates and 8%-23% lower runtime depending on simulated metadata sink cost
  • Patched output was complete in 18/18 runs; baseline lost final output in 11/12 delayed-sink runs

Screenshots / recordings

N/A

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-actionsgithub-actionsBot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Based on my search, I found several related PRs that touch on shell output handling:

Potentially Related PRs:

  1. fix(app): show shell output while a command runs #37097 - fix(app): show shell output while a command runs

    • Related to shell output visibility during execution, which is connected to your metadata update batching logic
  2. fix: normalize carriage-return shell output #36684 - fix: normalize carriage-return shell output

    • Addresses shell output formatting, potentially affected by your chunking changes
  3. fix(shell): drain stdout before reading output to avoid "(no output)" on exit 0 #35543 - fix(shell): drain stdout before reading output to avoid "(no output)" on exit 0

    • Directly relevant: addresses the exact problem you're solving (trailing output being lost before the final read)

The most closely related is #35543, which also handles the edge case of output loss at process exit. Your PR extends this solution with batching and timing controls to prevent output loss in high-volume scenarios.

No exact duplicates found, but #35543 may need consideration for interaction with your changes.

@github-actionsgithub-actionsBot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for freeto 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.

ShellTool can return before the output stream drains

1 participant

@flowluap