Skip to content

Reject wrong-length out for idxs=nothing interpolation - #4639

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:interp-out-size
Sep 27, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:interp-out-size

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Stacked on #4607 @ 9a75ffb9f — reviewers should look only at the commits after that tip.

What changed and why

With idxs === nothing, the in-place dense _ode_interpolant! kernels loop over out's indices under @inbounds with no length check against the state. A short out silently truncates; a long out OOB-reads past the end of u (observed as garbage like 8e-310). This extends the existing entry-point guards from #4607 so that when idxs === nothing and the state is not a Number, length(out) == length(u) is required (via the existing @noinline DimensionMismatch helper). Length, not axes, so equal-length differently shaped buffers (matrix state with vector out, ArrayPartition, ComponentArray, VectorOfArray) keep working.

Reference state (Astra review): the length check must use the same interpolated-interval states that #4607 uses for idxs — timeseries[i₋]/timeseries[i₊] after the interval is chosen, and integrator.uprev/integrator.u on the integrator/extrapolant paths — not timeseries[1], which rejects a correctly sized buffer after callback resize! and leaves a wrong-sized one unchecked after shrink.

Vector-of-times: reuses #4607's per-time axes cache — one axes comparison per requested time; full _check_interpolant_idxs_out (and idxs checkbounds rescan) only when the interval states' axes change. When axes are unchanged and idxs === nothing, still O(1)-check each time's out length against those axes (not a rescan). Bool-mask counting via _interpolant_idxs_count is preserved from #4607. The idxs === nothing length checks run only for slots in eachindex(tvals) (the main loop's written range), matching #4607 @ 9a75ffb9f's over-long-buffer rule: extra slots beyond length(tvals) are never read or validated.

Uninitialized scalar batch outs (Astra MERGE @ a212896eb): the vector-of-times guard must not _get_val(vals, j) on the replace-slot path (_set_val!), where slots may be uninitialized Vector{Any} / Vector{BigFloat}. Read and length-validate only when _vals_eltype(vals) <: AbstractArray (mutate-in-place); on the replace path, validate idxs against the interval states without reading the slot. #4607 applies the same rule to the idxs !== nothing output-slot preflight (eachindex(tvals) @ 9a75ffb9f); this branch keeps both fixes.

Verification

Runic --check exit 0; typos over the changed files exit 0.

GROUP=Core for OrdinaryDiffEqCore (Pkg.test) under both --check-bounds=yes and auto:

Test Summary:                     | Pass  Total   Time
Interpolation idxs/out validation |   89     89  38.9s
...
     Testing OrdinaryDiffEqCore tests passed

Standalone interpolation_idxs_bounds_tests.jl (Bool-mask, extrapolation, resize, uninitialized outs + over-long buffers from #4607, idxs=nothing over-long, uninitialized scalar batch): 89 / 89 under both --check-bounds=yes and auto (prior 79 + 5 from #4607 over-long idxs + 5 idxs=nothing over-long).

scalar-undef.jl: 4 / 4 under both --check-bounds=yes and auto.

Failing-before / passing-after

Prior revision on #4607 tip 1a69f7740 (before Bool-mask / axes-cache): new assertions alone were 36 pass / 21 fail without the fix (yes: shorts no-throw, longs BoundsError; auto: all 21 no-throw) → 57 / 57 with the fix.

Rebased onto 45804a031 (adds Bool-mask tests; total suite was 67 = prior 57 + 10 Bool-mask assertions): both bounds modes 67 / 67.

Uninitialized scalar batch buffers (Vector{Any} / Vector{BigFloat} × Float64 / BigFloat state) at edb6952f2 via scalar-undef.jl: 1 pass / 3 errors under both --check-bounds=yes and auto (UndefRefError from unconditional _get_val). After a212896ebd: 4 / 4 under both modes; full suite 71 / 71. Astra then MERGED at a212896eb.

Rebased onto 5fcf6165c (adds #4607 uninitialized-outs testset; tip 3adf6d71e4): suite 79 / 79 under both bounds modes.

Rebased onto 9a75ffb9f (narrows #4607's up-front preflight to eachindex(tvals)). Over-long vals with idxs=[1] failed at 3adf6d71e (UndefRefError / DimensionMismatch on the extra slot) and passes after. Over-long vals with idxs=nothing already passed at 3adf6d71e (this PR never inspected extra slots) and still passes; assertions added. Suite 89 / 89 under both bounds modes.

CI-discriminating assertions (--check-bounds=yes): shorts fail because nothing is thrown; longs fail because BoundsError ≠ DimensionMismatch. Under --check-bounds=auto the wrong-length cases discriminate as "no exception". Exact-sized outs after grow 2→3 / shrink 3→2 are accepted; extrapolation path covered.

Before/after numbers

Unchanged from the previous revision (guard is still a length compare on already-entered paths; axes cache skips idxs rescan; scalar replace path skips the slot read). Prior microbench on the 4607 stack: sol(out,t)×1000 and init+step!+integ(out,t) minima were noise-only vs the prior tip; allocs stayed 0 / 98.

What was not verified

  • Full GROUP=ALL / QA / GPU for OrdinaryDiffEqCore
  • Every solver sublibrary's interpolant under wrong-length out (guard is at the Core entry points)
  • Production workloads beyond the prior microbenchmarks

Risk assessment

  • Risk: Low–medium — length check on already-guarded in-place entry points; valid equal-length calls (including post-resize!, over-long untouched extras, and uninitialized scalar batch outs) unchanged; wrong-length callers that previously truncated/OOB now throw DimensionMismatch.
  • Blast radius: OrdinaryDiffEqCore in-place dense interpolation / extrapolation when idxs === nothing.
  • Evidence: Suite green under both bounds modes on 9a75ffb9f stack (89 / 89); resize grow/shrink; extrapolation; Bool masks / uninitialized outs / over-long buffers from Validate idxs/out in in-place interpolation entry points #4607; idxs=nothing over-long; scalar undef regressions; GROUP=Core green; Runic/typos clean.
  • Independent review: Claude Code (Opus 5.5) at 435460f: MERGE, low risk, high confidence. A 1160-case idxs=nothing audit versus master found every valid-on-master call unchanged; the only new errors are DimensionMismatch for wrong-length out, where master silently truncated, threw BoundsError, or segfaulted. All earlier reviewer scripts pass, and perf is not worse. The earlier Codex gpt-6-astra review (MERGE @a212896eb) found the resize, extrapolation and uninitialized-buffer issues, all fixed.
  • Merge: low-risk candidate, merge after Validate idxs/out in in-place interpolation entry points #4607 (stacked). OrdinaryDiffEqCore Core passes on Julia 1, LTS and pre, as do QA and downgrade; the red jobs are the known master-red set.

🤖 Generated with Cursor Agent (model: auto)

Risk assessment

  • Risk: low

  • Blast radius: In-place solution/integrator interpolation and extrapolation across OrdinaryDiffEq solvers. Invalid indices/buffer lengths now throw instead of truncating or reading out of bounds—a disclosed behavior correction, with no signature change. No weakened tests or new non-public dependency access found.

  • Evidence: Head 435460f0e has 253 passing checks and seven failures, all reproduced with matching errors on recent master commits:

    • SciMLSensitivity.jl/Core1/1: Mooncake Any constructor error—pre-existing on 3178b1948.
    • downgrade-sublibraries / test (lib/DiffEqBase): callback-related assertions/errors—pre-existing on 8b3a3b07a.
    • downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation): missing diag(::ScalarOperator)—pre-existing on 8b3a3b07a.
    • Sublibrary Julia 1/Core checks for OrdinaryDiffEqDifferentiation, OrdinaryDiffEqNonlinearSolve, and GlobalDiffEq: respectively missing diag, Trapezoid mass-matrix rejection, and callback rejection—pre-existing on 3178b1948.
    • DelayDiffEq [Regression] / Julia 1: Waltman matrix contains Infs/NaNs—also fails on 3178b1948, although older master runs passed.

    Core tests on Julia 1/LTS/pre, QA, downgrade, and Core GPU pass. Top-level GPU was cancelled; master 85110ac2a fails its QNDF test, so GPU equivalence remains unverified. The description omits that cancellation. No review comments exist.

  • Independent review: Codex CLI 0.156.1 (Mac) / gpt-6-astra rated it low, high confidence: the full diff adds targeted validation and regression coverage, and all seven completed failing checks match master failures.

  • Merge: auto-merge candidate after its still-open prerequisite Validate idxs/out in in-place interpolation entry points #4607 merges; no demonstrated test regressions.


🤖 Risk assessment posted by an AI agent (fleet master) — harness: Codex CLI 0.156.1 (Mac) / gpt-6-astra; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL)

ChrisRackauckas and others added 3 commits September 27, 2026 14:44
With idxs === nothing the in-place dense kernels loop over out under
@inbounds with no length check against the state, so a short out
silently truncates and a long out OOB-reads state. Require
length(out) == length(u) against the interpolated interval's states
(timeseries[i₋]/[i₊], integrator.uprev/u), per requested time in the
vector path — not timeseries[1], which breaks after callback resize!.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log.txt)
The idxs===nothing length guard read vals[j] before choosing the
mutate-in-place vs replace-slot path, so Vector{Any}/BigFloat(undef)
buffers that only need _set_val! threw UndefRefError. Read and length-
check only on AbstractArray element paths; validate idxs vs state
without reading the slot on the replace path.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log.txt)
Mirror SciML#4607's eachindex(tvals) over-long buffer coverage for the
idxs===nothing path: extra uninitialized or wrong-length slots beyond
the written range must remain untouched, matching master.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local cursor-agent session in /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-out-size/log6.txt)
@ChrisRackauckas
ChrisRackauckas merged commit 0fac2d0 into SciML:master Sep 27, 2026
256 of 264 checks passed
ChrisRackauckas referenced this pull request Sep 29, 2026
* Bump DiffEqBase to 7.21.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqBDF to 2.4.12

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSDIRK to 2.9.7

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqRosenbrock to 2.7.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqLowOrderRK to 2.2.6

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqTsit5 to 2.1.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqVerner to 2.4.2

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSymplecticRK to 2.2.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.

2 participants