Skip to content

test(acp): hold the cyclic collector off for the too-deep payload test - #23771

Closed
leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:claude/recursion-limit-gc-quiesce
Closed

leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:claude/recursion-limit-gc-quiesce

Conversation

@leonlaiyc

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: the test that refuses an unrenderable rawInput passes or fails on the code it tests, not on whether a garbage-collection sweep lands while it sits at the recursion limit.

test/test_tool_call_classification_provenance_bound.py::TestTheProvenanceCachesShareOneBound::test_a_payload_the_encoder_could_not_render_is_refused_not_retained_unmeasured failed on three unrelated PRs within an hour on 2026-10-24 (#19440, #23332, #15543), each time in Backend Tests (3.12, 5):

ExceptionGroup: multiple unraisable exception warnings (2 sub-exceptions)
  RecursionError: maximum recursion depth exceeded      (inside pytest's unraisable_hook)
  RuntimeError: Failed to process unraisable exception

The test encodes a 5,000-deep payload with indent=2. On Python 3.12 that is the pure-Python encoder, which recurses to RecursionError on purpose. A gen0 sweep that lands in those innermost frames runs the finalizers of whatever cyclic garbage the worker is carrying. They overflow, so does pytest's hook, and the test fails although every assertion held.

Why it matters

A red Backend Tests shard on a PR that does not touch ACP costs a rerun, and a fork author cannot rerun upstream jobs, so the PR waits on a maintainer. File sharding is stable, so this test always runs on shard 5, and every PR whose run lands it next to such garbage is exposed.

Not a goal

  • The other tests that walk to the recursion limit without the fixture. None of them failed in the 88 failed Backend Tests jobs I checked (the 80 most recent failed PR CI runs), and each can take the same fixture when it does.
  • Changing how _dumps_degraded detects an unrenderable payload, or the depth the test uses.

What changed (motivation → approach → change)

  • Symptom: the test fails with an unraisable ExceptionGroup on unrelated PRs.
  • Root cause: it drives the encoder to RecursionError with the cyclic collector on, which docs/system-specs/common/testing-conventions.md names as a flake class: "A test that drives code to RecursionError on purpose must hold the cyclic collector off for the walk."
  • Change, in test/test_tool_call_classification_provenance_bound.py only: the test uses the shared stray_line_helpers.cyclic_gc_quiesced fixture (one gc.collect() at depth zero, the collector off for the test, then re-enabled and collected again), the remedy that section gives and the fixture test_acp_frame_record.py already uses. Reference counting still frees the walk's own objects; only cycles wait for teardown.
  • CI note: the diff is test-only, so CI takes the leaf path, whose corpus-gate group can reach the 60-minute job limit on hosted runners (CI: leaf-mode Backend Tests jobs run every corpus gate and hit the 60-minute limit on hosted runners #23450, fixed by ci: run leaf corpus gates once across the matrix, not per job #23461). That is unrelated to this change.

Backwards compatibility

Compatible: test-only; no product code changes.

Removes nothing: the test makes the same assertions.

Tests

  • Reproduction on Python 3.12.13: a pytest plugin sets gc.set_threshold(1, 1, 1) for the call and plants one logging-finalizer cycle after every sweep, the shape of a pending Task an earlier test leaked. On main the test fails 3 of 3 runs with the CI ExceptionGroup. With this change it passes 3 of 3, and no finalizer runs during the call. Without the plugin, main passes. The plugin is in Flaky: test_a_payload_the_encoder_could_not_render_is_refused_not_retained_unmeasured fails with unraisable RecursionError on Python 3.12 #23770.
  • test/test_tool_call_classification_provenance_bound.py: 26 passed on Python 3.12.13; with test/test_tool_call_classification.py, 70 passed on 3.13.5. The same harness does not fail main on 3.13.5 here.
  • test/test_flake_pattern_ratchet.py: 60 passed. black, isort, flake8, check_comment_history, check_brand_name and check_subprocess_encoding pass on the diff.

Proof: not provable -- test-only change

Manual verification

N/A — test-only change; the reproduction above is the check.

Related Issues

Fixes #23770

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

🤖 Generated with Claude Code

The provenance-bound test that refuses an unrenderable rawInput encodes
a 5,000-deep payload with indent=2. On Python 3.12 that runs the
pure-Python encoder down to RecursionError. A gen0 sweep landing in
those innermost frames runs the finalizers of whatever cyclic garbage
the worker carries; they overflow, pytest's unraisable hook overflows
with them, and the test fails with "ExceptionGroup: multiple unraisable
exception warnings". It did so on three unrelated PRs on 2026-10-24.

Use the shared cyclic_gc_quiesced fixture, the remedy
testing-conventions.md prescribes for a test that drives code to
RecursionError on purpose.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leonlaiyc
leonlaiyc requested review from a team and KiroCrewCaptain as code owners October 24, 2026 15:39
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 24, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #23330, which is assigned to @CrysisDeu. I found it only after opening this. The fix, the reproduction and the new occurrences are handed over in a comment there.

@leonlaiyc leonlaiyc closed this Oct 24, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky: test_a_payload_the_encoder_could_not_render_is_refused_not_retained_unmeasured fails with unraisable RecursionError on Python 3.12

1 participant