Files
deepseek-harness/docs/rfc/proposed/testing/2026-06-11-deterministic-and-stress-testing.md
T
Ziya 2565133af3 docs(i18n): RFC tree batch — 146 bilingual pairs via the committed pipeline
implemented(除 4 篇超长文档随后补)、proposed、rejected 全树配对;
同一流水线 + 二遍校验(paraphrase-back + 仓库上下文一致性)产出。
docs/rfc/implemented/AGENTS.md 与其 CLAUDE.md 符号链接列入排除
(agent 指令文件,与根 AGENTS.md 同策略)。
2026-07-15 23:25:06 -07:00

2.2 KiB

RFC: Deterministic tests, the replay invariant fixture, and race stress

English | 中文

Status: proposed

Problem

Several loop tests synchronize with setTimeout(30) sleeps — flakiness debt that wastes agent cycles on retries and can mask ordering bugs. Separately, our core architectural promise (any session log replays to identical derived history) is asserted in two tests but is cheap to assert everywhere. And the inbox wakeup race was verified by hand exactly once; nothing re-verifies it continuously.

Proposal

Three measures:

  1. No wall-clock sleeps in tests. Replace setTimeout(N) waits with event-driven waits (the existing waitForIdle pattern, extended to waitForStatus, waitForEvent(n)) or vitest fake timers where time itself is under test. Enforce with a lint rule banning setTimeout in packages/*/tests outside an allowlisted helper module.
  2. Universal replay fixture. A shared test helper wraps the loop harness so that after every test, the agent's session log is replayed into a fresh Session and deriveMessages() equality is asserted automatically. The invariant then gets checked hundreds of times per CI run across every scenario the suite produces, not twice.
  3. Nightly race stress. A CI job running the agent-loop and inbox suites with vitest --repeat=200 (and --shuffle) to flush scheduling-dependent failures; any flake found is a bug to fix, never a retry.

Plan

Land 1 and 2 together (they touch the same helpers); add the nightly job after the suite is sleep-free so repeats are fast.

Acceptance criteria

  • No setTimeout remains in packages/*/tests outside the allowlisted helper module, enforced by the lint rule.
  • The shared harness replays every test's session log into a fresh Session and asserts deriveMessages() equality automatically, across the whole suite.
  • The nightly job runs the agent-loop and inbox suites with --repeat and --shuffle; a flake it finds is triaged as a bug, never retried away.

Risks

Fake timers interact subtly with Promise scheduling in the loop — prefer event-driven waits; reserve fake timers for timer-service behavior itself.