Skip to content

Polyalgorithm solve!: assert retcode type for Julia 1.10 inference - #1347

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/inf310-inference-310
Oct 16, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/inf310-inference-310

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

What changed and why

SciMLBase 3.57 added an RC type parameter to NonlinearSolution (retcode::RC, SciML/SciMLBase.jl#1620). In the generated solve!(::NonlinearSolvePolyAlgorithmCache), the fall-through path reads retcode = cache.caches[idx].retcode with a runtime idx; Julia 1.10 infers heterogeneous-tuple indexing at a dynamic index as Any, so typeof(retcode) cannot pin RC and the inferred return type degrades to the partial UnionAll NonlinearSolution{…}, which fails @inferred. This adds a ::ReturnCode.T assert — the declared field type of every subcache's retcode — matching the _uType/_fuType/_traceType asserts the same generated body already uses for this 1.10 limitation.

Verification

All on Julia 1.10.12 (julia +lts), SciMLBase 3.57.0, in a scratch env with NonlinearSolveBase devved at this branch.

Without the fix (registry NonlinearSolveBase v2.54.1, SciMLBase 3.57.0) — reproduces the master failure in Core on Julia lts (ubuntu job 109631864277, macos job 109631864862):

solve() inference          |    8      8  14.8s
solve!() inference: Error During Test at test/Core/core_tests__item3.jl:27
  Got exception outside of a @test
  return type NonlinearSolution{..., SciMLBase.ReturnCode.T} does not match inferred return type NonlinearSolution{...}
...
solve!() inference         |     1      1  6.1s
ERROR: LoadError: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

With the fix:

Test Summary:     | Pass  Total   Time
solve() inference |    8      8  14.6s
Test Summary:      | Pass  Total   Time
solve!() inference |    8      8  19.8s

Same test file on Julia 1.12.7 (SciMLBase 3.57.0): 16/16 pass.

NonlinearSolveBase sublibrary, GROUP=Core on Julia 1.10.12 (Pkg.test() in lib/NonlinearSolveBase, SciMLBase 3.57.0): all tests passed.

Runic.main(["--check", "lib/NonlinearSolveBase/src/solve.jl"]): clean. typos: clean.

CI status on this PR

Three checks are red; none is caused by this change:

  • FirstOrder QA — fails on master too; unrelated.
  • SCCNonlinearSolve Core — also fails on master (job 109631882829), from the same SciMLBase 3.57 RC cause (isconcretetype(NonlinearSolution{…10 params…}) assertion at lib/SCCNonlinearSolve/test/core_tests__item4.jl:100). Fixed by Keep spelled NonlinearSolution element type concrete across SciMLBase layouts #1332.
  • Core (julia lts) — this PR fixes the PolyAlgorithm Type Inference testset (16/16 in job 110572035298); the job then fails in 23 Test Problems: Broyden at Watson function | alg #2 (norm(res, Inf) = 3.32 > 1e-3). On master the job aborted at the inference error before reaching this file, so the failure is newly visible, not newly caused. The changed line is only reached from the polyalgorithm solve!; the failing case is a direct Broyden(; init_jacobian = Val(:true_jacobian)) solve, so this PR cannot affect it. The file passes locally on AMD hardware for both master and this PR; CI ran on Intel. It needs a separate fix.

Bisect

SciMLBase v3.56.1..v3.57.0 is six commits; the first bad commit is ee5dedb7 — "Make NonlinearSolution's retcode field type a parameter" (SciML/SciMLBase.jl#1620), whose parent is the v3.56.1 tag itself. The failure is Julia-1.10-specific because 1.12 infers caches[idx] as a precise Union and hence .retcode as ReturnCode.T; the CI jobs on 1/pre are unaffected.

Risk assessment

Very low. The assert is a no-op at runtime: every subcache declares retcode::ReturnCode.T, so the value is already that type; it only guides inference, as the neighboring ::_uType/::_fuType/::_traceType asserts do. A non-ReturnCode.T sub-retcode would already fail at the existing cache.retcode = cache.caches[idx].retcode store into the ReturnCode.T-typed field (polyalg.jl:366), so the assert adds no new failure mode. No dependency or public-API changes.

Independent review: Claude Code (model claude-opus-5-5, adversarial round 1) rated this low risk, high confidence, verdict MERGE — review summary at <local path> on a fleet worker host.

Not verified

  • Full GROUP=Core of the outer package on lts (only the failing test file was run); other Core testsets could contain similar runtime-index reads feeding RC.
  • macOS not run (mechanism is platform-independent).
  • solve() (non-mutating) passes either way — it routes through __solve, not the stepping solve!; not fully traced.

Correction to a previous claim

An earlier version of this body listed SimpleNonlinearSolve's nonlinear_solution_new_alg (lib/SimpleNonlinearSolve/src/utils.jl) as a possible follow-up, claiming solve(prob, SimpleLimitedMemoryBroyden()) inferred NonlinearSolution{…} where RC on 1.10. That was wrong: my probe passed the bare parametric type SimpleLimitedMemoryBroyden (itself a UnionAll) as the signature, which trivially widens the result. With a concrete signature both solve(prob, SimpleLimitedMemoryBroyden()) and nonlinear_solution_new_alg infer NonlinearSolution{…, SciMLBase.ReturnCode.T} on 1.10 + SciMLBase 3.57.0, and @inferred passes — the 10-parameter compatibility constructor picks RC = typeof(sol.retcode) correctly. There is no issue there.

🤖 Generated with Devin — Devin CLI 3000.11.3, model swe-2-high; local session, transcript at on a fleet worker host

Risk assessment

  • Risk: low
  • Blast radius: Only the solve! loop that NonlinearSolveBase generates for NonlinearSolvePolyAlgorithmCache, in its fall-through branch that picks the best residual. The diff is one line in lib/NonlinearSolveBase/src/solve.jl:606, which adds ::ReturnCode.T to cache.caches[idx].retcode. It is a typeassert, not a conversion. If a sub-cache ever had a retcode that is not ReturnCode.T, this branch would throw a TypeError instead of building the solution. That case already fails at the ReturnCode.T-typed cache.retcode store in polyalg.jl, so no new failure mode in practice. Users of FastShortcutNonlinearPolyalg/RobustMultiNewton and the default algorithm on Julia 1.10 get a concretely inferred NonlinearSolution; behaviour on 1.11+ does not change. ReturnCode is SciMLBase's public module, NonlinearSolveBase.jl:43 already imports it, and the same file already uses ReturnCode.T. No non-public internals are used, no public API changes (patch-level), and no tests are weakened, skipped or loosened. No version bump is included.
  • Evidence: The head commit 98fc1d1f90 sits directly on master 06b122951a (0 commits behind). Six checks fail on head. All six also fail on master's push CI for 06b122951a (runs 36634513687, 36634513732, 36634513103):
    • Same failure as master (pre-existing):
      • sublibraries / lib/NonlinearSolveBase [QA]: same failing tests, 18 passed / 1 failed / 1 errored (all_explicit_imports_are_public, all_qualified_accesses_are_public, public API is rendered in docs).
      • lib/NonlinearSolveFirstOrder [QA]: 19 passed / 1 errored, same tests.
      • lib/NonlinearSolveFirstOrder Core: 1113 passed / 21 errored, same erroring testsets.
      • lib/SCCNonlinearSolve Core: same isconcretetype(NonlinearSolution{…10 params…}) failure.
      • downgrade-sublibraries / test (lib/NonlinearSolveFirstOrder): 1512 passed / 28 errored, same erroring testsets.
    • tests / Core (julia lts, ubuntu-latest): red on master too, so not a regression at check level, but it now fails at a different point.
      • Master stops at the solve!() inference error (core_tests__item3.jl:27). This PR fixes that error: the macOS lts Core job on the PR passes completely.
      • The ubuntu job then fails at 23 Test Problems: Broyden, 6: Watson function | alg #2: 3.32 ≤ 1e-3, 92 passed / 1 failed.
      • That case is a direct Broyden(; init_jacobian = Val(:true_jacobian)) solve. It never enters the polyalgorithm solve! that was edited.
      • Since SciMLBase 3.57 no run on master or any open PR has reached this test; every one stops at the inference error first. So I could not show the Watson failure on master.
      • The last green master Core-lts ubuntu run (c5f0d24f27, job 109033370232) passed it on a self-hosted runner. The PR job ran on a GitHub-hosted ubuntu-latest runner. test/Core/23_test_problems_tests__item7.jl already documents that problems with Broyden true_jacobian (alg Refactor #2) flip between converging and failing depending on the runner.
    • Description gaps: the PR body accounts for only 3 of the 6 red checks. NonlinearSolveBase QA, FirstOrder Core and downgrade FirstOrder go unmentioned; all three are pre-existing. It claims SCC Core is fixed by Keep spelled NonlinearSolution element type concrete across SciMLBase layouts #1332, which I did not verify.
    • Discussion: there are no review comments or reviews on the PR.
  • Independent review: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence: the diff is a one-line typeassert on the existing ReturnCode.T field type, matching the neighbouring _uType/_traceType asserts. Every failing check also fails on master. The newly visible Watson/Broyden failure cannot reach the changed code and is runner-dependent.
  • Merge: auto-merge candidate. No regressions against master, though two caveats remain:
    • The PR is still a draft marked "ignore until reviewed by @ChrisRackauckas".
    • Core (julia lts, ubuntu) will stay red after merge because of the Watson/Broyden alg Refactor #2 knife-edge failure. Re-running that job, or a separate fix for the Broyden test, would settle whether it predates this PR.

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Claude Code 2.1.285 fleet-master head, model claude-opus-5-5[1m]
Conversation: local session 3c311569-dda6-4687-bc9f-65febb212c33 (no session URL)

Adopted 2026-10-07 (ci-green head)

What changed: rebased onto master 0055e314 (after #1356 and #1357); no code change. Head is now 7f0d1d0f.

Root cause / where the fix belongs: SciMLBase v3.57.0 (SciML/SciMLBase.jl#1620) made retcode::RC a type parameter on purpose, for Reactant traced return codes. SciMLBase cannot restore inference here. The value of RC comes from typeof(retcode), and on Julia 1.10 cache.caches[idx].retcode with a runtime idx infers as Any. Only the call site knows that every subcache's retcode is a ReturnCode.T, so the assert belongs here in NonlinearSolveBase.

Verification (Julia 1.10.12, SciMLBase 3.57.0, env with root and all lib/* devved from the worktree):

test/Core/core_tests__item3.jl, master 0055e314 (fails before):

solve() inference |    8      8  32.3s
solve!() inference: Error During Test at .../test/Core/core_tests__item3.jl:27
  return type NonlinearSolution{Float64, 1, ..., SciMLBase.ReturnCode.T} does not match inferred return type NonlinearSolution{...}
solve!() inference |     1      1  16.0s

This branch (passes after):

solve() inference |    8      8  36.6s
solve!() inference |    8      8  49.1s

The full root GROUP=Core run on lts with this branch ran 82 testsets and exited 0: PolyAlgorithm Type Inference | 16 16, 23 Test Problems: Broyden | 93 pass, 22 broken. The Watson/Broyden failure seen on CI earlier did not reproduce locally on AMD. Runic --check and typos on the changed file: clean.

Red checks after the rebase (CI is still running):

Risk assessment

  • Risk: low
  • Blast radius: one typeassert in the generated polyalgorithm solve! fall-through branch (lib/NonlinearSolveBase/src/solve.jl). It does nothing at runtime for ReturnCode.T retcodes and changes no public API. A non-ReturnCode.T sub-retcode would already fail at the ReturnCode.T-typed cache.retcode store.
  • Evidence: item3 errors on master (1 errored) and passes on this branch (8/8 + 8/8) on Julia 1.10.12. The full Core group on lts passes locally.
  • Independent review: Codex gpt-6.1-sol re-reviewed the post-merge head b11d007 and rated it low, MERGE, high confidence: the assertion matches the documented cache contract and the existing regression test discriminates (reviews/NonlinearSolve-astra/reviews/pr-1347/round1/REVIEW.md on a fleet worker host). Its one non-blocking note is a pre-existing, unrelated reinit!/start_index=2 bug, tracked separately.
  • Merge: auto-merge candidate once CI on the rebased head is green apart from the SCC and benchmark checks classified above. This PR keeps "Ignore until reviewed by @ChrisRackauckas".

🤖 Generated with Claude Code (model: claude-opus-5-5[1m]) https://claude.ai/code/session_011aK5Xvp9NpdkzKuEwtiMGd

…ndex

On Julia 1.10, `cache.caches[idx]` with a runtime `idx` infers `Any`, so
`cache.caches[idx].retcode` reaches `build_solution_less_specialize` as
`Any` and `typeof(retcode)` cannot pin the new `RC` parameter that
SciMLBase 3.57 added to `NonlinearSolution`; `solve!` then infers the
partial UnionAll `NonlinearSolution{...}` and `@inferred` fails. Assert
`::ReturnCode.T`, matching the `_uType`/`_fuType`/`_traceType` asserts
already used in this generated body for the same 1.10 limitation.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3
Agent-Model: swe-2-high
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/NonlinearSolve.jl/jobs/inf310-devin/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 16, 2026 23:45
@ChrisRackauckas
ChrisRackauckas merged commit dad173f into SciML:master Oct 16, 2026
99 of 100 checks passed
ChrisRackauckas added a commit that referenced this pull request Oct 17, 2026
…ltiplicity

Picks up #1347 (PolyAlgorithm solve! retcode type assert for Julia 1.10
inference), fixing the lts Tests-Core and Downgrade-Tests-Core failures.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.92
Agent-Model: swe-2-max
Agent-Session: local Devin CLI session oss-fix/SciML-NonlinearSolve.jl-1375
@ChrisRackauckas-Claude

ChrisRackauckas-Claude commented Oct 18, 2026 •

Copy link
Copy Markdown
Member Author

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent runtime isolation for the shared Core LTS failure on seven open PRs: with the unchanged test/Core/core_tests__item3.jl test on Julia 1.10.12, pre-fix master e903b6bb passes 16/16 against SciMLBase parent 293085236eafc2c4ddc7b5e352d19a172e9a491b, and fails (8 passed, 1 error in solve!() inference) against its immediate child ee5dedb70057fae2f45dd20c4f3dba1e6dc1fbda. Other resolved dependencies were held fixed. Both source commits still declare package version 3.56.1; v3.57.0 is the first released tag containing the change.

The immediate master fix commit dad173fab67c0a880cec569efe073ed5c6acc02d passes 16/16 against that same first-bad dependency commit. Clean current master 8d5e163e also passes 16/16 with registered SciMLBase 3.58.0. These are local runs of the existing test file with its assertions unchanged.

All seven inspected heads lack dad173fa and retain the untyped cache.caches[idx].retcode read, so their reported inference errors are inherited from historical master. Classification comments have been posted on those PRs. No duplicate issue or fix PR was opened.

Links:


🤖 Posted by an AI agent — harness: Codex CLI · model: gpt-6.1-sol
Conversation: local headless job codex-nls-core-lts-20261017 (no session URL)

ChrisRackauckas referenced this pull request Oct 30, 2026
Bump versions: NonlinearSolveBase 2.55.1
Merge master to include Core inference fix

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Agent-Harness: Claude Code 2.1.302
Agent-Model: claude-sonnet-5-5
Claude-Session: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI
Agent-Model: gpt-6-luna
Agent-Session: local fixer job SciML__NonlinearSolve.jl__1378 (no session URL)
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.

2 participants