Skip to content

fix(opencode): preserve loop diagnostics in tool metadata#490

Merged
Astro-Han merged 1 commit into
devfrom
codex/i489-bash-loop-diagnostics
May 7, 2026
Merged

fix(opencode): preserve loop diagnostics in tool metadata#490
Astro-Han merged 1 commit into
devfrom
codex/i489-bash-loop-diagnostics

Conversation

@Astro-Han

Copy link
Copy Markdown
Owner

Summary

  • Preserve existing harness diagnostics when tools update running tool metadata.
  • Add regression coverage for repeated successful Bash calls after Bash output metadata updates.

Why

Bash updates state.metadata while it streams output. That replaced the loop diagnostics attached on tool-call, so successful repeated Bash commands were invisible to the loop gate. In the #489 export, the same git diff command ran 39 times without the expected reminder, block, or stop.

This fixes the shared Tool.Context.metadata boundary instead of special-casing Bash, so tool-owned display metadata and harness-owned diagnostics can coexist.

Related Issue

Closes #489

Human Review Status

Pending. A human should make the final merge decision after reviewing the final diff and verification evidence.

Review Focus

  • The metadata merge order in SessionPrompt: new tool metadata such as Bash output should still update, while diagnostics.loop and diagnostics.failure remain intact.
  • The new regression test proves repeated successful Bash exact-input calls hit the existing 3/4/5 loop gate.
  • No Bash execution, permission, timeout, truncation, or loop threshold behavior changed.

Risk Notes

Low implementation risk, but the touched boundary is shared by tools that call ctx.metadata(). The focused tests cover Bash streaming metadata plus existing diagnostics, loop-gate, and Bash behavior.

How To Verify

Red test before fix: bun test test/session/prompt-effect.test.ts --test-name-pattern "loop gate stops repeated successful bash calls after metadata updates" failed with 5 completed Bash parts instead of 3.
Focused regression after fix: same command passed, 1 test, 27 expect calls.
Focused tests: bun test test/session/prompt-effect.test.ts test/session/diagnostics.test.ts test/session/loop-gate.test.ts test/tool/bash.test.ts: 129 passed, 0 failed.
Typecheck: bun run typecheck in packages/opencode passed.
Diff check: git diff --check had no output.

Screenshots or Recordings

Not applicable. This is session harness behavior with no visible UI layout change.

Checklist

  • Human review status is stated above as pending, approved, or not required
  • I linked the related issue, or stated why there is no issue
  • This PR has type, primary area, and priority labels, or I requested maintainer labeling
  • I described the review focus and any meaningful risks
  • I listed the relevant verification steps and the key result for each
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope
  • I manually checked visible UI or copy changes when needed, with screenshots or recordings
  • I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes
  • I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant
  • I reviewed the final diff for unrelated changes and suspicious dependency changes
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Astro-Han has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 56 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: dcc3471a-a46e-41c4-8d9d-bf2cc5cd1095

📥 Commits

Reviewing files that changed from the base of the PR and between 57e96b5 and 517762f.

📒 Files selected for processing (2)
  • packages/opencode/src/session/prompt.ts
  • packages/opencode/test/session/prompt-effect.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/i489-bash-loop-diagnostics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Astro-Han Astro-Han added bug Something isn't working harness Model harness, prompts, tool descriptions, and session mechanics P1 High priority labels May 7, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the metadata handling in packages/opencode/src/session/prompt.ts to use SessionDiagnostics.mergeMetadata when updating tool states, ensuring existing metadata is preserved and merged correctly. Additionally, a new test case has been added to packages/opencode/test/session/prompt-effect.test.ts to verify that the loop gate effectively stops repeated successful bash calls after metadata updates. I have no feedback to provide as there were no review comments.

@Astro-Han Astro-Han merged commit 506b263 into dev May 7, 2026
22 checks passed
@Astro-Han Astro-Han deleted the codex/i489-bash-loop-diagnostics branch May 7, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working harness Model harness, prompts, tool descriptions, and session mechanics P1 High priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Bash tool metadata drops loop diagnostics so repeated commands bypass the loop gate

1 participant