Skip to content

test: stop CI timeouts and keep the suite out of the real home directory - #160

Merged
royosherove merged 3 commits into
mainfrom
fix/flaky-telegram-split-timeout
Nov 22, 2026
Merged

royosherove merged 3 commits into
mainfrom
fix/flaky-telegram-split-timeout

Conversation

@royosherove

@royosherove royosherove commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

This PR has two test-only fixes. Production behavior is unchanged.

1. Generated-document tests timing out on slow CI

Problem

CI "Test" failed on main (ef28d1d, v0.7.0). telegram-split.test.ts > generated documents > covers what it claims to… hit vitest's default 5000 ms timeout. Locally, with the full suite running in parallel, two more timed out the same way: holds its properties for 400 documents (5714 ms) and telegram-delivery > a table that is being streamed… (5540 ms).

Root cause

These tests are slow because each one loops over hundreds of generated documents. They are not hanging. They take 1–3 s on an idle machine and over 5 s on a loaded one, so the default timeout fails them for speed alone.

I profiled splitMarkdownForTelegram and found nothing super-linear. Each chunk only scans limit plus 3 lines (reach). The binary search costs about 7.6 renders per chunk (14,253 probes for 1,866 chunks over 400 docs), and only 85 of those repeat, so memoizing would save nothing. A single-pass escapeHtml gave the same output (hash checked over 1,200 docs × 4 limits) but was only about 5% faster, within noise, so I left it out. Cutting the number of probes would mean bounding the search by HTML length against source length, and that relationship isn't monotone. That isn't a safe change.

Change

Only tests change. The 9 heavy generated-document tests get GENERATED_DOCS_TIMEOUT_MS = 60_000: the 3 in telegram-split.test.ts and 6 in telegram-delivery.test.ts. Seed counts and assertions are unchanged.

Timings (slowest tests)

test idle, file alone full suite parallel (before) full suite, taskset -c 0 + busy loop (after)
split: 400 docs at 4096 3110 ms 5714 ms, timed out 4835 ms ✓
split: covers what it claims 1806 ms 3973 ms 3824 ms ✓
split: 150 docs smaller limits 800 ms 2241 ms 1798 ms ✓
delivery: streamed table fills a message 3286 ms 5540 ms, timed out 5214 ms ✓
delivery: 120 docs with tables 848 ms 2208 ms 1856 ms ✓

Checks

  • npm ci ✓
  • npm run typecheck ✓
  • npm test ×3 ✓ (64 files, 884 tests each)
  • single-core throttled full run ✓ (884/884)
  • npm publish --dry-run: packs 154 files, then exits with "cannot publish over 0.7.0". That's expected because the version isn't bumped. Not caused by this PR.

2. The suite was not hermetic: it wrote into the real ~/.roundhouse

Problem

On a machine where the suite had already run once, the next run failed:
telegram-setup.test.ts > TelegramAdapter.handlePairing > isPairingPending returns false when no pairing file exists (expected true to be false). CI passed only because its home directory is fresh. Reproduced by running vitest run twice with the same HOME: the first run passed 884/884, the second failed this test.

Root cause

src/config.ts computes ROUNDHOUSE_DIR = resolve(homedir(), ".roundhouse") at import time, and PAIRING_PATH, CRON_JOBS_DIR etc. derive from it. Nothing in the test setup redirected the home directory, so tests wrote telegram-pairing.json, soul.md, tools.md, user.md, crons/, memory-state/, active-topics.json and logs/ into the real ~/.roundhouse (plus ~/.pi/agent and ~/.mcporter). The pairing tests set process.env.ROUNDHOUSE_DIR to a temp dir, but config.ts never reads that variable. They believed they were isolated but were reading and writing the real pairing file, so one run's leftover file failed the next run.

Change

  • vitest.config.ts (new):
    • test/setup/global-home.ts (globalSetup) points HOME/USERPROFILE at a temp root for the whole run, so worker processes and any processes the tests spawn inherit it. It is removed at teardown.
    • test/setup/isolate-home.ts (setupFiles) gives every test file its own empty HOME before the test file or any src module is imported. It is removed in afterAll.
  • test/telegram-setup.test.ts: the pairing tests isolate through HOME + vi.resetModules() instead of the ignored ROUNDHOUSE_DIR variable. Assertions are unchanged.
  • src/cli/subagent-command.ts: uses ROUNDHOUSE_DIR from config instead of its own copy.
  • No ROUNDHOUSE_DIR env override was added. Several production paths (telemetry, kiro sessions, the sub-agent orchestrator, whisper, /later, doctor) build ~/.roundhouse from homedir() themselves, so an override that only some of them honored would be a trap for users.
  • A follow-up commit removes a stray .local/share/vitest/.vitest-secret-token that was committed by mistake (from a local run with an empty HOME; it is a throwaway local vitest API token, now deleted) and adds .local/ to .gitignore.

Checks

  • ~/.roundhouse did not exist before the runs and still does not after them.
  • ~/.pi, ~/.mcporter, ~/.local/share/vitest: no files modified during the runs.
  • npm test ×3 in a row with the real HOME: 64 files / 884 tests passed each time.
  • The suite also passes with HOME set to a home already polluted by the old code (stale telegram-pairing.json etc.): 884/884.
  • npm ci ✓, npm run typecheck ✓, npm pack --dry-run ✓ (154 files; no test or vitest config files in the package).

The tests that loop over hundreds of generated documents took 2-3 s on a
fast machine and over 5 s on a loaded one, so vitest's default 5 s timeout
failed them for speed alone (CI on ef28d1d; locally two of them timed out
when the whole suite ran in parallel).

Give the nine heavy generated-document tests in telegram-split and
telegram-delivery an explicit 60 s timeout. Seed counts and assertions are
unchanged. The splitter itself is linear (about 7.6 renders per chunk from
its binary search), so there is no performance fix to make in format.ts.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T07:08:19.416407Z de6cfd3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The suite wrote into the real ~/.roundhouse (telegram-pairing.json,
soul.md, tools.md, crons/, memory-state/, active-topics.json, logs/),
so on a machine where it had run once the next run failed:
"isPairingPending returns false when no pairing file exists" found the
pairing file a previous run left behind. CI passed only because its
home is fresh. That test set process.env.ROUNDHOUSE_DIR, which
config.ts never reads, so it was writing to the real home all along.

- vitest.config.ts: a global setup points HOME/USERPROFILE at a temp
  dir for the whole run (spawned processes inherit it), and a setup file
  gives every test file its own empty HOME before any src module is
  imported; both are removed afterwards.
- telegram-setup.test.ts: the pairing tests isolate through HOME instead
  of the ignored ROUNDHOUSE_DIR variable.
- subagent-command.ts: use ROUNDHOUSE_DIR from config instead of its own
  copy.

Production behavior is unchanged.
A local run with an empty HOME made vitest write .local/share/vitest/.vitest-secret-token inside the repo, and it was committed by mistake. The token is a throwaway local vitest API token; the file is deleted on the machine that made it, so the token is no longer used.
@royosherove royosherove changed the title test: stop telegram-split generated tests timing out on slow CI test: stop CI timeouts and keep the suite out of the real home directory Nov 22, 2026
@royosherove
royosherove merged commit 15594b4 into main Nov 22, 2026
1 check passed
@royosherove
royosherove deleted the fix/flaky-telegram-split-timeout branch November 22, 2026 07:08
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.

1 participant