Skip to content

fix(config): stop the edition-agent lookup re-entering config load - #23782

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/23427-load-reentry
Oct 24, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/23427-load-reentry

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop TestDanglingDefaultAgentReset tests from failing at random on CI with ExceptionGroup: multiple unraisable exception warnings.

Backend Tests shard 7 keeps failing on PRs that touch no config code. The failing test changes from run to run (test_a_relative_workspace_is_placed_under_the_data_home, test_the_removal_evidence_is_bounded_and_evicts_the_oldest_removals_first, and others in the same class). The log shows RecursionError inside pytest's unraisable hook and a half-built PosixPath ('_str', '_drv').

Why it matters

Every contributor whose PR lands on shard 7 can get a red run they did not cause. It has been reported on nine unrelated heads in #23427 alone, once on both attempts of one run, and reruns cost CI time and reviewer trust.

Not a goal

What changed (motivation → approach → change)

Symptom → cause. With no platform context installed, _edition_agent_names() in config/loader_snapshots.py asks current_context() for the edition's agents. That call builds a context, which loads config, which reaches _edition_agent_names() again. The loop only stops at Python's recursion limit, and safe_context_call swallows the RecursionError. On main, 13 of the 27 tests in TestDanglingDefaultAgentReset run about 988 frames deep this way. Any GC finalizer that fires down there has no stack left, so pytest fails whichever test is running. This is the cycle #21089 describes.

Change. _edition_agent_names() now notes, per thread, that a lookup is in progress. A second lookup on the same thread answers "no edition agents". That is the same answer it already gives on an adapter error, and the answer the innermost call reached at the recursion limit before. The outer lookup still asks the real context. With the guard, the same tests peak at 48 frames and raise nothing. The config/loader.py facade forwards the new _EDITION_LOOKUP state like the module's other globals.

Why this spot: it is the one place the loop closes, and it changes no answer the outer call gives. A guard inside current_context() would also refuse other nested callers that work today.

Backwards compatibility

Compatible: only a lookup nested inside the same lookup on the same thread changes. It answered "none" before too, after about 95 levels of recursion.

Removes nothing: no key, path, record or function is removed or narrowed.

Tests

  • test_the_edition_lookup_with_no_context_does_not_re_enter_itself runs the dangling-default reset with no context installed and counts how deep current_context() nests. It asserts depth 1 and that the default is still reset to default. Without the guard it nests 95 deep.

Proof: PROVEN test/test_config_loader_default_agent.py::TestDanglingDefaultAgentReset::test_the_edition_lookup_with_no_context_does_not_re_enter_itself (head 9d6ffac)

Determinism: the whole file passed 10 of 10 runs in 10 shuffled orders with -W error::pytest.PytestUnraisableExceptionWarning. The 11 test files that use default_template, _edition_agent_names, _with_edition_agents or builtin_agents passed 3 of 3 runs under -n 4 with the same flag (563 tests each run).

Manual verification

N/A — this is test infrastructure behaviour; a per-test stack-depth probe showed 988 frames and 1–2 swallowed RecursionErrors per affected test on main, and 48 frames and none with the fix.

Related Issues

Closes #23427
Closes #23221
Part of #21089

Sibling sweep

Swept: git grep -nE "current_context()" -- src/kiro_crew/config/ src/kiro_crew/agent_discovery_parts/ src/kiro_crew/agent_discovery.py
Sibling: src/kiro_crew/agent_discovery_parts/agent_roster.py -- not affected -- reached only through _edition_agent_names when inside config load
Sibling: src/kiro_crew/config/loader.py -- not affected -- build_provider_factory takes a loaded config and is not called from load

Pattern harvest

Rule candidate: review-prompt
Pattern: a lazy-default context lookup (current_context()) reachable from inside KiroCrewConfig.load() re-enters load; peek installed_context() or guard re-entry.

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

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 9d6ffac335937485498a4200e21249413ce55b24 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 9d6ffac335937485498a4200e21249413ce55b24 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

The guard only changes the nested same-thread lookup, and that call already answered "none" once it hit the recursion limit. Nothing blocks.

Notes

  • The inner config load still runs the default-agent healer with "no edition agents". If an edition's agent is the default, that inner load could still reset it and write the reset to disk. The behaviour is unchanged from before. Peeking installed_context() would avoid both the inner load and that write.

[DESIGN-REVIEWED] 9d6ffac

Description read

[DESCRIPTION-READ] 1f1695327ba163ce87cd77b16097b009b69db206d3b7c12bcf9594c561afb379

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 9d6ffac335937485498a4200e21249413ce55b24 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix closes the config-load loop where it forms, and a new test pins it. The repository already has a peek mechanism for this same re-entry.

Notes

  • Item 1 — duplicate of src/kiro_crew/platform/context.py PEEK_CALLERS / installed_context(): the speech_providers.py::_installed_speech entry already solves this exact class ("It must peek: the STT half runs inside KiroCrewConfig.load(), and current_context() with nothing installed loads config, which would re-enter that load"). With no context installed, the outer lookup also ends at "none" on both profiles: the standalone default contributes none, and a non-standalone profile raises into the existing fallback. The description's own harvest names it: "peek installed_context() or guard re-entry". Subtraction: delete _EDITION_LOOKUP and its forward in loader.py. Then read installed_context() in _with_edition_agents and declare that call site in PEEK_CALLERS. That leaves one re-entry mechanism instead of two.

What this change ships

Inventory (3 items) — 2 justified

Intent: stop shard-7 config tests failing at random from runaway recursion during config load. FIX.

  1. A nested edition-agent lookup on the same thread now answers "no edition agents" right away instead of recursing about 95 levels — duplicate of platform/context.py installed_context() peek pattern
  2. The config/loader.py facade forwards the new per-thread lookup state — justified
  3. A test pins that context construction nests only one level deep and the default still resets — justified

[FIRST-PRINCIPLES-REVIEWED] 9d6ffac

Description read

[DESCRIPTION-READ] 81080a3ef01d5f346aa18faf7cdf0bc338b5a1177546002ecd3cc1577186c456

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 9d6ffac335937485498a4200e21249413ce55b24 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 9d6ffac

Verdict parsed from the review's SHA-scoped output markers for commit 9d6ffac335937485498a4200e21249413ce55b24.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 9d6ffac335937485498a4200e21249413ce55b24 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 9d6ffac335937485498a4200e21249413ce55b24 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9d6ffac

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 9d6ffac335937485498a4200e21249413ce55b24 false-positive: <reason, 20 to 500 characters>

@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 Oct 24, 2026
@iamwhatever
iamwhatever force-pushed the fix/23427-load-reentry branch from 8eec2e8 to d60673b Compare October 24, 2026 16:53
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 24, 2026
@iamwhatever
iamwhatever force-pushed the fix/23427-load-reentry branch from d60673b to 9d6ffac Compare October 24, 2026 17:35
@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 Oct 24, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready at 9d6ffac335937485498a4200e21249413ce55b24: pr_status.py --reviewers gpt,opus exits 0, with all 106 checks done and none failing, plus the readiness: passed label. The GPT 6.1 and Opus 5.5 reviews found no blocking findings. Design and First Principles both pass, and UX was skipped because the diff has no UI. The PR is mergeable, and main has moved by one commit that touches none of this PR's files. It is waiting for a maintainer review. I have not merged it, approved it or turned on auto-merge.

🤖 AI-assisted comment 🤖

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 24, 2026 19:01

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: a thread-local re-entry guard in _edition_agent_names() stops the config-load recursion that made shard 7 tests fail at random, with a regression test that asserts the lookup nests only once.

@KiroCrewCaptain
KiroCrewCaptain merged commit 9d2df15 into main Oct 24, 2026
107 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/23427-load-reentry branch October 24, 2026 19:02
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants