Skip to content

fix(tests): the knowledge base metadata test fails when the machine is busy because it asserts elapsed wall-clock time #1825

Closed

Description

@dan-petty

tests/test_kb_manuals_metadata.py::test_offline_speed_under_one_second asserts that three calls finish within one second of wall-clock time. It failed in a pre-push gate with KB metadata operations took 1.00s (exceeded 1.0s limit), in a run where 1 test failed and 11,321 passed. The gate shared the machine with two other gates and several test runs (load average 43), so the 1.0 s limit measured the load and not the code. The same push passed once the load fell.

The assertion adds nothing the rest of the test does not already check. "Offline" is guaranteed by the hermetic floor, which refuses every network socket and every program but git in tests, so a call that reached the network would fail on its own. The test then asserts that matched and drifting manuals are found and that filtering keeps one; those assertions stay. A wall-clock bound is the shape of check the project has already removed elsewhere (#1725, "tests never hit DNS/network") and fails on a busy runner or a busy workstation.

Remedy: delete start, elapsed and the assert elapsed < 1.0 line, the time import if nothing else uses it, and "in <1s" from the docstring. Search tests/ for other perf_counter or time.time() bounds with an assert ... < on elapsed time and decide each on the same ground: the floor, not a stopwatch, proves a test is offline.

regression of #1664, shipped in v0.2.37


Second test (folded in by the intake duplicate check on 2026-10-22)

Problem

tests/test_ui_reactive.py::test_quitting_does_not_wait_on_a_silent_log_stream asserts that quitting the dashboard takes less than 5.0 seconds of wall-clock time. On a busy machine the quit took 5.6 seconds, and the test failed with quitting took 5.6s while a stream was open. The same test passes in 1.7 to 3 seconds on its own. The bound measures the load of the machine, not a hang.

Evidence

Remedy

The test must prove that quitting does not wait for the silent stream, without a tight wall-clock bound. For example, quit while the stream is blocked and assert that the application stops before the stream is released: the event release is still unset when the application has stopped. A hang then fails the test through the generous per-test timeout, and a slow machine does not fail it. The test must still fail if the quit waits for the stream thread. Show this with a mutation of the production code or with a copy of the old behaviour.

Activity

  1. added
    source/agent
    type/test
    on Oct 22, 2026
  2. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/test. The candidate is about fixing a test that fails under load due to time assertions.
    • Priority: P2-Medium. This is a test reliability issue, not a critical bug or feature.
    • Value: Medium. Improves test stability under load which benefits CI/CD and developer experience.
    • Effort: Low. The fix involves removing a few lines of code and assertions.
  3. added this to the v0.2.39 milestone on Oct 22, 2026
  4. added a commit that references this issue on Oct 22, 2026
    75071b0
  5. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1896, merged into release/v0.2.39 as 75071b0.

    Cause: Two tests asserted elapsed wall-clock time. test_offline_speed_under_one_second asserted elapsed < 1.0, and test_quitting_does_not_wait_on_a_silent_log_stream asserted elapsed < 5.0. A busy host measures the wait for a CPU, so both failed in pre-push gates with correct code: 1.00 s, 1.03 s and 1.49 s for the first test, and quitting took 5.6s for the second. docs/TESTING.md already says that no test asserts on elapsed wall-clock time. Alone, under a load average of 26, the first test body takes 0.26 s and the second takes 1.4 to 2.0 s.

    Change: The knowledge base metadata test loses its clock reads, its assertion and import time, and it is renamed test_floor_only_environment_matches_and_drifts_manuals_and_filtering_keeps_some. The hermetic floor already proves that the test is offline, because it refuses every network socket and every program but git. Every other assertion of the test stays. The quit test now reads no clock. Its silent stream waits on release for twice THREAD_HANDOFF_BOUND_SECONDS, and it sets hold_ran_out if it gives up by itself. After the application shuts down, the test asserts that release and hold_ran_out are both unset. A quit that does not wait for the stream ends with the stream still held. A quit that waits ends only when the hold runs out, and the test then fails. The task file docs/agent/tasks/task-1825-kb-metadata-test-asserts-no-wall-clock-time.md and the fragment changelog.d/1825.md are included.

    Tests: The…

    4 file(s) changed.

    How it was verified

    Check runs at d1304e8:

    • Prune PR DevContainer Images: pending
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Fail-to-Pass Check: pass
    • Rule Pack Tests: pass
    • Changed-Test Independence: pass
    • Fail-to-Pass Self-Check: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1825-kb-metadata-test-asserts-no-wall-clock-time.md:

    • The knowledge base metadata test has no clock read and no assertion on elapsed time, and every other assertion of it stays.
    • The name of the knowledge base metadata test does not say "speed" or "one second". Nothing else in the repository names the old test.
    • The quit test has no clock read, no bound of 5 s and no "5" as a bound in its docstring.
    • The quit test fails when the production code waits for the stream thread on quit, shown by the mutation above.
    • uv run devops ci test tests/test_kb_manuals_metadata.py tests/test_ui_reactive.py passes.
    • Fail-to-pass: not applicable. The change removes wall-clock assertions, and the production code is correct.
  6. added a commit that references this issue on Oct 23, 2026
    f209f6c
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

    source/agenttype/test

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions