GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||
GeezerVison is showing github.com — feat(core): run shell commands in the process daemon by jlongster · Pull Request #61876 · anomalyco/opencode Conversation
|
| // the daemon's commands back. Once closed, this one leaves their timers, stops and reporting to it, and only | ||
| // still answers its own waiters. | ||
| let closed = false | ||
| yield* lifecycle.awaitShutdown.pipe( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you check what happens when a Location shuts down without a server restart (idle eviction like #51828, or invalidate)? Once closed is set, stop() returns early (L556), and teardown only detaches daemon commands. So the background job's onInterrupt → shell.stop(id, "killed") does nothing. As far as I can tell, Job.settle then marks the job cancelled, because the registry isn't closed and we're not detaching. The process keeps running in the daemon, with no timeout.
The next boot of that Location takes it back in recover(), but only SessionRestart calls ShellTool.reattach, so no job watches it and the session never hears how it ended. The 7-day sweep also skips running processes. Either stop daemon commands on a Location close that isn't a handoff, or reattach their jobs when the replacement Location boots.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, and fixed in 923b926. The scenario was reachable through a Location reload, vcs.init / debug.location.evict (plain invalidate), and narrowly through idle eviction. A closed Location now keeps watching the daemon commands it started (exit, timeout, stop), so the job finishes normally and the session is notified; only a server shutdown with a prepared handoff detaches. stop() works after close again, so jobs.cancel / cancelSession stop the command. The replacement still takes the commands back and is the only one that publishes events and applies retention; both read the deadline and stop reason from the daemon, so they can't disagree. notifyWhenDone no longer lives in the plugin's Location scope. New test in tool-shell: a background job survives a reload, cancelling one sends SIGTERM, the other completes and notifies.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The fix in 923b926 covers the scenario I raised. I read the diff and ran the tests in packages/core. I didn't change anything in the checkout; the bun.lock modification was already there and I left it alone.
shell.ts ~L244): daemon commands are skipped unless detaching.isStopping() is true. A reload or eviction therefore leaves their wait and timeout fibers running. Those fibers come from runForkWith(context), not the Location scope, and they only need PersistentPty, which is a global node. The transport stays usable after the Location closes.stop(): the closed early return is gone, so jobs.cancel / cancelSession on the old Location now send SIGTERM.stopReason and timeoutDeadline back through latest(), at timer expiry and on exit, so they report the same status. If both happen to stop the same command, it gets two SIGTERMs, which does no harm.notifyWhenDone: forkDetach takes it out of the plugin's Location scope, so the session is still notified after the Location closes.test/tool-shell.test.ts (63 pass, 23 skip, including the new reload test), plus shell, shell-daemon, detaching and job (37 pass, 1 skip). All of these ran on this machine's default path; I didn't run them against a real v8 daemon binary.I don't see anything blocking.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| expect(env.daemon.ops).not.toContain("terminate") | ||
| expect(env.signals(1)).toEqual([]) | ||
| expect(env.signals(4)).toEqual(["SIGTERM"]) | ||
| yield* Effect.sleep(150) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
These tests use real-clock sleeps (Effect.sleep(20/50/100/150)) against 50–100 ms command timeouts to decide whether a timer did or didn't fire (also L219, L299–L326). On a loaded CI machine that will flake. Could they use TestClock (already imported), or wait on the fake daemon's signals/ops instead of fixed delays?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0d93fd7. No real-clock sleeps remain in shell-daemon.test.ts: timers run on TestClock, and fake-daemon socket I/O is awaited with an until(condition) helper. The restart test sets an expired deadline directly instead of sleeping past it. Also fixed an EPIPE in the fake daemon and a retention race that showed up under load; 11 runs under 2x CPU load pass. The real-daemon test now runs by default against @opencode/pty 0.5.0.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Checked against pr/head (0d93fd7). This resolves my concern.
shell-daemon.test.ts no longer has any Effect.sleep or bare Bun.sleep. Timeouts and the SIGTERM→SIGKILL grace period are driven by TestClock.adjust (L165–170, L285, L317, L346). Everything else waits on fake-daemon state through until().until() (fixture/shell-daemon.ts:107) polls in real time on purpose, since the test clock can't drive socket replies. It gives up after 2,000 attempts of about 2 ms each, so a slow machine waits longer instead of failing.timeoutDeadline: Date.now() - 1 (L243). That matches the code: shell.ts:745 restores timers from deadline - Date.now() on the wall clock, so an expired deadline fires at once with no clock involved.One small thing: if process 3 is ever missing, if (expiring) at L243 skips the setup silently. shell.wait(before.expiring.id) would then hang until the test times out instead of failing with a clear message. Asserting it exists would be clearer, but it isn't a flake risk.
I didn't run the suite. The shared checkout's working tree is on an older commit with a modified bun.lock, so I didn't touch it, and I made no changes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Both earlier points are addressed. A Location that closes while the server keeps running now keeps watching its daemon commands. Timeouts and stops are read back from the daemon's metadata, and the background notifier no longer stops with the Location, so the session still hears how a command ended. The new tool-shell test covers this across a Location reload. The shell-daemon tests now use TestClock and the fake daemon's ops instead of real sleeps.
Re-checked at the new head: interrupting a shell call still gives the model the output tail, the saved-file notice and the shell ID. Core shell/job/session tests and typecheck:tsc pass. The public API impact is the same as in my earlier review. Nothing new to raise.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ad of at shutdown
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Both earlier points are still addressed in this head. Daemon commands now live in a server-wide registry (Shell.daemonNode), so a Location closing no longer takes them down, and background-job notices run in the server's scope through daemon.watch. The shell-daemon tests use TestClock and the fake daemon's ops.
Re-checked with the simulated model: interrupting a running shell call gives the model the output, the saved-file notice and the shell ID (the base gives Tool execution interrupted with no content). The TUI now shows that result too; before/after screenshots below. Core and server tests and typecheck:tsc pass.
Public API: the shell tool's structured output gains an optional killed string, and its metadata gains killed: true when set. An interrupted result now has interrupted: true and no longer has shellID in its metadata; the text names the shell ID. The persistent-pty rename route no longer returns PtyFeatureUnsupportedError. All backwards compatible.
The latest commits also reformat generate.ts, schedule.ts and artifact.ts, which aren't part of this change; those hunks can be dropped.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Split into three stacked PRs for review: #62976 (protocol v8 client) → #62977 ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
core: interrupted tools cannot retain partial results
There was an error while loading. Please reload this page.