Skip to content

fix: patch _Server in workflows entrypoint tests (#9675) - #9682

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/workflows-entrypoint-test-patch-server-9675
Sep 9, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/workflows-entrypoint-test-patch-server-9675

Conversation

@NicholasRBowers

Copy link
Copy Markdown
Contributor

Problem / Motivation

URGENT — every PR based on current main is red. Backend Tests shard 4 hangs on test/test_workflows_app.py::test_main_boots_platform_before_binding_server: a 120s pytest timeout on Linux 3.12, an xdist worker crash on Windows, and the Coverage Gate cascades red because the shard never uploads. The test monkeypatches server.ThreadingHTTPServer, but main() constructs server._Server — a subclass whose base was bound at class-definition time — so the patch never engages and the test boots a real listener on the real PORT, then blocks forever in serve_forever().

Why it matters

The whole repository is blocked: no PR can go green until this lands, and the failure shape is the worst kind — a silent hang with no test output to diagnose from. It was a semantic merge collision: #9066 added the test, #9413 introduced _Server, each PR's CI ran on a merge ref predating the other, so both were green alone and red combined.

What changed (motivation → approach → change)

The test hung because it patched a name main() no longer reads. The fix (test-only — the production code is correct) patches server._Server, the class main() actually constructs, in both test_main_boots_platform_before_binding_server and test_main_fails_closed_when_platform_cannot_compose, whose identical patch was dead but masked by its raising boot stub. monkeypatch.setattr raises on a missing attribute, so a rename of _Server fails fast.

A named patch alone cannot survive the exact vector that caused this incident — main() constructing the listener under a name the test does not patch. Both tests therefore also arm a name-independent guard: socketserver.TCPServer.server_bind is patched to pytest.fail, so any unsubstituted construction path fails loudly at the bind instead of hanging the shard. The fail-closed test's fake is class-shaped (with serve_forever) so an ordering regression reports the ordering assertion, not an unrelated AttributeError on None.

Tests

  • test_main_boots_platform_before_binding_server — the boot→bind→serve ordering assertion is unchanged; the patch now engages. Red-before-green demonstrated locally: on unpatched main the test hangs until pytest-timeout kills the xdist worker (the exact CI signature); with the fix, the file's 34 tests pass in ~6s.
  • test_main_fails_closed_when_platform_cannot_compose — same substitution; its previously-dead patch is now live, and served == [] still locks the fail-closed invariant.
  • The server_bind guard was mutation-verified: re-introducing the dead ThreadingHTTPServer patch with the guard armed fails immediately with "main() bound a real socket" instead of hanging.
  • Full test/test_workflows_app.py plus src/kiro_crew/apps/builtins/workflows/tests green on Python 3.12.

Manual verification

N/A — unit coverage sufficient: the defect and fix are both fully contained in the two entrypoint tests, and the red-before-green run reproduced the CI hang signature locally.

Related Issues

Closes #9675

Pattern harvest

Rule candidate: review-prompt
Pattern: monkeypatching a base-class name never intercepts a subclass bound at class-definition time — patch the name the code under test actually constructs, and back socket-touching entrypoint tests with a bind-level tripwire.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

@NicholasRBowers

Copy link
Copy Markdown
Contributor Author

Intent: Make the two workflows entrypoint tests substitute the class main() actually constructs, so they never bind a real socket — unblocking Backend Tests shard 4 for every PR on main.
Not a goal: No production code change; no change to the boot→bind→serve contract itself; no refactor of other apps' server tests (their direct ThreadingHTTPServer patches are alive).

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 73a3a816389782b44da579de2865ca5b76614219 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 73a3a81

Verdict parsed from the review's SHA-scoped output markers for commit 73a3a816389782b44da579de2865ca5b76614219.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 73a3a816389782b44da579de2865ca5b76614219: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 73a3a816389782b44da579de2865ca5b76614219 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Verified against source: main() at src/kiro_crew/apps/builtins/workflows/server.py:272 constructs _Server, so the test-only fix patches the name actually read, and the bind-level tripwire converts any future unpatched construction path from a silent shard hang into a loud failure. The diff is fully accounted for by the description, the description's claims all have backing code, and "Manual verification: N/A" is legitimate since CI itself exercises exactly these tests.

Design-Verdict: PASS

Test-only root-cause fix: patches the class main() actually constructs, plus a name-independent bind tripwire that makes the failure mode loud instead of a hang.

[DESIGN-REVIEWED] 73a3a81

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 73a3a816389782b44da579de2865ca5b76614219 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 73a3a81

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 73a3a816389782b44da579de2865ca5b76614219: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 9, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor

Heads-up: Backend Lint & Type Check (3.12) is red on this head — that one is from this PR's own change (the _forbid_real_bind helper / class-shaped fake), not main. #9683 carries the same _Server retarget for both tests (without the extra tripwire) and is currently 0 red with PR Hygiene re-running, so it is the alternate for #9675: whichever of the two is fully green first can merge, and the other should be closed as superseded.

test_main_boots_platform_before_binding_server monkeypatched
server.ThreadingHTTPServer, but main() constructs _Server, whose base
class was bound at class-definition time - the patch never engaged, so
the test booted a real listener on the real PORT and blocked forever in
serve_forever(), hanging Backend Tests shard 4 on every PR (120s
timeout on Linux, xdist worker crash on Windows, Coverage Gate cascade).

Patch server._Server (the name main() actually resolves) instead, in
both this test and test_main_fails_closed_when_platform_cannot_compose,
whose identical patch was dead but masked by its raising boot stub.
monkeypatch.setattr raises on a missing attribute, so a future rename
of _Server fails fast instead of hanging.

Both tests also arm a name-independent guard that patches
socketserver.TCPServer.server_bind to pytest.fail, so any future
construction path the named patch misses fails loudly at the bind
instead of hanging the shard, and the fail-closed test uses a
class-shaped fake so an ordering regression reports the ordering
assertion rather than an unrelated AttributeError.

The production code is correct; this is a test-only semantic merge
collision between #9066 and #9413, whose CI rounds each ran on a merge
ref predating the other.

Closes #9675
@NicholasRBowers
NicholasRBowers force-pushed the fix/workflows-entrypoint-test-patch-server-9675 branch from f1285c5 to 73a3a81 Compare September 9, 2026 09:47
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 9, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: NicholasRBowers#a942f9ca] Thanks for the heads-up, @CrysisDeu. The Backend Lint red you saw was on the prior head (a comment-history-gate hit on the _forbid_real_bind docstring) and is fixed: the current head 73a3a81 is fully green — 65/65 checks, PR Readiness passed, GPT/Opus/Design lanes clean, readiness: passed label applied. Per the race rule you proposed, this PR reached fully-green first (#9683 currently shows readiness: action required with 2 failing checks). I'll leave the supersede call on #9683 to you and the maintainers rather than acting on it from this session. On the tripwire delta: the server_bind guard is the piece that catches the next variant of this incident class — a future main() constructing the listener under a name the test doesn't patch hangs the shard silently again, and the guard turns that into an immediate loud failure (mutation-verified in this PR's Tests section).

@chenmingwei23
chenmingwei23 enabled auto-merge (squash) September 9, 2026 11:03

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

Tier 1 auto-approve: test (1 file). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean (Semgrep success 0 ann, CodeQL success 0 alerts), security checklist all-NO, AI reviewers green. Category: test-only change to test/test_workflows_app.py (patches _Server in workflows entrypoint tests).

@chenmingwei23
chenmingwei23 merged commit c0cf53f into main Sep 9, 2026
65 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/workflows-entrypoint-test-patch-server-9675 branch September 9, 2026 11:04
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 9, 2026

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

Tier 1 auto-approve: test (1 file). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: test-only change confined to test/test_workflows_app.py — substitutes the class the entrypoint actually constructs and adds a bind guard so the tests cannot open a real listener; no runtime code touched.

amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…irodotdev#9682)

test_main_boots_platform_before_binding_server monkeypatched
server.ThreadingHTTPServer, but main() constructs _Server, whose base
class was bound at class-definition time - the patch never engaged, so
the test booted a real listener on the real PORT and blocked forever in
serve_forever(), hanging Backend Tests shard 4 on every PR (120s
timeout on Linux, xdist worker crash on Windows, Coverage Gate cascade).

Patch server._Server (the name main() actually resolves) instead, in
both this test and test_main_fails_closed_when_platform_cannot_compose,
whose identical patch was dead but masked by its raising boot stub.
monkeypatch.setattr raises on a missing attribute, so a future rename
of _Server fails fast instead of hanging.

Both tests also arm a name-independent guard that patches
socketserver.TCPServer.server_bind to pytest.fail, so any future
construction path the named patch misses fails loudly at the bind
instead of hanging the shard, and the fail-closed test uses a
class-shaped fake so an ordering regression reports the ordering
assertion rather than an unrelated AttributeError.

The production code is correct; this is a test-only semantic merge
collision between kirodotdev#9066 and kirodotdev#9413, whose CI rounds each ran on a merge
ref predating the other.

Closes kirodotdev#9675

Co-authored-by: Nick Bowers <nrb@amazon.com>
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.

ci: test_main_boots_platform_before_binding_server hangs/crashes shard 4 on every PR since #9066

4 participants