compound-engineering-plugin icon indicating copy to clipboard operation
compound-engineering-plugin copied to clipboard

tests: ce-work-cross-model-integration flakes on main (serial transaction tests fail nondeterministically)

Open khsaurabh opened this issue 2 months ago • 2 comments

tests/skills/ce-work-cross-model-integration.test.ts flakes on main — which test fails varies by environment, so this looks like a shared timing/state dependency across the serial-transaction tests rather than one bad assertion.

Reproduction (pristine main, commit at the time of writing, no local changes):

  • Linux, bun 1.x: bun test tests/skills/ce-work-cross-model-integration.test.ts fails 2/2 runs in same-base disjoint wave terminalizes together and lands as separate controlled host commits (peer_job_runner wait returns failed where done is expected, the same expect(...).toBe("done") shape as the CI failure below).
  • GitHub Actions test job (ubuntu) on a PR whose diff touches only ce-plan markdown and its contract test failed instead in ce-work serial cross-model transaction > scope expansion remains a successful detached result for host inspection — same file, same wait -> "failed" signature: https://github.com/EveryInc/compound-engineering-plugin/actions/runs/33956247463/job/101280011018

Since the failing PR diff cannot influence ce-work integration machinery (docs-only change), and main fails locally on a sibling test in the same file, the flake lives on main. I have not root-caused it; happy to dig in and send a fix if the maintainers want one.

khsaurabh avatar Sep 05 '26 08:09 khsaurabh

We ran a multi-day investigation of this flake on our fork's CI and have both a captured evidence chain and a defensive fix landed (happy to upstream the patch).

Signature: wait receives "failed" (~1.4s into the test) instead of "done" in tests/skills/ce-work-cross-model-integration.test.ts; the supervisor classifies it as worker exited 1.

Captured causal chain (from preserved job artifacts, not logs alone):

  1. Supervisor records worker exited 1 (peer-job-runner.py:1213).
  2. The adapter's normalizer judged the result schema invalid (cross-model-work.sh:981) and published failure_reason: "terminal output failed implementation result schema" — a string unique to that path.
  3. result.raw, stdout.log, stderr.log — the adapter scratch captures — were all ENOENT at the adapter's read, minutes-old.
  4. The paradox that pins it: ROUTE_EXIT==0 is proven by the receipt's own content (a non-zero exit takes the publish_unavailable path with different strings). Exit 0 means the exec ... > stdout.log 2> stderr.log redirections succeeded and created the files — so freshly-written files vanished within ~50ms of the route's exit, outside the process tree. In-process deleters are excluded: EXIT-trap inheritance tested across bash/sh/zsh (files survive), a repo-wide grep finds no /tmp cleaner, and signal-class kills would leave exit codes 127/137/143 with distinct symptoms.
  5. Corroborating observation: the same runner fleet exhibits ~25-minute IO stall windows — every test in the file times out at exactly 30001ms on git add . with empty stdout/stderr while sibling files run 10x slower, then the window self-heals. Same host-filesystem-pathology family.

Fix (landed on our fork): move the adapter scratch out of the world-shared /tmp root into the controller-owned unit tree — units/<unit>/adapter-scratch/, a sibling of result/, which is already supervised, 0700, and cleaned up with the run. This eliminates the entire class of external interference without needing to identify the deleter. mkdir failure falls back to the old location (logged, so the fallback is observable); mktemp failure still exits 2. A regression assertion pins the new location.

Statistics: ~1 hit per ~41 full-suite repro rounds in calm conditions; ~50% of first-run test jobs during one congested midday window, then 0/12 in the identical window the next day (one-off fleet event, not time-of-day). Synthetic load produced 0/8 hits — not load-correlated.

Defense-in-depth note: 19+ other mktemp "${TMPDIR:-/tmp}/..." sites across skill scripts share the same exposure on a transiently hostile /tmp; we plan to follow up on those separately and can report back.

chouti avatar Sep 29 '26 07:09 chouti

Thanks for the thorough write-up, @chouti.

This doesn't reproduce on current main. tests/skills/ce-work-cross-model-integration.test.ts passed 30/30 locally, 24 of those at 4-way concurrency. Since #1843 merged on Oct 7 there have been 443 green CI runs, and none of the failed test jobs in that window failed in this file.

#1843 rewrote the route and output parsing in cross-model-work.sh along with this test, so the lines and the terminal output failed implementation result schema path from the report are gone.

On the scratch move: the adapter still puts its scratch under $TMPDIR, but nothing in the repo sweeps it, and our CI runs on fresh GitHub-hosted VMs that don't share /tmp. The IO stalls and the 50%-one-day, 0/12-the-next pattern look specific to your runners, so I'm not taking the move upstream.

Closing this. If it shows up again on current main, please open a new issue with the failing run.

tmchow avatar Nov 11 '26 01:11 tmchow