cli-rs: prompt-history and frecency interop oracles can abort while polling an asynchronous JSONL append on Windows
Upstream dev @ e1d864a24d, Windows 10 x64 (build 19045), Bun 1.4.4. Commands below use PowerShell.
After bun install in the repo, run the following from packages/cli-rs:
$env:OPENCODE_TS_ROOT = (Resolve-Path ../..).Path
$env:OPENCODE_RS_REQUIRE_TS = '1'
bun run cargo test --locked -p opencode-tui --test all file_is_shared_with_typescript
On the compiled upstream test binary the history and frecency cases both failed with JSON EOF; the stash case passed. A small direct reproduction isolates the history helper. From the same directory, with a new empty state directory:
$root = (Resolve-Path ../..).Path
$state = (New-Item -ItemType Directory -Path (Join-Path $env:TEMP ([guid]::NewGuid().ToString()))).FullName
'[{"append":{"text":"example","files":[],"agents":[],"skills":[],"pasted":[],"mode":"normal"}}]' | bun --cwd "$root/packages/tui" --preload '@opentui/solid/preload' "$root/packages/cli-rs/parity/oracle/E.2-history.ts" $root $state
Expected one JSON array on stdout. Observed exit 0, empty stdout and ENOENT on stderr while polling for prompt-history.jsonl. The file existed after the process exited. The frecency helper showed the same behavior for frecency.jsonl. With existing history entries we also observed "JSON Parse error: Unterminated string" during the append check. The Rust harness parses the empty stdout and reports JSON EOF, which obscures the earlier error.
The polling helpers should tolerate a pending write and report a useful failure if the deadline expires. The evidence concerns the interop checks and does not establish corruption of saved user data.
Sources: https://github.com/anomalyco/opencode/blob/e1d864a24dec1507160e430597eae53487358c21/packages/cli-rs/parity/oracle/E.2-history.ts#L55 and https://github.com/anomalyco/opencode/blob/e1d864a24dec1507160e430597eae53487358c21/packages/cli-rs/parity/oracle/E.3-frecency.ts#L36
Thanks for the detailed report. I reproduced this on Linux, at the commit you reported. That commit is also the current dev (e1d864a), so it still happens there, and it isn't Windows-only.
- With a fresh, empty state directory,
parity/oracle/E.2-history.tswith a single append op exited 0 with empty stdout, every time. stderr showedENOENT ... prompt-history.jsonlthrown from inside theuntil("the appends")check. Afterwards the file existed and held the appended line. parity/oracle/E.3-frecency.tswith["a.ts"]failed the same way onfrecency.jsonl.
From the code: the check in each helper reads the file and calls JSON.parse on each line without handling a missing file or a half-written line. until in parity/lib/provider.ts doesn't catch that error, and when the deadline expires it only logs to stderr and returns. That fits the empty stdout you saw and the JSON EOF error from the Rust harness. I didn't see the Unterminated string case with existing history, and I didn't run the cargo test itself.
The script below reproduces both cases.
Reproduction script (repro.sh)
#!/bin/sh
# Reproduces anomalyco/opencode#67081 on Linux: the E.2/E.3 parity oracles throw ENOENT while
# polling an append that has not reached the file yet, exit 0 and print nothing on stdout.
# Usage: ROOT=/path/to/opencode-checkout (after `bun install`) sh repro.sh
ROOT=${ROOT:-/workspace/repo}
cd "$ROOT/packages/cli-rs" || exit 1
state=$(mktemp -d)
echo "== E.2-history (fresh state $state)"
echo '[{"append":{"text":"example","files":[],"agents":[],"skills":[],"pasted":[],"mode":"normal"}}]' |
bun --cwd "$ROOT/packages/tui" --preload '@opentui/solid/preload' "$ROOT/packages/cli-rs/parity/oracle/E.2-history.ts" "$ROOT" "$state" >"$state.out" 2>"$state.err"
echo "exit=$? stdout=[$(cat "$state.out")]"; grep -m1 ENOENT "$state.err"
echo "file afterwards:"; cat "$state/prompt-history.jsonl"
state=$(mktemp -d); cwd=$(mktemp -d)
echo "== E.3-frecency (fresh state $state)"
echo '["a.ts"]' |
bun --cwd "$ROOT/packages/tui" --preload '@opentui/solid/preload' "$ROOT/packages/cli-rs/parity/oracle/E.3-frecency.ts" "$ROOT" "$state" "$cwd" >"$state.out" 2>"$state.err"
echo "exit=$? stdout=[$(cat "$state.out")]"; grep -m1 ENOENT "$state.err"
echo "file afterwards:"; cat "$state/frecency.jsonl"
Run it: sh repro.sh