Skip to content

fix(app): keep a running script's shells out of the background pill - #66402

Merged
Tarquinen merged 6 commits into
devfrom
script-shell-pill
Nov 25, 2026
Merged

Tarquinen merged 6 commits into
devfrom
script-shell-pill

Conversation

@Tarquinen

@Tarquinen Tarquinen commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Closes #66401

Type of change

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

What does this PR do?

createSessionBackground hid a running shell from the background pill only when the foreground execute call listed a running shell call with the same command. That list comes from toolCalls progress, which the server sends at most once per 100 ms. A shell that starts right after the previous call finished was live for about 100 ms with nothing claiming it, so the pill flashed "1 shell" for every shell call in a script after the first.

Now the shell tool stamps each shell with the id of the call that started it (metadata.callID), and for a shell run by a script that is the execute call. The app hides a shell while the execute call it names is running. This is an exact match, the same way #65303 matches a script to its call by job id.

execute hands its call id to the shell tool through a core-only Context.Reference (CodeModeTool.Parent), so the tool Context and the plugin events are unchanged.

  • A shell the script didn't start, such as a user ! command or an automation's shell, names no running call and still shows.
  • A shell call that timed out inside a script and left its command running still shows: it has a running job, which a shell only gets once it moves to the background.
  • The command match stays for servers that don't send the stamp.

How did you verify your code works?

Ran the web app and a server from this branch, with a scripted stand-in for the model, and watched [data-component="session-activity-chips"] with a MutationObserver:

  • One script running six sleep 0.3 shells in a row: with the app's matching reverted the pill flashed 5 times, about 100 ms each, in both runs. With it, the pill did not appear in 3 runs.
  • A !sleep 3 sent while a script's sleep 6 shell ran: the pill showed "1 shell" for those 3 seconds.
  • A script whose first shell call timed out after 1 s, followed by a second shell call: the pill showed "1 shell" until the first command exited and never counted the second.

Tests:

  • packages/app/test-browser/session-background.test.ts: the existing script test now also has the script's shells, fails with the app change reverted.
  • packages/core/test/tool-shell.test.ts: a script's shell names the execute call, fails with the core change reverted.
  • bun run check.

The app runs above were done before the last commit, which only changed how the call id reaches the shell tool. The core test covers that the stamp is the same.

Checklist

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

Added by the opencode bot (AI-generated).

Public API: adds metadata.callID to shells started by the shell tool (backwards compatible)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change fixes the flash in the code: I ran the new test against the base logic and it fails there, and it passes with this change. I didn't run the app end to end.

Public API: unchanged. The change is internal to the app's createSessionBackground.

One concern: the new rule is broader than the bug needs. While a foreground script runs, it now owns every running shell of the session that started after it. That includes shells the script didn't start, such as a user ! command (SessionShell.start, metadata.background: true) or an automation shell. I confirmed this with a quick test: a user shell started during a running script appears in the pill on the base, and with this change it stays hidden until the script ends. Details are inline.

: shell.time.started >= item.started && item.commands.includes(shell.command),
: // A script lists a call a moment after its shell starts. Until then the shell is the script's, unless
// a call for it has already ended, which leaves a shell still running in the background.
shell.time.started >= item.started &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!item.ended.includes(shell.command) matches any shell started after the script, not only the ones it started. A user ! command (SessionShell.start creates it with metadata: { sessionID, background: true }) or an automation shell started while a long script runs is now hidden from the pill until the script ends. On the base it shows. Could this rule apply only to shells a script could have started? For example, skip shells with metadata.background === true, or allow only a short window after shell.time.started before the progress update has to list the call.

@Tarquinen
Tarquinen marked this pull request as draft November 25, 2026 17:00
@Tarquinen Tarquinen changed the title fix(app): keep a running script's shells out of the background pill before it lists them fix(app): keep a running script's shells out of the background pill Nov 25, 2026
@Tarquinen
Tarquinen marked this pull request as ready for review November 25, 2026 19:10

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commits fix my earlier concern: matching on the callID the shell tool stamps means a user ! shell or an automation's shell started during a script shows in the pill again. A shell whose call timed out also shows, because it now has a running job. I checked this with unit tests, not in the running app. The new app test fails with the base background.ts and passes with this change. tool-shell.test.ts passes, and tsc -b is clean in packages/app and packages/core.

Public API: two optional additions, both backwards compatible: shells started by the shell tool now carry metadata.callID, and the tool Context in @opencode/schema gains an optional parent. Clients that don't read callID keep the command match as before.

Nothing new to raise.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit keeps the same callID stamp but passes it through a core-only reference instead of the tool Context. I checked this with tests, not in the running app. tool-shell.test.ts passes, and it fails when I remove the line that sets the reference, so the test checks the new route. The app's background test still passes, and tsc -b is clean in packages/core.

Public API: shells started by the shell tool now carry an optional metadata.callID. This is backwards compatible. The plugin tool Context no longer changes.

Nothing new to raise.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit only reworks the app test: the script's shells are now checked inside the existing script test. I ran it: it passes with this change and fails against the base background.ts. As before, I didn't run the app itself. The rest of the change is the same as last round.

Public API: shells started by the shell tool now carry an optional metadata.callID. This is backwards compatible.

Nothing new to raise.

@wrightderek658-cell

wrightderek658-cell commented Nov 25, 2026 via email

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background pill flashes for each shell a Code Mode script runs

2 participants