Skip to content

test: stop three tests from racing a tiny real-clock budget - #22767

Merged
Git-on-my-level merged 1 commit into
mainfrom
lessons/real-clock-tests
Oct 20, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
lessons/real-clock-tests

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Three backend unit tests depended on a tiny real wall-clock budget, so they flaked on loaded CI runners. This finishes the flake class that #22758 fixed for five sibling tests (lessons/batch-rollout-and-staging-traps.md #15).

  • test_terminal_cleanup_deferral_inherits_the_recovery_deadline used a 0.05s handler budget and staged its outcome by counting job reads. An 80ms stall in the attempt's read let the budget expire before the pipeline ran, and the replacement enqueue was never called (reproduced locally). It now uses feat(deploy): build-only mode in gcp_backend.yml for listen-only rollouts #22758's _pipeline_expiring_the_handler_budget, which keeps the production budget and expires it inside the pipeline stub. It passes with an 80ms stall on each of reads 1–3. The inherited recovery deadline, which is what the test asserts, is unchanged.
  • test_hung_fetch_has_own_deadline_and_other_results_survive (Parakeet pressure, 20ms) and test_per_user_budget_exceeded_is_recorded_and_skipped (daily summary, 50ms) needed healthy work to finish inside the budget. Both now use 0.5s. The hung or blocked case still times out, and each test takes about 0.5s longer.
  • The other 0.05s handler-budget tests in test_sync_cloud_tasks.py stage only queued and processing reads, so where the expiry lands does not change their branch. They are left as they are.

Test-only; production code is unchanged.

Lane / contract

lessons-audit (two-lane/legacy-retire lead). Not a swarm lane file. integration/legacy-retire picks this up at its next main sync.

Product invariants affected

none

Verification

Unit layer, m5, BACKEND_UNIT_TEST_FILE_LIST + backend/test.sh (nice 19):

  • test_sync_cloud_tasks.py (186 passed), test_parakeet_batch_pressure.py and test_daily_summary_job_resilience.py (35 + 42 passed);
  • before the change, the target test failed with an injected 80ms read stall; after it, the test passes with stalls on reads 1–3 (the injection was temporary and is not committed).

Rollback

Revert the commit (tests only).

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

#22758 moved five direct-delivery budget tests off a 0.05s real handler
budget. test_terminal_cleanup_deferral_inherits_the_recovery_deadline still
used it, and it stages its outcome by counting job reads (read 4 is the
terminal one). An 80ms stall in the attempt's job read lets the budget
expire before the pipeline runs. The recovery then never reaches its terminal
read and the replacement enqueue is never called. Reproduced locally with
that stall; with this change the test passes with the stall on reads 1-3.
It now uses #22758's _pipeline_expiring_the_handler_budget, which keeps the
production budget and expires it inside the pipeline stub. The inherited
recovery deadline (now + the 0.2s cleanup timeout) is unchanged.

The same class, in the opposite direction: two tests require healthy work to
finish inside a tiny real budget. Parakeet pressure used a 20ms per-request
timeout and daily summary a 50ms per-user budget. Both now use 0.5s; the hung
or blocked case still times out.

The other 0.05s handler-budget tests in test_sync_cloud_tasks.py stage only
queued and processing reads, so where the expiry lands does not change their
branch. They are left as they are; that file goes away with the legacy
deletion (lane 10).

Test-only; production code is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T05:21:50.806595Z 8aa635a PR opened
ℹ️ 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.

@Git-on-my-level
Git-on-my-level merged commit 31a0723 into main Oct 20, 2026
62 checks passed
@Git-on-my-level
Git-on-my-level deleted the lessons/real-clock-tests branch October 20, 2026 05:33
Git-on-my-level added a commit that referenced this pull request Oct 20, 2026
* test(backend): ratchet tiny real-clock budgets in tests

Three times on 2026-10-20 a backend unit test that shrank a production
budget to tens of milliseconds raced a loaded CI runner (#22758, #22767,
and the legacy-retire change C10). Add a static AST ratchet over
backend/tests/**/*.py that flags budget/deadline/timeout names set to a
literal in (0, 0.5) s via attribute assignment, setattr/patch.object/
patch, setenv/os.environ/patch.dict, or keyword arguments to code under
test. Harness waits (wait_for, Event.wait, get, join, ...), mock call
assertions, and functions that control the clock are excluded.

The 100 current offenders are allowlisted with a blame owner and #22767;
the test fails on new offenders and on stale entries so the list only
shrinks. It is a codebase scan, so it is marked slow and listed in
tests/slow_guardrail_manifest.txt (~0.45 s).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): close real-clock ratchet gaps from review

Grok review (FIX-FIRST) found four gaps:
- `'monotonic': time.monotonic` counted as a fake clock and exempted six
  real-clock ack-budget tests in test_listen_pusher_session.py. Only a
  clock replaced by something other than time.* / None counts now, and
  decorators are part of the inspected source. The six sites are
  grandfathered (106 entries).
- patch.object(obj, 'NAME', new=v) was not read.
- The byte prefilter missed parenthesized, ' +0.05', and 1_0e-2 values.
  It is possessive now so whitespace runs cannot backtrack.
- patch.dict('os.environ', ...), patch.dict(..., NAME='0.05') and
  values={...} were not read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): real clock passed via new= or parens is not a fake clock

Grok r2: the optional `new=` introducer could be skipped so the
lookahead tested `new`, and `(time.monotonic)` slipped past it, so
`patch.object(obj, 'monotonic', new=time.monotonic)` still exempted
the function. Introducers (`new=`/`value=`, parentheses, whitespace)
are now consumed possessively and also rejected by the lookahead.
Self-tests cover both real-clock spellings and a fake `new=` clock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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