Skip to content

fix(session): preserve raw running tool state - #34959

Closed
GrilledFoch wants to merge 1 commit into
anomalyco:devfrom
GrilledFoch:fix-powershell-running-state-dev
Closed

GrilledFoch wants to merge 1 commit into
anomalyco:devfrom
GrilledFoch:fix-powershell-running-state-dev

Conversation

@GrilledFoch

@GrilledFoch GrilledFoch commented Jul 2, 2026 •

Copy link
Copy Markdown

Issue for this PR

Fixes #34960.

Related context, but not marked as closing: #29822, #24731, #21489, #27871.

Type of change

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

What does this PR do?

This preserves raw tool input while a legacy v1 tool part is still pending/running.

The bug I hit was observed with OpenCode v1.14.28 on Windows PowerShell. My local Mavis wrapper/log observer is not part of OpenCode, but its logs showed the failure shape as a terminal state mismatch: lastStatus=running while terminal status=completed, followed about 30 minutes later by session.finish reason=stale.

Relevant local Mavis log anchors:

  • line 151: [stream-stall] progress ignored without armed state
  • line 190: lastStatus=running with status=completed
  • lines 729-736: session.finish reason=stale, idleMs=1800408

The local trigger shape was:

New-Item -ItemType Directory -Path $env:TEMP\opencode-pipeline-repro -Force | Out-Null
Get-ChildItem $env:TEMP\opencode-pipeline-repro

On current dev, I reproduced the relevant OpenCode-side state loss with a focused regression test. A clean origin/dev worktree at f52424e05f, with only the regression test applied, failed because the running tool state had raw === undefined while the PowerShell pipeline was still running.

This PR:

  • accumulates tool-input-delta text into pending/running raw
  • preserves raw, time.start, title, and metadata across pending -> running and running metadata updates
  • adds optional raw?: string to legacy v1 ToolStateRunning
  • updates OpenAPI/generated SDK types for that optional field
  • redacts running raw in sanitized session export
  • drops unexpected error-state raw
  • keeps running raw in subagent compaction, while keeping error compaction clean

Generated artifacts were regenerated/checked with:

  • bun dev generate > ../sdk/openapi.json in packages/opencode
  • bun ./packages/sdk/js/script/build.ts at repo root

The generated SDK/OpenAPI content diff is limited to optional raw on ToolStateRunning.

How did you verify your code works?

Environment: Windows. Initial focused verification used Bun 1.3.13. Before pushing, I upgraded local Bun to 1.3.14 to satisfy the repository pre-push hook (packageManager: bun@1.3.14); the hook then ran root bun typecheck successfully.

PowerShell regression prefers powershell.exe, falling back to pwsh only if Windows PowerShell is unavailable. On this machine powershell resolves to C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe, $PSVersionTable.PSVersion = 5.1.26100.8737.

Passing locally:

  • bun run typecheck in packages/opencode
  • bun run typecheck in packages/sdk/js
  • bun run typecheck in packages/schema
  • root bun typecheck via the pre-push hook after upgrading to Bun 1.3.14
  • bun test test/session/processor-effect.test.ts test/cli/export.test.ts test/cli/run/subagent-data.test.ts --timeout 30000 in packages/opencode
    • 25 pass, 0 fail, 112 expect() calls
  • bun test test/session/prompt.test.ts --timeout 30000 in packages/opencode
    • 44 pass, 14 skip, 0 fail, 186 expect() calls
  • git diff --check

Full-suite note:

  • Earlier local Windows bun test --timeout 30000 in packages/opencode exceeded the 604 second command timeout before producing a complete result.
  • I am treating that full-suite Windows timeout as unrelated to this PR.
  • I am not claiming it as fixed by this PR, not claiming it as a pass, and not using it as evidence for this raw running-tool-state change.

Screenshots / recordings

N/A; this is a session state handling fix.

Checklist

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

@github-actions

github-actions Bot commented Jul 2, 2026

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

github-actions Bot commented Aug 2, 2026

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 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.

Windows PowerShell pipeline can lose raw running tool input

1 participant