Skip to content

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

Closed

Description

@admarble

Two small gaps left documented by #1059's QA

1. doctor's version/auth probes can hang forever

src/commands/doctor.ts calls execSync("codex --version") and execSync("codex login status") with no timeout option. codex login status can reach the network, so a hung binary or a stalled request hangs sequant doctor with no output and no way out but Ctrl-C.

This mirrors the pre-existing getOpencodeVersion pattern, so the fix should cover both rather than only the codex pair: pass a timeout (a few seconds is plenty for --version) and treat the timeout as "not installed / not authenticated" with the existing hint.

2. templates/codex/ null-routing has no direct test

templateDestination maps templates/codex/** to null (it is rendered by writeCodexProvisioning, not copied by copyTemplates). src/lib/templates.test.ts has the equivalent case for templates/opencode/; codex has none. Today the routing is only exercised indirectly through #1059's AC-6 symlink test, which would still pass if the routing were wrong.

Neither is user-visible today. Filing so they are not lost — both are a few lines.


Release-graph plan — pre-2.16.0 blockers (2026-09-17)

Graph: pre-2.16.0 release blockers, node 3 of 4 Tier: mechanical Wave: 1
May touch: src/commands/doctor.ts, src/commands/doctor.test.ts, src/commands/doctor.integration.test.ts, src/lib/templates.test.ts, CHANGELOG.md

Confirmed 2026-09-17

src/commands/doctor.ts lines 255 / 273 / 293 — opencode --version,
codex --version, codex login status — all execSync, none with timeout. Each
already sits in a try/catch returning undefined / false, so an ETIMEDOUT lands
on the existing "not installed / not authenticated" path with its hint: the fix adds
the option and needs no new error handling.
src/lib/templates.test.ts — 16 opencode references including the direct
returns null for templates/opencode/** case at line 628; 0 codex references.

Acceptance Criteria

  • AC-1: all three probes pass a timeout to execSync — Evidence: grep -c "timeout:" src/commands/doctor.ts prints 3 or more (today 0)
  • AC-2: a hanging codex on PATH makes getCodexVersion() return undefined within the timeout instead of hanging — Evidence: npx vitest run src/commands/doctor.integration.test.ts -t "1075" 2>&1 | grep -E "Tests +([3-9]|[1-9][0-9]+) passed" prints a passed line (AC-2..AC-4 are three cases named with 1075, each with a sleeping stub on PATH and a bounded wall-time assertion)
  • AC-3: a hanging codex login status makes isCodexAuthenticated() return false within the timeout — Evidence: covered by the AC-2 command, as its own case
  • AC-4: the same treatment covers getOpencodeVersion, not only the codex pair — Evidence: covered by the AC-2 command, as its own case
  • AC-5: templateDestination("templates/codex/**") returning null has a direct test mirroring the opencode case at templates.test.ts:628 — Evidence: npx vitest run src/lib/templates.test.ts -t "codex" 2>&1 | grep -E "Tests +[1-9][0-9]* passed" prints a passed line (today: 0 matched, prints nothing)
  • AC-6: CODEX_API_KEY set still short-circuits before any subprocess, value never logged — Evidence: npx vitest run src/commands/doctor.test.ts -t "1075" 2>&1 | grep -E "Tests +[1-9][0-9]* passed" prints a passed line (a unit case asserting no spawn when the env var is set)

AC-2 and AC-5 are gate tests: mutation-verify (drop the timeout option → AC-2 hangs
or fails; delete the codex routing line → AC-5 fails) and record the markers.

Placement note

Sleeping-stub cases go in doctor.integration.test.ts, not doctor.test.ts — a file
without .integration. runs under the 5s unit budget (#842) and a timeout test will
blow it.

Activity

  1. admarble commented on Sep 18, 2026

    @admarble
    ContributorAuthor

    Runner context (2026-09-18, wave 1 of the pre-2.16.0 graph)

    • Base: main at f776158f. The files in May touch are unchanged since this plan was written, so the line references above still hold.
    • Hard 30-minute wall per MCP-dispatched phase. Commit WIP before running the suite. Run the suite once, in the foreground, with a timeout. Never background it.
    • Gate-test ACs must carry the Mutation-verified: AC-N — <mutation>; <test> failed; restored. marker in the PR body (CLAUDE.md format, machine-anchored as <!-- SEQUANT_MUTATION: ... -->). /qa §6i enforces it.
    • Keep every existing CHANGELOG.md Unreleased entry; add yours alongside.
    • Stop at PR. Do not merge. Merge order is decided by the human.
    • fix(mcp): plugin MCP server dies with CONNECTION_CLOSED when the open project has an older sequant in node_modules — npx ignores the pin and runs the local copy #1084 has an open, unmerged branch that also edits src/commands/doctor.ts and doctor.test.ts (local-shadow check). Do not pull it in; the second PR to land will merge origin/main and re-run the doctor tests.
    • grep -c "timeout:" src/commands/doctor.ts is still 0 on main today.
  2. admarble commented on Sep 18, 2026

    @admarble
    ContributorAuthor

    /spec — Plan (#1075)

    Complexity: Standard (6 ACs, 2 directories)

    AC Quality Check

    lintAcceptanceCriteria: 6/6 passed, 0 flagged. All six carry a declared Evidence: clause with a runnable command. Behavior-rule detector: no AC triggers (AC-6 hits never only — 1 keyword, below the 2-keyword threshold), so no Rule Touchpoints section.

    Scope Assessment

    Non-Goals: not present as a section, but the body scopes itself explicitly ("both are a few lines", May touch list). Adequate for a mechanical node.

    Metric Value Status
    Feature count 2 (probe timeouts; routing test) ✅
    AC items 6 ✅
    Directory spread 2 (src/commands/, src/lib/) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria — verification

    AC-1 — three probes pass timeout to execSync
    Verification: Integration Test (grep gate)
    Scenario: Given doctor.ts → When grep -c "timeout:" → Then ≥3.

    AC-2 — hanging codex ⇒ getCodexVersion() returns undefined within the timeout [GATE]
    Verification: Integration Test
    Scenario: Given a codex stub that sleeps 25s at the front of PATH → When getCodexVersion() → Then returns undefined and elapsed < 10s.
    Assumptions: execSync inherits process.env.PATH; the killed child is the direct child (stub must exec sleep 25, not fork it, or the pipe can outlive the SIGTERM).

    AC-3 — hanging codex login status ⇒ isCodexAuthenticated() returns false
    Verification: Integration Test — Given the same stub → When isCodexAuthenticated() → Then false and elapsed < 15s.

    AC-4 — same treatment for getOpencodeVersion
    Verification: Integration Test — Given an opencode stub → Then undefined and elapsed < 10s.

    AC-5 — direct null-routing test for templates/codex/** [GATE]
    Verification: Unit Test — expect(templateDestination("templates/codex/config.toml")).toBeNull() in a case whose name contains codex.

    AC-6 — CODEX_API_KEY short-circuits before any subprocess, value never logged
    Verification: Unit Test — Given the env var set and mockExecSync cleared → Then isCodexAuthenticated() is true, execSync not called, and the captured output never contains the value. Pair it with an unset-key control in the same case so not.toHaveBeenCalled() is not vacuous.


    Implementation Plan

    Phase 1 — src/commands/doctor.ts

    1. Add two module constants: PROBE_TIMEOUT_MS = 5_000 (--version) and AUTH_PROBE_TIMEOUT_MS = 10_000 (codex login status, which reaches the network and deserves the longer bound).
    2. Add timeout: to the three execSync option objects at lines 255 / 273 / 293. No new error handling — Node throws ETIMEDOUT/signal: SIGTERM into the existing catch, which already returns undefined / false and prints the install/login hint. Confirmed by reading all three catch blocks.

    Phase 2 — src/commands/doctor.integration.test.ts (AC-2/3/4)
    3. New describe.skipIf(process.platform === "win32")("doctor probe timeouts (#1075)", { timeout: 45_000 }, …) — three cases each naming 1075. Precedent for skipIf: combined-branch-test.integration.test.ts:93.
    4. beforeEach writes codex and opencode stubs (#!/bin/sh + exec sleep 25, mode 0o755) into a mkdtemp dir; a withStubPath(fn) helper prepends it to PATH and restores in finally. Scope the PATH mutation to the helper, never file-level beforeAll — the existing runs without crashing case spawns the real node dist/bin/cli.js doctor, which probes both binaries; a leaked stub PATH would make that case eat three sleeps.
    5. Each case asserts the return value and Date.now() - t0 < bound. The wall-time assertion is the actual gate: a silent stub already yields undefined from the regex miss, so the return value alone would pass even un-timed.

    Phase 3 — src/lib/templates.test.ts (AC-5)
    6. Add it("returns null for templates/codex/** (#1075)", …) next to the opencode case at line 628, asserting templates/codex/config.toml (the one real file in that tree) routes to null.

    Phase 4 — src/commands/doctor.test.ts (AC-6) + CHANGELOG.md
    7. Add the 1075 unit case inside the existing 1059 AC-4: codex CLI checks describe, which already saves/restores CODEX_API_KEY in beforeEach/afterEach.
    8. Add a ### Fixed bullet under [Unreleased], keeping every existing entry.

    Phase 5 — mutation verification (AC-2, AC-5)
    9. Start from git status --short | wc -l = 0 (commit first). AC-2: drop the three timeout: lines → the three 1075 cases fail on the wall-time bound (~25s each, inside the 45s budget — they fail, they do not hang; execSync is synchronous and vitest cannot interrupt it, which is why the stub sleeps a bounded 25s rather than forever). AC-5: delete doctor-side line templates.ts:331 → the new case fails. Restore, then record both Mutation-verified: AC-N — … markers plus their <!-- SEQUANT_MUTATION: … --> anchors in the PR body. Note in the record if the AC-5 mutation also trips other templates.test.ts cases.

    Design Review

    1. Where does this belong? Entirely inside the probe helpers in doctor.ts — they already own the "binary is absent/broken ⇒ report unknown" contract; a hang is just a slower form of broken.
    2. Simplest correct approach? Two constants and three option keys. Rejected: spawnSync with manual kill (same semantics, more code); async/Promise.race (would ripple through doctorCommand's sync call sites for no user-visible gain).
    3. Existing pattern? getOpencodeVersion's try/catch-returns-undefined shape, which the codex pair already copies — AC-4 keeps the three in lockstep rather than leaving one divergent.
    4. What would a reviewer challenge? "Why 10s for auth?" — a codex login status that legitimately takes 6s over a slow link must not be misreported as unauthenticated; 10s bounds the hang while leaving real headroom. And "is the wall-time assertion flaky in CI?" — the bound is 2× the timeout, and the integration project runs fileParallelism: false.

    Feature Quality Planning

    Sibling-site scan

    doctor.ts has a fourth un-timed execSync and there is one in an adjacent module. Neither is silently pulled in:

    • doctor.ts:207 — git log --oneline --grep=…, run once per closed issue in a loop. Local git, so low hang risk, but it is the same pattern in the same file and one extra line to fix. A 4th timeout: still satisfies AC-1's "3 or more". → Open Question 1.
    • src/lib/workflow/platforms/github.ts:136 — execSync("gh auth status"), un-timed and network-reaching, called by doctor's own GitHub check. This is the exact failure class AC-3 fixes for codex, just one layer down, and GitHubProvider owns gh. → recommended follow-up issue, not in-scope here.
    • system.ts:18 (command -v, shell builtin) and aider.ts:166 (which) are not worth changing.

    Open Questions

    1. Also timeout doctor.ts:207 (git log) in this PR? — Recommendation: yes, one line, same file, same pattern, AC-1 still satisfied. Impact if wrong: a hung local git still hangs doctor, just via a less likely path.
    2. AUTH_PROBE_TIMEOUT_MS = 10_000 — right bound? — Recommendation: keep 10s. Impact if too short: a slow-but-working network login reports "not authenticated" and prints a misleading hint. Lowering it to 5s would shave ~5s off the suite, which is not worth a false negative.
    3. File the gh auth status follow-up now? — Recommendation: yes, one issue, linked here.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: SCOPE_OK, 6 tight evidence-bearing ACs, ~15 lines of source plus tests. testgen is deliberately skipped even though AC-2/5/6 declare unit/integration evidence: here the tests are the deliverable and are already specified down to the stub script and the assertion bounds, so generated stubs would be overwritten immediately — and /testgen has a record of leaving orphan stubs behind. No UI, so no test phase; no auth/secret surface beyond the existing CODEX_API_KEY non-logging assertion, so no security-review.

    Label Review

    Current: (none)
    Recommended: planned, cli, no-browser-test
    Reason: CLI-surface chore with no UI; no-browser-test makes the skipped test phase explicit rather than inferred.
    Quality Loop: Won't auto-enable — SCOPE_OK.

  3. added
    planned
    cli
    no-browser-test
    on Sep 18, 2026
  4. admarble commented on Sep 19, 2026

    @admarble
    ContributorAuthor

    Runner note (2026-09-18) — §6i blocker resolved in the PR body

    QA's AC_NOT_MET was driven by the two SEQUANT_MUTATION markers in PR #1091 lacking the <file> > prefix. Rewrote both failedTest values in the PR body (no code change):

    • AC-2 → src/commands/doctor.integration.test.ts > doctor probe timeouts (#1075) — all 3 cases
    • AC-5 → src/lib/templates.test.ts > templates > templateDestination > returns null for templates/codex/** (#1075)

    Re-ran §6i's parseMutationMarkers(prBody, diffTestFiles) against the live body: AC-2 valid, AC-5 valid (the original body reproduces test_not_in_diff for both, so the finding was real). All six AC evidence commands re-run by the runner in the worktree: AC-1 4, AC-2/3/4 3 passed, AC-5 1 passed, AC-6 1 passed.

    Still open from the PR body: three unidentified full-suite failures; the runner is settling them against main now. github.ts:136 follow-up left for the human to decide.

  5. admarble commented on Sep 19, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 0/2 met

    Gaps:

    • The cross-file sibling of this PR's defect class is correctly scoped out but the promised follow-up issue was never filed
    • AC-6's trailing 'value never logged' assertion is non-failable as written, though the claim is genuinely covered by the sibling 1059 AC-4c case at doctor.test.ts:627
    • Unrelated CHANGELOG reformatting widens the diff and invites conflicts with concurrent CHANGELOG edits
    • AC-6's "value never logged" assertion is weak (detail below) — the short-circuit half it was commissioned for is sound.

    Suggestions:

    • File the gh auth status follow-up the PR body promises.
  6. added a commit that references this issue on Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clino-browser-testplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions