mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-27 07:38:51 +00:00
fix(codemode): don't let a waiting shell_read hold up stop
This commit is contained in:
parent
06dd8ca427
commit
dba7abc681
3 changed files with 25 additions and 6 deletions
|
|
@ -507,10 +507,11 @@ export const Plugin = {
|
|||
if (Option.isNone(found) || found.value.metadata.sessionID !== context.sessionID)
|
||||
return yield* new ToolFailure({ message: `${input.shellID} is not a shell command of this session.` })
|
||||
const wait = Math.min(input.wait_ms ?? READ_WAIT_MS, READ_MAX_WAIT_MS)
|
||||
// Waits for the command's job when it has one, so the exit it sees is the job's: holding the job's notification
|
||||
// meanwhile, and taking its result once finished, so a pushed command read here isn't notified again.
|
||||
// Waits for the command's job too when it has one, holding the job's notification meanwhile and taking its result
|
||||
// once finished, so a pushed command read here isn't notified again. A cancelled job ends before its command.
|
||||
const job = yield* jobs.get(id)
|
||||
const until: Effect.Effect<unknown, unknown> = job?.status === "running" ? jobs.wait({ id }) : shell.wait(id)
|
||||
const until: Effect.Effect<unknown, unknown> =
|
||||
job?.status === "running" ? jobs.wait({ id }).pipe(Effect.andThen(shell.wait(id))) : shell.wait(id)
|
||||
// The calling script keeps blocking while this waits, instead of moving to the background.
|
||||
yield* jobs
|
||||
.collect(
|
||||
|
|
|
|||
|
|
@ -63,9 +63,9 @@ export const Plugin = {
|
|||
yield* Effect.forEach(
|
||||
stopped,
|
||||
Effect.fnUntraced(function* (id) {
|
||||
// The model asked for this, so no notification follows.
|
||||
yield* jobs.deliver(id)
|
||||
const info = yield* jobs.cancel(id)
|
||||
// The model asked for this, so no notification follows: the cancel's result is taken. This doesn't
|
||||
// wait for other holds, such as a `shell_read` waiting on the same shell, which the cancel ends.
|
||||
const [info] = yield* jobs.collect([id], jobs.cancel(id).pipe(Effect.asVoid))
|
||||
if (info?.notificationID) yield* jobs.completeBackground(info.notificationID)
|
||||
}),
|
||||
{ discard: true },
|
||||
|
|
|
|||
|
|
@ -1310,6 +1310,24 @@ describe("ShellTool", () => {
|
|||
expect((yield* shell.wait(shellID)).status).toBe("killed")
|
||||
yield* outboxCleared
|
||||
expect((yield* stop([shellID], "call-stop-again")).output).toEqual({ stopped: [], notRunning: [shellID] })
|
||||
|
||||
// A shell_read waiting on the command doesn't hold the stop up, and sees the command end.
|
||||
const other = yield* executeTool(registry, codeModeCall({ command: idleCommand, yield_ms: 50 }, "call-other"))
|
||||
const otherID = String(other.output.shellID)
|
||||
const reading = yield* executeTool(
|
||||
registry,
|
||||
codeModeCall({ shellID: otherID, wait_ms: 60_000 }, "call-read", ShellTool.readName),
|
||||
).pipe(Effect.forkScoped({ startImmediately: true }))
|
||||
yield* Effect.promise(() => Bun.sleep(100))
|
||||
expect((yield* stop([otherID], "call-stop-read").pipe(Effect.timeout("3 seconds"))).output).toEqual({
|
||||
stopped: [otherID],
|
||||
notRunning: [],
|
||||
})
|
||||
expect((yield* Fiber.join(reading).pipe(Effect.timeout("3 seconds"))).output).toMatchObject({
|
||||
running: false,
|
||||
exitCode: null,
|
||||
})
|
||||
yield* outboxCleared
|
||||
expect(yield* Queue.size(notices)).toBe(0)
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue