Commit Graph
13 Commits
Author SHA1 Message Date
Devika Verma 27881f445b fix(shell): a failed PowerShell cmdlet no longer reports an earlier program's exit code
`$LASTEXITCODE` keeps its value across calls, so after `cmd /c exit 3`
every later failing cmdlet (a missing `Get-Item`, say) reported exit
code 3, even several calls later.

When the parse check finds no errors, the same line now clears
`$LASTEXITCODE` just before the command runs. A failure reports a
native program's code only if one ran in this command, else 1. Like
bash, a later call no longer sees the previous call's code; each result
carries its own.
2026-11-05 15:14:47 +05:30
Devika Verma d0c47ea754 fix(shell): a multi-line PowerShell command no longer hangs
PowerShell's `-Command -` REPL waits for an empty line before it runs a
statement that spans lines (`foreach (...) {` ... `}`), like an
interactive console. Nothing sent one, so the trailer was read into the
open block, the marker never came, and the call hung until its timeout.

After a command that spans lines, one empty line is now sent before the
trailer. The parse check guarantees the command is complete, so the
line only ends it. Single-line commands are sent as before; the last
line's exit code still decides, and state defined across lines
persists.
2026-11-05 15:14:47 +05:30
Devika Verma df69eb9997 fix(shell): a PowerShell parse error is exit code 1, not 0
PowerShell's `-Command -` REPL skips a line it cannot parse, so the trailer's
`$?` still held the previous trailer's success and `run_shell` returned
exit_code 0 (round-2 F-8: `curl ... --data-binary @notes.txt` is splatting
to PowerShell). An unclosed quote also swallowed the trailer and hung until
the timeout.

The executor now parses each command in the running shell first, with
PowerShell's own parser (the command is sent as base64). On errors nothing
runs and the result is exit code 1 with PowerShell's error text, as
`powershell -Command` gives. The check's variables are removed again.
Covers direct mode and the sandbox tool runner, which share the executor.
2026-11-05 15:14:47 +05:30
Devika Verma c6d75b4f08 test_shell: capped-wait test uses a silent command, so only the exit can end the wait
The test started an echo in the background and expected a huge wait to
come back with the task exited. The wait also returns on new output, and
the echo's line can arrive a moment before the process exits, so under
load the wait returned "running" (reproduced: 3 of 300 runs on a loaded
machine; 0 of 600 with this change).
2026-10-29 19:55:41 +05:30
Devika Verma 45c283d75f shell_task_output: wait_seconds, so an agent can wait for a background task instead of polling it (OPE-227)
shell_task_output returned at once, and run_shell's description told the model to poll it. That is right for a dev server (nothing to wait for) and wrong for a build or test run the next step depends on: every poll is a full model call, and the only alternative, run_shell("sleep N"), is a blind wait capped at 600 s. Measured on a sealed evaluation run: 297 polls on one background job, ~$8.50 of cache reads and ~50 min of a 90-min clock spent asking whether it had finished.

wait_seconds (default 0 = unchanged) blocks until the task exits, prints new output, or the user interrupts, up to the shell's 600 s ceiling; the record gains waited_seconds. The sandbox path carries the wait over the socket and stretches the client's RPC timeout to cover it (it was a hard 30 s). Descriptions reworded, generically: check background processes with shell_task_output; if your next step depends on one finishing, pass wait_seconds rather than polling.

Tests, on both executor variants: returns early on exit (with the last line), returns early on new output, gives up at the deadline while running, wait_seconds 0 / negative / omitted unchanged, cap advertised and applied.
2026-10-20 22:36:47 +05:30
Rohit C Prasad 42f71f8abd Tool runner on Windows: the daemon listens on a named pipe
The pipe's security descriptor admits only the accounts the daemon is given; the runner and shell tests run on Windows.
The registry's liveness probe no longer uses os.kill(pid, 0), which terminates a process on Windows.
2026-09-21 21:51:26 -07:00
Devika Verma 58385ef02b Seatbelt provider: the tool runner inside the macOS sandbox
Files limited to the session's folders, network only through the allow-list proxy, no secrets in the environment.
A folder granted while a session runs restarts the sandbox and tells the agent (both providers).
On macOS the executor finds a timed-out command's children without pgrep.
2026-09-19 18:31:35 -07:00
Devika Verma e70181f776 Tool runner: JSON-RPC daemon, attach relay, client and the Workspace interface
Direct mode stays the default and is unchanged; the runner serves the same Executor contract.
A cut stream resumes, a restarted runner fails running commands, a request id runs once.
Shell tests now run on both paths; runner-local is a developer provider with no confinement.
2026-09-19 15:40:33 -07:00
Rohit Prasad 85330f6c3e Merge pull request #216 from CyberDefenseOperations/contrib/fix-flaky-shell-background-test
test: fix flaky test_background_task_runs_and_exits near the exit tick
2026-08-23 12:15:57 -07:00
Rohit C Prasad b866157778 Managed tools land on the persistent shell's PATH
install() links binaries into a stable tools/bin dir; LocalExecutor appends it
at spawn, so a mid-session install works by name without a respawn.
2026-08-14 23:50:51 -07:00
Rocky DeStefano b0aeff63ed test: tighten the output drain (address PR review perf feedback)
Per review: drain output greedily (consume anything already buffered with no
sleep) and only sleep between EMPTY reads, stopping after two consecutive empties
(robust to a one-tick gap between chunks). Bound cut 2.0s -> 0.5s. Common case is
now a couple of reads rather than a 0.02s poll that could, worst case, read up to
~100 times; also removes the break-on-first-empty fragility. Verified 20/20.
2026-07-26 23:33:25 -06:00
Rocky DeStefano 668f46ea8c test: fix flaky test_background_task_runs_and_exits near the exit tick
The background-shell poll helper (_poll_output) returned the instant it saw
status=='exited', but shell_task_output reads are incremental and the final
output chunk can still be draining into the task buffer on the same tick the
status flips to exited. Under load the first post-exit read returns empty and
the helper returns acc='', failing 'quick_done' in acc. This is a harness race,
not a shell bug (the incremental-read contract is correct). Keep reading until a
read yields nothing new (bounded 2s) after the terminal status so the tail is
captured deterministically. Verified 15/15.
2026-07-26 16:42:11 -06:00
Rohit C PrasadandDevika 2b45018ffa OpenWorker: initial import
Imported from andrewyng/aisuite@1b4bbf303e
(contents of its platform/ directory, hoisted to the repo root).
Development history prior to this commit lives in that repository.

Co-authored-by: Devika <devikaverma11@gmail.com>
2026-07-21 11:09:41 -07:00