Skip to content

Fix AIModel ALL_MODELS class-init cycle (NPE in CognitiveRelayCostTest et al)#581

Merged
wow-miley merged 1 commit into
mainfrom
wow-miley/fix-pre-existing-cost-test-failures
Jun 15, 2026
Merged

Fix AIModel ALL_MODELS class-init cycle (NPE in CognitiveRelayCostTest et al)#581
wow-miley merged 1 commit into
mainfrom
wow-miley/fix-pre-existing-cost-test-failures

Conversation

@wow-miley

Copy link
Copy Markdown
Contributor

Summary

  • Declares ALL_MODELS as by lazy { listOf(...) } in the companion objects of AIModel_Claude, AIModel_Gemini, and AIModel_OpenAI to break a JVM class-initialization cycle.
  • Without lazy, if any data object (e.g. AIModel_Gemini.Flash_2_5) was accessed before its companion finished initializing, the companion's <clinit> would observe that object's INSTANCE as null and permanently commit a poisoned list — causing CognitiveRelayCostTest, RouteCostReportTest, and ModelDescriptorTest to NPE when run as part of the full suite but pass in isolation.
  • Updates the defaultModelDescriptors() kdoc in ModelDescriptorRegistry to explain the actual fix.

Why it passed CI

The failures are ordering-dependent: tests pass when run with --tests filter (fresh JVM, no prior class contamination) but fail in the full jvmTest run when another test class first touches a model data object directly and poisons ALL_MODELS. If CI was hitting cached Gradle test results from before the new test files were introduced, the failures never surfaced.

Test plan

  • ./gradlew :ampere-core:jvmTest passes (all 1366 tests, 0 failures)
  • ./gradlew ktlintFormat clean

🤖 Generated with Claude Code

…scriptors

Make ALL_MODELS lazy in AIModel_Claude, AIModel_Gemini, and AIModel_OpenAI
companions to break a JVM class-init cycle: if any data object (e.g.
AIModel_Gemini.Flash_2_5) was accessed before its companion finished
initializing, the companion's <clinit> would observe INSTANCE as null and
permanently commit a list with null entries, causing CognitiveRelayCostTest,
RouteCostReportTest, and ModelDescriptorTest to NPE when running in the
full test suite but not in isolation.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Concept staleness check — 1 warning(s).

These changes touched files listed under a concept's tracked_sources without updating the concept file. Either update the concept (and bump last_verified) or include a Concept-Verified: <ConceptName> trailer in a commit on this PR.

Validator output
⚠ Concept 'CognitiveRelay' may be stale: ampere-core/src/commonMain/kotlin/link/socket/ampere/agents/domain/routing/capability/ModelDescriptorRegistry.kt matches tracked_sources pattern ampere-core/src/commonMain/kotlin/link/socket/ampere/agents/domain/routing/** but docs/concepts/cognitive-relay.md was not modified.

validate-concepts: 1 warning(s). Validator informs; never blocks.

@wow-miley
wow-miley merged commit 93765ab into main Jun 15, 2026
2 of 3 checks passed
@wow-miley
wow-miley deleted the wow-miley/fix-pre-existing-cost-test-failures branch June 15, 2026 06:12
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.

1 participant