Skip to content

fix(tests): a model-turn 429 is classified — billing fails, capacity skips; the admission 429s say "capacity" (#2919) - #2977

Merged
vybe merged 10 commits into
devfrom
vybe/issue-2919
Sep 23, 2026
Merged

vybe merged 10 commits into
devfrom
vybe/issue-2919

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Fixes #2919

Summary

#2894 stopped a bare 503 skip from hiding a real failure. Eighteen integration tests still had the same pattern for 429: a bare pytest.skip("Agent queue full"). That meant a model-turn 429 caused by an exhausted subscription (billing) was reported as skipped, not failed. This PR closes that gap the same way #2894 did.

What changed

  • The 429 arm in tests/testing_utils/readiness.py::require_agent_answer mirrors fix(tests): classify a model-turn 503 instead of skipping on it (#2889) #2894. The header is checked first: X-Trinity-Error-Code: billing → fail, capacity → skip, a header-less or unknown 429 → fail as unknown. The body-marker fallback is pinned to the producer's source text.
  • The AST laundering guard now also covers == 429, and it no longer cares about the operator, as fix(tests): classify a model-turn 503 instead of skipping on it (#2889) #2894's was.
  • 18 dead 429 skips deleted: test_agent_chat.py ×5, test_dynamic_thinking_status.py ×6, test_parallel_task.py ×6, agent_server/test_agent_chat_direct.py ×1. Every site already calls require_agent_answer above the old skip.
  • The three admission-refusal 429s now send X-Trinity-Error-Code: capacity: the /chat queue-full refusal (routers/chat.py), _acquire_task_capacity's backlog-full refusal, and the _map_task_failure "at capacity" branch (chat_execution_service.py). The backend diff is 3 headers= kwargs + 1 import. task_execution_service.py is untouched. Two docs already said this header was sent (architecture/execution.md, feature-flows/agent-to-agent-collaboration.md); now it actually is.
  • Docs: execution.md, agent-to-agent-collaboration.md, execution-queue.md, docs/testing/STRATEGY.md, tests/README.md.

Evidence

  • Guard red: before the deletions, the widened AST guard failed and named exactly 18 offenders.
  • Producer red ×3: each of the three producer tests failed (None == {'X-Trinity-Error-Code': 'capacity'}) before its headers= kwarg was added.
  • The tests were passing when they shouldn't have (found in review): the fail-expecting cases used pytest.raises(pytest.fail.Exception), which lets a skip through. A mutation that makes the classifier "skip every 429" gave 71 passed / 6 skipped / 0 failed before c4c8a6ac1 and 6 failed after it.
  • Gate (6 files: test_2889_readiness_classifier, test_2889_error_code_header, test_chat_admission, test_946_task_idempotency_on_deny, test_2661_task_timeout_receipt, test_1483_execute_parallel_task_characterization): 156 passed.
  • Full tests/unit (-n auto): 17803 passed / 46 skipped / 0 failed.
  • dev's required checks run no tests/unit, so both runs above were done locally.

Deviation from the approved plan

Plan decision #16 said "capacity overrides the result code". It was reversed in review (326e33267). Now a code the producer already set wins, and capacity only fills in when there is no code. The reason: a billing result's error text is prose passed through from upstream, and that prose can contain "at capacity". The override would have turned a real exhausted-subscription failure into a capacity skip. No path Trinity writes itself sees a different header today, because no Trinity-written "at capacity" result carries a code. The plan has an amendment recording this.

For the human to confirm

  • The skip text in test_parallel_task.py used to tell developers to rerun the test on its own ("Slots still occupied from prior tests — rerun isolated"). That hint is gone along with the skip.

Not verified

  • /verify-local and a live run of the 18 integration sites. Docker was down on the build host. The 4 site files do collect (98 tests) and the import smoke test passes.

Follow-ups (listed, not filed)

  • Q5 / issue bullet 3: a failure on one agent spreads to the whole fleet. Proposal: an auto_switch response fails its own test without turning on the session fast-fail.
  • Q4: test_public_links.py:587 and test_schedules.py:552 have the same bare-skip shape. Fix them, then widen the guard's walk to cover them.
  • The sync /task backlog-full 503 has no header, so it fails as unknown.
  • client_portal/service.py:3108 matches the substring "at capacity", and mcp_auth_service.py:379 sends an admission 429 without a code.
  • Make _error_code_headers public. The router calls it through the module object.
  • test-runner.md catalog entry (private submodule).

🤖 Generated with Claude Code

trinity-ability and others added 10 commits September 22, 2026 23:19
…t skip (#2919)

Replaces test_non_503_is_a_no_op (which pinned 429 as a no-op) with the
three consumer cases the 429 arm has to satisfy. Red for the behaviour:
DID NOT RAISE Failed / Skipped, 4 failed, 39 passed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…kips, unknown fails (#2919)

The 429 arm in require_agent_answer, mirroring #2894 one status code
over: header first (billing/auth → fail + session cascade; capacity →
skip with evidence, never recorded), X-Circuit-Open second, then on a 429
only the source-pinned capacity wording (transport vocabulary is not
consulted), else unknown ⇒ FAIL. Verdict gains a trailing-default
status; the reason builders name it; capacity_skip_reason is new and
stays off the skip-audit allowlist.

Gate: 63 → 89 passed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e: capacity (#2919)

TaskExecutionErrorCode.CAPACITY had zero assignment sites, so a queue-full
429 was recognisable only by the absence of a header plus its prose, while
execution.md and the A2A feature flow already listed `capacity` as emitted.
Three additive headers= kwargs, bodies byte-identical:

- routers/chat.py: the /chat CapacityFull admission 429 (through
  chat_execution_service._error_code_headers, the one emitter)
- _dispatch_async: the CapacityFull (capacity + backlog full) 429
- _map_task_failure: the at-capacity branch decides the status by the
  result text, so the code it sends now agrees (capacity overrides any
  result code; none exists on that branch today)

task_execution_service.py untouched.

Red (backend reverted from scratch copy): 3 failed, 24 passed —
  assert None == {'X-Trinity-Error-Code': 'capacity'} ×3
Green: test_2889_readiness_classifier + test_2889_error_code_header
  92 passed; characterization suites (chat_admission, 946, 2661, 1483)
  48 passed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…skips (#2919)

_is_503_check → _is_laundered_status_check, keyed on
readiness.LAUNDERED_STATUSES (one home for the vocabulary): `==`, `in`
list/tuple/set, and an `or` of such checks. Known escapes are written
down in its docstring (same limits #2894 accepted). Adds the matcher
table and a walk meta-test pinning the four site files inside the guard.

Guard widened BEFORE deleting — red listed exactly 18 offenders:
  test_dynamic_thinking_status.py:203,230,268,334,425,507
  test_parallel_task.py:569,630,664,719,794,839
  test_agent_chat.py:42,67,432,469,505
  agent_server/test_agent_chat_direct.py:35
Each followed require_agent_answer(...), which now skips a capacity 429
and fails a billing/unknown one, so every branch was dead. Deleted; the
downstream assert_status(…, 200) is unchanged. Mutation check: restoring
test_agent_chat_direct.py's site → guard red with exactly 1 offender.

Gate: 104 passed. The 18 integration sites were not run live (Docker
down); the four files collect (98 tests).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…2919)

- execution.md (header contract's owning area file): the three
  admission-refusal emitters of `capacity`, and the 429 arm of
  require_agent_answer; the value list there is now true.
- agent-to-agent-collaboration.md: a queue-full 429 carries `capacity`.
- STRATEGY.md / tests/README.md: "503 or 429" — capacity skips
  (unallowlisted), billing fails and arms the session fast-fail, the guard
  covers `== 429`.

Requirements delta: none (no area covers the test harness or the header).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… capacity (#2919)

/sync-feature-flows over origin/dev..HEAD: routers/chat.py and
chat_execution_service.py map to execution-queue.md (the 429 body it
documents) and agent-to-agent-collaboration.md (already updated). One
sentence; no new flow, no index change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ort skipped (#2919)

`Skipped` is not a `Failed`, so `pytest.raises(pytest.fail.Exception)` lets a
wrongly-skipping helper propagate its skip: mutating require_agent_answer to
"skip every 429" (the defect this issue removes) left the unit file at
71 passed / 6 skipped / 0 failed. Route every fail-expecting case through
`_must_fail()`, which turns a skip into an AssertionError. Same mutation now:
6 failed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s was (#2919)

`_is_503_check` matched any comparison against 503; the widened matcher
accepted only `==`/`in`, silently unguarding `>= 503`, `!= 503` and
`not in [503]` on the 503 half. Match the constant regardless of operator
(a strict superset of both), pin `>= 429` / `!= 503` / `not in [503]` in the
shape table, and correct the "known escapes" list. Mutation: re-adding a
`status_code >= 429: pytest.skip` site turns the guard red naming it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…producer's (#2919)

`_map_task_failure` picks its 429 by substring ("at capacity") on the result
text and was stamping `capacity` over any code the result carried. That code
is the producer's structured verdict on a turn that RAN (#2638 `billing`,
whose `error` is the agent's own prose) — overriding it would let the new
429 arm SKIP an exhausted subscription whose prose happened to say "at
capacity". Prose must not beat the structured code: `capacity` now only
fills an absent code (the capacity rejection sets none, so every live
at-capacity 429 still carries `capacity`). Red first:
`{'X-Trinity-Error-Code': 'capacity'} != {'X-Trinity-Error-Code': 'billing'}`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ts capacity on at-capacity (#2919) — mechanical, doc/comment accuracy

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@vybe
vybe marked this pull request as ready for review September 23, 2026 09:43
@vybe

vybe commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

merge-train: pushed one mechanical commit to this branch — doc/comment accuracy only, no behaviour change:

  • docs/memory/architecture/execution.md and tests/testing_utils/readiness.py: the CapacityFull 429 site is _acquire_task_capacity (shared by async and sync /task), not _dispatch_async.
  • execution.md + the _map_task_failure comment: the backlog-reconstruct path no longer sends no header — on the at-capacity branch capacity fills the absent code.

test_2889_* re-run locally: 108 passed. Follow-up Q5 (fail-fast after an auto-switched billing 429) accepted as written.

@vybe vybe 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.

merge-train: validated individually (3-member queue, below train size); all checks green incl. pytest + journey-smoke.

@vybe
vybe merged commit cdbe5eb into dev Sep 23, 2026
25 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.

2 participants