Skip to content

fix(tests): three more causes of the red Tier 3 night are test defects — a shared ask queue, a unit test in the live tier, three stale assertions (#4620) - #4805

Merged
pavshulin merged 1 commit into
devfrom
feature/4620-tier3-stale-tests
Nov 27, 2026
Merged

pavshulin merged 1 commit into
devfrom
feature/4620-tier3-stale-tests

Conversation

@pavshulin

Copy link
Copy Markdown
Contributor

Description

The nightly Tier 3 run on dev is red (#4620). #4788 takes two of its seven causes. This PR takes three more: causes 6, 3 and 5 of the table in #4620, numbered 1 to 3 below. All three are defects of the tests, not of the product. The PR changes tests and adds one learnings note; no product code changes.

1. One agent's ask queue shared by a whole module (unit job, 4 tests per red seed).
tests/unit/test_ent1109_credential_handover.py raises every ask for one agent, in a database that outlives the test. TestDelivery leaves 18 asks pending and TestTheAsk raises 11, against a cap of 25 pending asks per agent. In file order TestTheAsk runs first and never meets the cap. In a shuffled order the next raise is refused with queue_full: four tests on each of the night's two red seeds (67890 and 99999), a different four on each.

2. A unit test that ran in the live tier (7 tests).
tests/test_cb_probe_execution_close.py needs no stack, but it sat in tests/ root, where only the live-tier jobs collect it. It stubbed database, utils.helpers, redis and more into sys.modules with setdefault, which keeps whatever an earlier-collected file left there. In the live selection that is tests/git_sync/test_s5_conflict_classifier.py's load-time database stub, whose db is None. Every service execute_task reaches was then bound to None, and the seven tests died on 'NoneType' object has no attribute 'get_setting_value' before they reached the circuit breaker or the cancel handler. Alone, the module passes.

  • The module moves to tests/unit/ and loses its own stubs: there the conftest provides the real database on a per-process file. The ten tests and their assertions are unchanged.
  • It imports the service once at collection, so the service's collaborators are bound to that database. Without the import, five other unit files, each run directly before this one in a two-file run, left their own database double bound into settings_service and reproduced the same seven failures. A whole-suite run never showed that, because collection imports the service first.
  • It was in the root for two reasons that no longer hold. bug: 108 test files sit in tests/ root, where no CI job runs them #1895 moved the self-contained root tests and left this one behind because it was red at the time: against bug: recovery paths write execution terminals without closing the paired activity — agent shows as running for up to 2h, then logs a fabricated 120-min failure #1804 (a mock that was never updated), and on a seed-dependent ImportError from the module's own sanitizer stub. bug: stale test mocks drifted from #1804, #2015 and ent#237 — 9 failures of lost coverage #2242 fixed the first the next day, and the stub is gone with this PR. The move never followed.
  • The per-PR unit job now runs it. tests/registry.json and the sys.modules baseline follow the move, as do two one-line mentions of the file: the header text tests/lint_root_test_placement.py writes into its baseline, and a path in a docstring of tests/unit/test_terminal_write_cas_gate.py. The root-placement baseline goes 10 → 8: this module left, and test_public_links.py now takes a live fixture, so it no longer needs the exemption.

3. Three assertions that described the product as it used to be (3 tests).

Not in this PR

Related Issue

Refs #4620

No closing keyword, for the reason #4788 gives: #4620 is the nightly's own tracking issue, dev-nightly.yml closes it on the first green night, and after this PR the night is still red on the 11 tests above.

Journey Impact

Journey Impact: none: test fixtures and assertions, one test module moved between test tiers, two lint baselines, the test registry and one learnings note; no product code and no journey promise changes

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Testing

  • I have tested this locally
  • New tests added (if applicable)
  • All existing tests pass
  • Every new test executes the changed path

No new tests: every change is to an existing test. Each one was seen red for the stated reason first. The branch is based on 30ce96ecb; the diff also applies cleanly on dev at 85dd5d143 (two commits later, one of which edits the service these unit modules drive), and both unit modules pass there. It also merges cleanly onto 9ddef927e, one commit later, which touches none of the files involved.

Cause 1 (ask queue).

Run Base This PR
The module alone, seed 67890 4 failed, the same four as the night 74 passed
The module alone, seed 99999 4 failed, the same four as the night 74 passed
TestDelivery then TestTheAsk, no shuffle 3 failed, queue_full 59 passed
Seeds 12345, 20261126, 1 (12345 was green at night) 74 passed each

A probe that counts the agent's pending asks before each test shows the count reach 25 and the next raise fail.

The same four tests are red in CI for seed 99999 outside the Tier 3 job too: backend-unit-nightly, run 45861192007 (2026-11-26), AskRejected: queue_full.

Cause 2 (the moved module).

Run Result
The module alone in tests/ root 10 passed
git_sync/test_s5_conflict_classifier.py + the module, in root 7 failed, the night's seven, same message
Moved, alone, file order and seeds 67890, 99999, 12345, 20261126, 7 10 passed each
Moved, row count of all 100 tables of the unit database before and after unchanged

Stubbing the collaborator the traceback names does not fix it in place: the next one fails on the same None (tried three in a row), which is why the module moves instead.

Pair sweep: the moved module run directly after each of the 80 unit files that write database into sys.modules or name it in a stub mapping (grep -lE "sys\.modules, *[\"']database[\"']|sys\.modules\[[\"']database[\"']\]|setdefault\([\"']database[\"']|[\"']database[\"']: " unit/*.py, minus the module itself). Before the collection-time import, 5 of the 80 pairings failed its seven tests; with it, none of the 79 that can run does. The 80th file does not collect by itself in my environment, at the base commit too.

Whole unit suite with the nightly's unit command (--dist loadfile -p randomly --randomly-seed=…, 8 workers where the workflow says -n logical), base against this PR on the same machine:

Seed Base This PR Red here, not red at base Red at base, green here
12345 (the seed the per-PR job runs) 44171 tests, 13 red 44181 tests, 14 red 1, a timing check (below) none; cause 1 does not show on this seed
67890 44171 tests, 18 red 44181 tests, 18 red 4 signal tests of my launcher (below) the 4 TestTheAsk tests
99999 not run 44181 tests, 18 red the same 18 as on 67890 the cause 1 module: 74 passed
  • The 10 extra tests are the moved module. All ten pass in every run.
  • 14 tests are red for reasons of my environment, in both trees: 12 call git ls-files in a copy without .git, and two are timing checks that come and go. The four files those 12 belong to pass on the real checkout of this commit (68 passed). One of those two is the single difference in the 12345 row (test_ent1176_managed_hooks::test_a_same_size_rewrite_with_its_mtime_restored_is_read_again); it was red at base under seed 67890. The only other status change on that seed is a test_2742_git_status_lock_free witness that went from passed to skipped: it skips by design when its control arm does not reproduce a lock race in that run.
  • The 67890 and 99999 runs of this PR were started detached (nohup … &), which leaves SIGHUP and SIGINT ignored. Four tests of test_ent1094_marketplace_release.py send those signals to a shell script and fail under that launcher; the same module is 142 passed when started in the foreground on the same tree. A foreground run of this PR on 67890, made before the last review edits, had exactly the 14.

Cause 3 (stale assertions), live, on a stack booted the way dev-nightly.yml boots it (PostgreSQL, placeholder model key):

Test Base This PR
test_generate_returns_501_without_gemini_key failed: 'GEMINI_API_KEY' in "Avatar generation isn't configured…" passed
test_reset_restores_default_values failed: execution_log_retention_days should be at default after reset passed
test_chat_without_email_requirement failed: 401 Session token required for this link skipped: the 401 is gone, the chat reaches the model turn and answers 502 without a key. Pass not observed.

The whole live selection (-m "not slow" --ignore=unit) on a tree with this PR and #4788 together:

Run Result
#4788 alone, 2026-11-25 16 failed, 1884 passed, 119 skipped, 7 errors (23 red)
#4788 + this PR, 2026-11-26 6 failed, 1928 passed, 118 skipped, 5 errors (11 red), in 38:26

Compared test by test:

  • The 11 red are the placeholder-key tests (10: four journeys, six in test_parallel_task.py) and the duplicate-subscription 500 (1). Nothing went from pass to red.
  • Red to pass: the avatar and settings tests (2). Red to skipped: the public-chat test (1). Left this tier: the ten test_cb_probe_execution_close.py tests (7 red, 3 passing).
  • The two CLI modules did not collect in the earlier run, because my environment lacked the CLI package then. They collect now: 43 tests, all pass.
  • Two tests of test_operator_queue.py went from skipped to pass (test_get_existing_item, test_respond_to_pending_item). They skip when the stack's queue happens to be empty; nothing in this PR touches them.
  • That accounts for the totals: passes +43 +2 +2 −3 = +44, skips +1 −2 = −1.

The live run was made before the last three edits to test_settings.py and test_public_links.py (the stored-row check, two skips turned into assertions). Those two classes, with the file's other policy classes, were rerun on the same stack afterwards: 12 passed, 1 skipped.

Mutation, each made in a scratch copy and run against the changed unit tests. Each of the moved module's ten tests goes red under at least one:

  • The breaker never counts as open (transport_open = False) → the three test_cb_open_* tests fail.
  • The breaker always counts as open → test_cb_closed_proceeds_normally fails.
  • execute_task's cancel handler no longer matches (except GeneratorExit:) → test_cancelled_error_marks_execution_failed fails.
  • That handler writes over a row that is already terminal → test_cancelled_error_skips_already_terminal_execution fails.
  • That handler swallows the cancel (return where it re-raises) → all three TestCancelledErrorInExecuteTask tests fail, test_cancelled_error_is_reraised among them.
  • The same three edits in the background wrapper → test_background_cancelled_marks_execution_failed, test_background_cancelled_skips_already_terminal, and all three TestCancelledErrorInBackground tests, in that order.
  • The queue clear removed from the fixture → the fixed-order run fails again (3 × queue_full).
  • The collection-time import removed → the seven fail again after test_backlog.py.
  • A no-op edit as control → 10 pass.

The three live tests cannot be mutated without rebuilding the stack; their red state is the base run in the table above.

Lints: tests/lint_sys_modules.py and tests/lint_root_test_placement.py pass; their own unit tests pass (51). #4788's diff applies cleanly on top of this one and its seam guard passes with both applied.

"All existing tests pass" is left unticked: the whole unit suite ran in an environment where some tests fail for reasons of that environment (above), and the live selection stays red on the 11 tests listed under "Not in this PR".

Checklist

  • My code follows the project's style guidelines
  • I have updated the documentation (if applicable)
  • I have not committed any sensitive data (API keys, credentials, etc.)
  • My commits are signed off (git commit -s) — required for contributors outside the core team
  • If this PR was written with an AI assistant, I say so above, and I have read and can explain every line
  • I have added appropriate logging for new functionality

Written with Claude Code.

🤖 Generated with Claude Code

…s — a shared ask queue, a unit test in the live tier, three stale assertions (#4620)

Three of the seven causes behind the red nightly (#4788 takes two; the
placeholder model key and one product defect stay open). No product code
changes.

A module shared one agent's ask queue (unit job, 4 tests per red seed).
tests/unit/test_ent1109_credential_handover.py raises every ask for one
agent, in a database that outlives the test. TestDelivery leaves 18 asks
pending and TestTheAsk raises 11, against a cap of 25 pending per agent. In
file order TestTheAsk runs first and never meets the cap; in a shuffled
order the next raise is refused with queue_full: four tests on each of the
night's two red seeds, a different four on each. The real_db fixture now
empties that agent's queue before and after each test.

A unit test ran in the live tier (7 tests).
tests/test_cb_probe_execution_close.py stubbed `database`, `utils.helpers`,
`redis` and more into sys.modules with setdefault, which keeps whatever an
earlier-collected file left there. In the live selection that was
tests/git_sync/test_s5_conflict_classifier.py's load-time `database` stub,
whose `db` is None, so every service execute_task reaches was bound to
None. The module moves to tests/unit/, where the conftest provides the real
`database` on a per-process file, and loses its own stubs; it imports the
service at collection so the service's collaborators are bound to that
database. #1895 had left it in the root because it was red at the time:
against #1804, which #2242 fixed the next day, and on a seed-dependent
ImportError from its own sanitizer stub, which is gone now. The move never
followed. The per-PR unit job now runs it. tests/registry.json and the two
lint baselines follow the move. The root placement list goes 10 -> 8: this
module left, and test_public_links.py now takes a live fixture.

Three assertions described the product as it used to be (3 tests).
- test_avatars: the 501 for a missing Gemini key carries copy for the
  person in the dialog since #957, and no error code. The test no longer
  asserts wording; on a 501 it checks only that there is a message.
- test_settings: POST /api/settings/ops/reset leaves the retention windows
  alone on purpose (#1638), and a fresh install seeds some of them with a
  value that is not the code default. The test now says what reset
  promises: every other ops setting returns to its default, and each
  retention window keeps its value and stays a stored row where it was
  one. The window names and sources come from GET /api/settings/retention.
- test_public_links: the email requirement is the agent's access policy
  (#311) and a new agent is created with it on (#1129). TestPublicChat put
  its link on whichever running agent `docker ps` listed first, with the
  policy that agent happened to have. The link now goes on the module's
  own agent (the suite's created_agent), and the fixture sets the policy
  the test is named after there, sending the whole policy because the
  route replaces it. This fixture no longer touches an agent the suite did
  not create.

A learnings note (docs/memory/learnings/) records the first cause as a
class: a per-agent cap is state shared between tests, even when every
request id is unique. The same defect had been fixed once before, in a
sibling module (#4401).

Refs #4620

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/review + /validate-pr — #4805

Lane B (tests only, with deletions). No product code. Scope matches the description: causes 6, 3 and 5 of #4620.

Execution coverage

changed file executed by verdict
tests/unit/test_ent1109_credential_handover.py (real_db clears ASKER's queue) the module itself, seeds 67890 / 99999 ✅
tests/unit/test_cb_probe_execution_close.py (moved, stubs removed, collection-time import) per-PR unit job now collects it ✅
tests/test_avatars.py, tests/test_settings.py, tests/test_public_links.py live tier only ✅ by the PR's live run; not re-run here
lint baselines, registry.json lint_sys_modules.py, lint_root_test_placement.py 🛡 guard

Reproduced locally on the PR head:

  • Both unit modules together, seed 67890: 84 passed. test_ent1109_credential_handover.py, seed 99999: 74 passed.
  • Mutation: with both _clear_asker_queue() calls removed, seed 99999 gives 4 failed, 70 passed. The fixture change is what makes it green.
  • tests/lint_sys_modules.py and tests/lint_root_test_placement.py exit 0.

Critical

None.

Informational

  • I1 test_public_links.py: the finally restore (httpx.put(policy_url, …, json=prior_policy)) ignores its status. If the restore fails, the module's agent keeps require_email: False for later tests in the module. The agent belongs to the suite and is deleted at teardown, so the blast radius is that module. An assert on the restore status would surface it. Non-blocking.
  • I2 test_avatars.py: the 501 assertion now checks for a non-empty detail and no wording. Fine as a contract. A regression that returns a 501 from a different cause would also pass, since the route carries no error code. Adding an error code to that 501 is product work and out of scope here.
  • I3 test_ent1109_credential_handover.py clears the queue with raw SQL (parameterized, scoped to one agent name). The cleanup keeps working if the agent name stays constant. The learnings note already recommends a per-test uuid agent name as the sturdier pattern.

Process

  • Security greps (keys, emails, IPs, host paths, file modes): clean.
  • Refs #4620 with no closing keyword is deliberate: the nightly workflow closes #4620. The issue will not auto-promote to status-in-dev.
  • Learnings fragment added under docs/memory/learnings/, in the right shape.
  • Merge gate: pytest (head, seed 12345) was still pending when this was posted. Tier 1 has to finish green before merge.

Verdict: APPROVE.

@pavshulin
pavshulin merged commit ea04de2 into dev Nov 27, 2026
24 checks passed
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.

3 participants