Skip to content

fix(#1075): timeout the codex+opencode CLI probes; add the missing templates/codex routing test - #1091

Merged
admarble merged 1 commit into
mainfrom
feature/1075-chore-doctor-templates-timeout-the-codex-opencode-
Sep 19, 2026
Merged

admarble merged 1 commit into
mainfrom
feature/1075-chore-doctor-templates-timeout-the-codex-opencode-

Conversation

@admarble

@admarble admarble commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two small gaps left documented by #1059's QA, both a few lines.

  • doctor's CLI probes can no longer hang. opencode --version, codex --version and codex login status each shelled out with execSync and no timeout. codex login status reaches the network, so a hung binary or a stalled request hung sequant doctor with no output and no way out but Ctrl-C. All three now pass a bound — PROBE_TIMEOUT_MS = 5s for the --version pair, AUTH_PROBE_TIMEOUT_MS = 10s for the network-reaching login check. No new error handling: Node kills the child and throws ETIMEDOUT into each probe's existing catch, which already returns undefined/false and prints the install/login hint.
  • templates/codex/** null-routing now has a direct test, mirroring the templates/opencode/** case it sits next to. Previously the routing was only exercised indirectly through feat(#497): sequant init --agent codex — .agents/skills symlink, .codex hooks wrapper, doctor, README #1059's AC-6 symlink test, which would still have passed if the routing were wrong.

Per the spec's Open Question 1, the fourth un-timed execSync in the same file — the per-issue git log --grep at doctor.ts:207 — got the same one-line treatment. Local git, so a lower hang risk, but the same pattern in the same file.

Not pulled in: src/lib/workflow/platforms/github.ts:136 (execSync("gh auth status"), un-timed and network-reaching) is the same failure class one layer down, but GitHubProvider owns gh — flagged in the spec as a recommended follow-up, deliberately out of scope here.

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original All three probes pass a timeout to execSync ✅ Implemented grep -c "timeout:" src/commands/doctor.ts → 4 (was 0)
AC-2 Original Hanging codex ⇒ getCodexVersion() returns undefined within the timeout [GATE] ✅ Implemented doctor.integration.test.ts — 3 1075 cases pass; suite wall time 20.03s = 5+10+5, i.e. each timeout fired
AC-3 Original Hanging codex login status ⇒ isCodexAuthenticated() returns false ✅ Implemented Own case in the same describe; asserts false and elapsed < 15s
AC-4 Original Same treatment covers getOpencodeVersion ✅ Implemented Own case; asserts undefined and elapsed < 10s
AC-5 Original Direct templateDestination("templates/codex/**") null test [GATE] ✅ Implemented templates.test.ts:640 — npx vitest run src/lib/templates.test.ts -t "codex" → Tests 1 passed (was 0 matched)
AC-6 Original CODEX_API_KEY short-circuits before any subprocess, value never logged ✅ Implemented doctor.test.ts — npx vitest run src/commands/doctor.test.ts -t "1075" → Tests 1 passed

Derived ACs: none (spec recorded none).

Mutation verification

Both gate ACs were mutation-verified from a clean tree (git status --short | wc -l = 0), then restored.

Mutation-verified: AC-2 — deleted all timeout: PROBE_TIMEOUT_MS / timeout: AUTH_PROBE_TIMEOUT_MS lines from src/commands/doctor.ts (grep -c "timeout:" → 0); all three doctor probe timeouts (#1075) cases failed (Tests 3 failed | 2 skipped), test wall time rose from 20.03s to 76.25s as each probe sat through the full 25s stub sleep — AC-4's failure was the wall-time bound itself (expected 25257 to be less than 10000); restored.

Mutation-verified: AC-5 — deleted src/lib/templates.ts:331 (if (normalized.startsWith(\"templates/codex/\")) return null;); exactly one test failed, the new returns null for templates/codex/** (#1075) (expected '.claude/codex/config.toml' to be null), with 53 passed and no other case affected — no blast radius; restored.

The AC-2 mutation is the reason the wall-time assertion exists rather than the return value alone: a silent stub already yields undefined from the version-regex miss, so an un-timed getCodexVersion still returns the right value — just 25s late.

Test plan

Check Result
npm run build ✅ Passed
npm run lint ✅ Passed (--max-warnings 0)
Touched files (doctor.test.ts, doctor.integration.test.ts, templates.test.ts) ✅ 118 passed, 0 failed
npm test (full, once, foreground) ⚠️ 6460 passed / 3 failed — see below

Full-suite caveat — RESOLVED by the runner (2026-09-19)

Re-ran the full suite once more in this worktree at 64578189, foreground, nothing else running in it: Test Files 319 passed (319), Tests 6463 passed | 1 expected fail | 3 skipped, 371s, exit 0. prompt-wait.test.ts also passes twice on main. The three failures below were load flakes from the exec run, not this diff.

Original exec-time caveat

Full-suite caveat — please read

The full suite ran once, in the foreground, in 937s: Test Files 3 failed | 316 passed (319), Tests 3 failed | 6460 passed.

None of the three are in files this PR touches — re-running all four touched files gives 118 passed, 0 failed. One of the three is identified: src/commands/__tests__/prompt-wait.test.ts > returns 0 and prints the reply when one arrives within the window, which fails on a missing .sequant/relay/<pid>/inbox.jsonl inside a setTimeout — a relay-timer path with no coupling to doctor.ts or templates.ts.

The other two are unidentified. I piped the suite through tail -40, so the per-file FAIL lines scrolled out of the captured log, and re-running the full suite to recover them would have hit the 30-minute phase wall with the work unpushed. They should be settled against origin/main in this worktree before merge — I could not confirm they are pre-existing, only that they are outside this diff.

Known gaps / notes

  • #1084 has an open, unmerged branch also touching src/commands/doctor.ts and doctor.test.ts (checkShadowingLocalSequant, near line 116 — well clear of the 255–293 probes). Not pulled in. The second PR to land must merge origin/main and re-run the doctor tests.
  • The timeout tests live in doctor.integration.test.ts on purpose: the unit project keeps vitest's 5s default (fix(test): tsx-spawning integration tests blow vitest's 5s default — phase-registry should use the prebuilt dist like its five siblings #842), which a timeout test would blow.
  • The stubs exec sleep 25 rather than forking, so the killed child is the direct child — a grandchild would outlive the SIGTERM and hold the stdout pipe open past the timeout.
  • The PATH mutation is scoped to a withStubPath callback, never a file-level hook: the existing runs without crashing case spawns the real CLI and probes both binaries, so a leaked stub PATH would make it eat three sleeps.
  • Cases are describe.skipIf(process.platform === "win32") (the stubs are #!/bin/sh).

Closes #1075

The three execSync probes in doctor.ts had no timeout, so a hung binary -- or a stalled network request from 'codex login status' -- hung 'sequant doctor' with no output. Each now passes a bound (5s for --version, 10s for the network-reaching login check) and lands on its existing catch, which already reports not-installed/not-authenticated with a hint. The per-issue 'git log --grep' probe gets the same treatment.

Also adds the missing direct test for templates/codex/** null-routing, mirroring the opencode case.

Entire-Checkpoint: c5fc39f412df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(doctor/templates): timeout the codex+opencode CLI probes; add the missing templates/codex routing test

1 participant