Fix AIModel ALL_MODELS class-init cycle (NPE in CognitiveRelayCostTest et al)#581
Merged
Merged
Conversation
…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>
|
Concept staleness check — 1 warning(s). These changes touched files listed under a concept's Validator output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ALL_MODELSasby lazy { listOf(...) }in the companion objects ofAIModel_Claude,AIModel_Gemini, andAIModel_OpenAIto break a JVM class-initialization cycle.data object(e.g.AIModel_Gemini.Flash_2_5) was accessed before its companion finished initializing, the companion's<clinit>would observe that object'sINSTANCEasnulland permanently commit a poisoned list — causingCognitiveRelayCostTest,RouteCostReportTest, andModelDescriptorTestto NPE when run as part of the full suite but pass in isolation.defaultModelDescriptors()kdoc inModelDescriptorRegistryto explain the actual fix.Why it passed CI
The failures are ordering-dependent: tests pass when run with
--testsfilter (fresh JVM, no prior class contamination) but fail in the fulljvmTestrun when another test class first touches a modeldata objectdirectly and poisonsALL_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:jvmTestpasses (all 1366 tests, 0 failures)./gradlew ktlintFormatclean🤖 Generated with Claude Code