From 22d8530864af0f12b94dd3ffe508e7c420cb1e40 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 15:02:56 +0530 Subject: [PATCH 1/3] ci: temporary workflow to find why `webfetch` and workspace-sync tests hang on CI Debug only, not for merge. Runs the two hanging test groups alone and inside their shards, and prints the test process's sockets, open files and syscalls whenever test output stops for 45 seconds. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/debug-test-hang.yml | 62 +++++++++++++++++++++++++++ script/github/debug-test-hang.sh | 39 +++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 .github/workflows/debug-test-hang.yml create mode 100755 script/github/debug-test-hang.sh diff --git a/.github/workflows/debug-test-hang.yml b/.github/workflows/debug-test-hang.yml new file mode 100644 index 0000000000..04efc5e06b --- /dev/null +++ b/.github/workflows/debug-test-hang.yml @@ -0,0 +1,62 @@ +# TEMPORARY (debug PR, do not merge). Finds why `test/tool/webfetch.test.ts` and the +# workspace-sync tests hang for minutes on CI runners. Delete with the branch. +name: Debug test hang + +on: + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + hang: + name: hang (${{ matrix.case }}) + if: github.head_ref == 'debug/ci-test-hang' + runs-on: ubuntu-latest + timeout-minutes: 25 + strategy: + fail-fast: false + matrix: + include: + - case: webfetch-alone + args: test/tool/webfetch.test.ts + - case: workspace-alone + args: test/altimate/workspace/sync-state.test.ts test/control-plane/workspace.test.ts + - case: shard-2 + args: --shard=2/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts + - case: shard-3 + args: --shard=3/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + persist-credentials: false + + - uses: oven-sh/setup-bun@ecf28ddc73e819eb6fa29df6b34ef8921c743461 # v2 + with: + bun-version: "1.3.14" + + - name: Cache Bun dependencies + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: ~/.bun/install/cache + key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }} + restore-keys: | + bun-${{ runner.os }}- + + - name: Configure git for tests + run: | + git config --global user.name "CI" + git config --global user.email "ci@test.local" + + - name: Install dependencies + run: bun install + + - name: Install merge tooling deps (script/upstream) + run: bun install + working-directory: script/upstream + + - name: Run tests with stall diagnostics + working-directory: packages/opencode + shell: bash + run: bash ../../script/github/debug-test-hang.sh ${{ matrix.args }} diff --git a/script/github/debug-test-hang.sh b/script/github/debug-test-hang.sh new file mode 100755 index 0000000000..67394c5dbb --- /dev/null +++ b/script/github/debug-test-hang.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# TEMPORARY (debug PR, do not merge): runs `bun test "$@"` and, whenever its output +# stops for 45s, prints what the test process is doing. +set -u +OUT=/tmp/debug-test.txt +echo "== host: $(nproc) cpus"; free -m | head -2; uptime +echo "== /etc/hosts"; cat /etc/hosts +echo "== localhost resolves to"; getent ahosts localhost | head -4 +echo "== proxy env"; env | grep -i -E '^(https?|no|all)_proxy=' || echo "(none)" +echo "== date"; date -u; echo "TZ=${TZ:-unset}" + +OPENCODE_SKIP_SUBPROCESS=1 bun test --timeout 90000 "$@" > "$OUT" 2>&1 & +PID=$! +dumps=0 +while kill -0 "$PID" 2>/dev/null; do + sleep 15 + kill -0 "$PID" 2>/dev/null || break + idle=$(( $(date +%s) - $(stat -c %Y "$OUT") )) + [ "$idle" -lt 45 ] && continue + dumps=$((dumps + 1)) + echo "::group::STALL dump $dumps: no test output for ${idle}s at $(date -u +%T)" + echo "-- last test output"; tail -n 12 "$OUT" + echo "-- load / memory"; uptime; free -m | head -2 + echo "-- process tree"; ps -eo pid,ppid,stat,etime,pcpu,pmem,args --forest | grep -v -E 'ps -eo|kworker|\[' | tail -n 40 + echo "-- bun process"; grep -E 'State|Threads|VmRSS|voluntary' "/proc/$PID/status" + echo "-- sockets"; sudo ss -tunap 2>/dev/null | grep -v -E 'systemd|chronyd|sshd' | head -n 40 + echo "-- open files (non-regular)"; sudo ls -l "/proc/$PID/fd" 2>/dev/null | grep -E 'socket|pipe|anon_inode|/tmp|\.db|\.lock' | tail -n 40 + echo "-- syscalls for 8s"; sudo timeout 8 strace -f -p "$PID" -s 100 -e trace=network,openat,flock,fcntl,poll,epoll_wait,futex,wait4,nanosleep,clock_nanosleep 2>&1 | grep -v -E 'EAGAIN|resumed' | tail -n 60 + echo "-- syscall summary for 5s"; sudo timeout 5 strace -f -c -p "$PID" 2>&1 | tail -n 25 + echo "::endgroup::" + if [ "$dumps" -ge 4 ]; then echo "== stopping the run after 4 stall dumps"; kill "$PID"; sleep 3; kill -9 "$PID" 2>/dev/null; break; fi + sleep 30 +done +wait "$PID"; code=$? +echo "== bun exit code $code" +echo "== tests over 10s, failures, summary" +grep -E '^\(fail\)|\[[0-9]{5,}\.[0-9]+ms\]|^ *[0-9]+ (pass|fail)$|^Ran ' "$OUT" | tail -n 40 +echo "== kernel log tail"; sudo dmesg 2>/dev/null | tail -n 25 +exit 0 From 1fa12e65f2fb3b1e5b24b76ae4a6f0b09effaf93 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 15:16:29 +0530 Subject: [PATCH 2/3] ci: debug run 2: report what the tests fetch from the npm registry Run 1 showed the stuck test process holding dozens of connections to the npm registry and writing `~/.npm/_cacache` while no test made progress. This run lists the packages fetched, and runs shard 3 with and without `test/tool/registry.test.ts` to confirm where the installs start. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/debug-test-hang.yml | 8 ++++---- script/github/debug-test-hang.sh | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/debug-test-hang.yml b/.github/workflows/debug-test-hang.yml index 04efc5e06b..01479ec2ee 100644 --- a/.github/workflows/debug-test-hang.yml +++ b/.github/workflows/debug-test-hang.yml @@ -19,10 +19,10 @@ jobs: fail-fast: false matrix: include: - - case: webfetch-alone - args: test/tool/webfetch.test.ts - - case: workspace-alone - args: test/altimate/workspace/sync-state.test.ts test/control-plane/workspace.test.ts + - case: registry-then-webfetch + args: test/tool/registry.test.ts test/tool/webfetch.test.ts + - case: shard-3-without-registry-test + args: --shard=3/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts --path-ignore-patterns=test/tool/registry.test.ts - case: shard-2 args: --shard=2/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts - case: shard-3 diff --git a/script/github/debug-test-hang.sh b/script/github/debug-test-hang.sh index 67394c5dbb..17165a6105 100755 --- a/script/github/debug-test-hang.sh +++ b/script/github/debug-test-hang.sh @@ -9,6 +9,13 @@ echo "== localhost resolves to"; getent ahosts localhost | head -4 echo "== proxy env"; env | grep -i -E '^(https?|no|all)_proxy=' || echo "(none)" echo "== date"; date -u; echo "TZ=${TZ:-unset}" +npm_cache_report() { + echo "-- npm cache: $(du -sh ~/.npm/_cacache 2>/dev/null | cut -f1), $(find ~/.npm/_cacache/index-v5 -type f 2>/dev/null | wc -l) index files" + echo "-- node_modules dirs under /tmp: $(find /tmp -maxdepth 5 -name node_modules -type d 2>/dev/null | wc -l)" + echo "-- registry requests by package (count):" + grep -rhoa '"key":"[^"]*"' ~/.npm/_cacache/index-v5 2>/dev/null | sed -E 's#"key":"make-fetch-happen:request-cache:##; s#"$##; s#https://registry.npmjs.org/##; s#/-/.*-([0-9][^/]*)\.tgz# TARBALL \1#' | sort | uniq -c | sort -rn | head -n "${1:-40}" +} + OPENCODE_SKIP_SUBPROCESS=1 bun test --timeout 90000 "$@" > "$OUT" 2>&1 & PID=$! dumps=0 @@ -22,6 +29,7 @@ while kill -0 "$PID" 2>/dev/null; do echo "-- last test output"; tail -n 12 "$OUT" echo "-- load / memory"; uptime; free -m | head -2 echo "-- process tree"; ps -eo pid,ppid,stat,etime,pcpu,pmem,args --forest | grep -v -E 'ps -eo|kworker|\[' | tail -n 40 + npm_cache_report 25 echo "-- bun process"; grep -E 'State|Threads|VmRSS|voluntary' "/proc/$PID/status" echo "-- sockets"; sudo ss -tunap 2>/dev/null | grep -v -E 'systemd|chronyd|sshd' | head -n 40 echo "-- open files (non-regular)"; sudo ls -l "/proc/$PID/fd" 2>/dev/null | grep -E 'socket|pipe|anon_inode|/tmp|\.db|\.lock' | tail -n 40 @@ -35,5 +43,7 @@ wait "$PID"; code=$? echo "== bun exit code $code" echo "== tests over 10s, failures, summary" grep -E '^\(fail\)|\[[0-9]{5,}\.[0-9]+ms\]|^ *[0-9]+ (pass|fail)$|^Ran ' "$OUT" | tail -n 40 +echo "== npm cache at the end"; npm_cache_report 120 +echo "== total distinct packages requested: $(grep -rhoa '"key":"[^"]*"' ~/.npm/_cacache/index-v5 2>/dev/null | sort -u | wc -l)" echo "== kernel log tail"; sudo dmesg 2>/dev/null | tail -n 25 exit 0 From 83895fc66eddffcfc33bda3ac7e22e7e51eaa245 Mon Sep 17 00:00:00 2001 From: RaghwendraSingh Date: Tue, 1 Dec 2026 15:41:43 +0530 Subject: [PATCH 3/3] test: debug run 3: candidate fix, the suite does not start real plugin installs Run 2 confirmed the cause: tests that write a tool or plugin file into a config dir make the app start an `npm install` of `@opencode-ai/plugin` there, in the test process and not awaited. Shard 3 passes with `test/tool/registry.test.ts` left out and fetches nothing from npm. Candidate fix under test here: - `ConfigPlugin.shouldInstallDependencies` returns false when `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1`; `test/preload.ts` sets it. - The config and TUI tests that check when an install is requested clear it; they use a recording installer and never reach the network. The debug workflow now runs all four shards with the npm-request report. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/debug-test-hang.yml | 8 ++++---- packages/opencode/src/config/plugin.ts | 9 ++++++++- packages/opencode/test/config/config.test.ts | 11 +++++++++++ packages/opencode/test/config/tui.test.ts | 5 +++-- packages/opencode/test/preload.ts | 6 ++++++ .../skill/release-v0.11.1-adversarial.test.ts | 19 ++++++++++++++++++- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.github/workflows/debug-test-hang.yml b/.github/workflows/debug-test-hang.yml index 01479ec2ee..4ebb998d82 100644 --- a/.github/workflows/debug-test-hang.yml +++ b/.github/workflows/debug-test-hang.yml @@ -19,14 +19,14 @@ jobs: fail-fast: false matrix: include: - - case: registry-then-webfetch - args: test/tool/registry.test.ts test/tool/webfetch.test.ts - - case: shard-3-without-registry-test - args: --shard=3/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts --path-ignore-patterns=test/tool/registry.test.ts + - case: shard-1 + args: --shard=1/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts - case: shard-2 args: --shard=2/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts - case: shard-3 args: --shard=3/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts + - case: shard-4 + args: --shard=4/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts steps: - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 with: diff --git a/packages/opencode/src/config/plugin.ts b/packages/opencode/src/config/plugin.ts index 7cc49f4f04..341f0f6464 100644 --- a/packages/opencode/src/config/plugin.ts +++ b/packages/opencode/src/config/plugin.ts @@ -81,11 +81,18 @@ export function needsDependencies(dir: string, plugins: readonly ConfigPluginV1. // PURE mode skips dependency installs entirely: isolated-HOME environments and subprocess tests run // with no package cache, so the install attempt fails, npm retries, and the process hangs past exit. // Fold that check in here so both call sites (Config and TuiConfig) stay in sync. +/** `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1` skips the install. The test suite sets it: an install + * started by one test is not awaited, outlives the test, and runs inside the test process. */ +function installDisabled(): boolean { + const v = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]?.toLowerCase() + return v === "true" || v === "1" +} + export function shouldInstallDependencies( dir: string, plugins: readonly ConfigPluginV1.Spec[] | undefined, ): boolean { - return !Flag.OPENCODE_PURE && needsDependencies(dir, plugins) + return !Flag.OPENCODE_PURE && !installDisabled() && needsDependencies(dir, plugins) } // altimate_change end diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index f32e56f635..9ad57c3fce 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -1063,6 +1063,17 @@ const loadConfigDirWithDependencies = ( describe("config dir plugin dependency install", () => { const npmIt = testEffect(Layer.mergeAll(infra, FSUtil.defaultLayer)) + // The suite's preload switches the background install off. These cases check when the app + // asks for one, through a recording installer that never reaches the network. + let installOff: string | undefined + beforeEach(() => { + installOff = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + }) + afterEach(() => { + if (installOff !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = installOff + }) + npmIt.effect("skips the install in a bare writable config dir but still writes .gitignore", () => Effect.gen(function* () { const npm = recordingNpm() diff --git a/packages/opencode/test/config/tui.test.ts b/packages/opencode/test/config/tui.test.ts index 306b0cdb37..f84da7087b 100644 --- a/packages/opencode/test/config/tui.test.ts +++ b/packages/opencode/test/config/tui.test.ts @@ -93,8 +93,9 @@ const getTuiPluginOrigins = (directory: string) => // altimate_change start — cover the TUI call site independently from server Config. for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] as const) { for (const pure of [false, true]) { + // The suite's preload switches the install off; this gate is checked through a recording installer. it.instance(`tui dependency install gate: ${source}${pure ? " (PURE)" : ""}`, () => - withEnv( + withEnv("ALTIMATE_DISABLE_DEPENDENCY_INSTALL", "0", withEnv( "OPENCODE_PURE", pure ? "1" : "0", withCleanState( @@ -130,7 +131,7 @@ for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] expect(installs).toEqual(!pure && ["file", "tool", "node_modules"].includes(source) ? [local] : []) }), ), - ), + )), ) } } diff --git a/packages/opencode/test/preload.ts b/packages/opencode/test/preload.ts index 1367e86df2..6f1361d58d 100644 --- a/packages/opencode/test/preload.ts +++ b/packages/opencode/test/preload.ts @@ -50,6 +50,12 @@ process.env["ALTIMATE_DISABLE_WORKSPACE"] = "1" // keychain); tests must never write there. Credential-store tests inject a backend instead. process.env["ALTIMATE_CODE_DISABLE_OS_CREDENTIAL_STORE"] = "1" // altimate_change end +// altimate_change start — a test that writes a tool or plugin file into a config dir makes the +// app start a real `npm install` of `@opencode-ai/plugin` there, in this process and not awaited. +// It outlives the test: several pile up, starve the event loop, and the tests that run next time +// out. Tests that check the install itself clear this and inject an installer. +process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1" +// altimate_change end // Set test home directory to isolate tests from user's actual home directory // This prevents tests from picking up real user configs/skills from ~/.claude/skills diff --git a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts index 5a805bdb51..e9ba2c086f 100644 --- a/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts +++ b/packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts @@ -249,7 +249,24 @@ describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => { fs.mkdirSync(path.join(dir, "node_modules")) saved = process.env[ENV_KEY] delete process.env[ENV_KEY] - expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) + // The suite's preload switches the install off; this case is about the product default. + const off = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] + try { + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true) + } finally { + if (off !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = off + } + }) + + test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1 suppresses installation, as the test suite's preload does", () => { + const dir = tmp() + fs.mkdirSync(path.join(dir, "node_modules")) + saved = process.env[ENV_KEY] + delete process.env[ENV_KEY] + expect(process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]).toBe("1") + expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true) + expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false) }) })