Skip to content

Fix DDE HistoryFunction boundary after reinit! - #4748

Merged
ChrisRackauckas merged 4 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4743-dde-reinit-history-boundary
Oct 16, 2026
Merged

ChrisRackauckas merged 4 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4743-dde-reinit-history-boundary

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

DelayDiffEq.HistoryFunction decided whether a query belongs to the user history by comparing against sol.prob.tspan[1]. reinit! updates the history integrator's saved times to the new t0 but leaves prob.tspan unchanged, so queries in [t0_old, t0_new) skipped the user history and extrapolated the reset solution (returning 2.0 instead of 1.9 for the analytic u=2+t reproducer).

This PR uses the actual solution start for the internal HistoryODEIntegrator (sol.t[1], with a fallback when empty) for both out-of-place and in-place history paths, including the initial-time constant-extrapolation check. Ordinary DEIntegrator wrappers keep using sol.prob.tspan[1], so save_start=false ODE-backed history wrappers stay correct.

Fixes #4743

Round-2 revision (Codex review)

Independent review: Codex gpt-6-astra, round 2 VERDICT MERGE, RISK low (high confidence).

Blocking finding 1: unconditional sol.t[1] broke ordinary ODE wrappers with save_start=false (in-interval query returned -100 instead of 2.05). Fixed by dispatching history_start_time on HistoryODEIntegrator vs other DEIntegrators. Reviewer reproducer added to test/interface/history_function.jl.

Blocking finding 2: reinit_history_boundary.jl failed Runic 1.10.0 (1e-8 → 1.0e-8). Formatted; --check --diff now exits 0 on all touched files.

Numerical impact

  • Non-reinit! DDE solves: bit-identical to master on three standard problems (constant-lag Tsit5, prob_dde_constant_1delay_scalar BS3, vanishing-delay RK4); diff of serialized (t,u) was empty (BIT_DIFF_EXIT=0).
  • After reinit! on the issue reproducer: history at -0.1 changes from 2.0 → 1.9; max |u-(2+t)| from 5.23e-3 → ~1e-14. This is a correctness fix for reinitialized solves, not a deliberate algorithm change.

Fail-before / pass-after evidence

#4743 reinit boundary

Negative control (restore only history_function.jl to master, keep the new test/reproducer):

NEGATIVE_CONTROL history=2.0 expected=1.9
NEGATIVE_CONTROL retcode=Success max_err=0.00522803766877189
NEGATIVE_CONTROL would_pass_hist=false would_pass_err=false
NEGATIVE_CONTROL_FAILS_AS_EXPECTED

With the DDE fix:

AFTER_FIX history=1.9 err=9.325873406851315e-15 ret=Success

Regression file test/integrators/reinit_history_boundary.jl: all four testsets passed (oop 6, iip 4, save_start/erase_sol 16, backwards 4). Integrators Reinitialization Tests: 54/54.

Generic ODE save_start=false (reviewer reproducer)

Three-way on generic-regression.jl (Julia 1.12.7):

Tree Exit Observed
Prior head 4b4abef 1 hist(nothing, 0.05) → -100.0 (expected ≈ 2.05)
origin/master 0 Pass
Fixed head c1558f755 0 Pass

Commands run (round 2)

# three-way generic regression
julia +1.12 --project=$HEADENV generic-regression.jl   # HEAD_EXIT=1, -100.0
julia +1.12 --project=$MASTERENV generic-regression.jl # MASTER_EXIT=0
julia +1.12 --project=$FIXEDENV generic-regression.jl  # FIXED_EXIT=0

# #4743 regressions under fixedenv
julia +1.12 --project=$FIXEDENV -e 'include(".../reinit_history_boundary.jl")'
# → REINIT4743_EXIT=0 (30/30)

# bit-identical non-reinit vs master
BIT_LABEL=fixed/master julia ... bitidentical.jl
diff bitidentical_fixed.jldata bitidentical_master.jldata  # BIT_DIFF_EXIT=0

# suites
cd lib/DelayDiffEq && GROUP=Interface julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
# → INTERFACE_EXIT=0; History Function Tests 82/82; Testing DelayDiffEq tests passed
cd lib/DelayDiffEq && GROUP=Integrators julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
# → INTEGRATORS_EXIT=0; Reinitialization 54/54; Testing DelayDiffEq tests passed

# Runic 1.10.0
julia +1.12 --project=@runic -e 'using Runic; println(pkgversion(Runic)); exit(Runic.main(ARGS))' -- --check --diff <touched files>
# → RUNIC_EXIT=0 for each of the three touched files

Not verified

  • Full GROUP=ALL / SDDE / QA / Regression suites beyond Integrators+Interface
  • Performance (instruction/allocation) — not claimed
  • reinit! that flips integration direction (tdir sign change) — out of scope; pre-existing on master per review
  • Updating prob.tspan inside reinit! as an alternate fix (deliberately avoided)

Risk assessment

  • Risk: low
  • Blast radius: DelayDiffEq history lookup only. history_start_time dispatches so that ordinary ODE-backed HistoryFunction wrappers keep master's tspan[1] boundary, and only the internal HistoryODEIntegrator, which always saves its start, uses sol.t[1]. No public API change.
  • Evidence: the reinit! on a DDE integrator leaves the history boundary at the old tspan[1], returning wrong history values #4743 reproducer returns history 2.0 without the fix and 1.9 with it. The reviewer's ODE save_start=false regression fails on 4b4abef, passes on master and passes here. Non-reinit DDE solves are bit-identical to master. DelayDiffEq Interface and Integrators pass. Runic 1.10.0 and typos are clean.
  • Independent review: Codex gpt-6-astra, a different harness from the author. Round 1 was CHANGES (medium): the unconditional sol.t[1] broke ODE wrappers with save_start=false, and the new test file failed Runic. Round 2 on c1558f7 rated it low, high confidence, VERDICT MERGE, no blocking findings.
  • CI: the red jobs are unrelated to this PR. SciMLSensitivity Core1, the 2 downgrade jobs, and DelayDiffEq Regression (the Waltman Rodas5P NaN on Julia 1.13.1) also fail on master. benchmark (1) failed on a missing AirspeedVelocity action file (runner infrastructure) and passes on other PRs.
  • Merge: low-risk candidate.

Independent review and orchestration: 🤖 Claude Code (model: claude-opus-5-5[1m]), session https://claude.ai/code/session_015tNYhuzygK9z8yhh6MNCAz

Risk assessment (independent review, codex-cli gpt-6.1-sol, reviewed head c597dbf)

  • Risk: low
  • Blast radius: DelayDiffEq history lookup and initial-time extrapolation after reinitialization. The new helper distinguishes the internal history integrator from ordinary ODE-backed wrappers. No added dependencies, supported API removals/signature changes, removed assertions, weakened tolerances, or added test silencing.
  • Evidence: Reviewed head c597dbff8d300c4e03ca6e467cb82e5335b82ba7; all four PR heads were rechecked at the end and remained unchanged. On Julia 1.13.0 with four threads, ./run-julia.sh --project=env-4748 test-4748.jl passed 30/30 boundary assertions and 82/82 history-interface assertions; ./run-julia.sh --project=env-4748 probe-4748.jl passed 17/17 additional assertions (129 total). These cover the linked issue's expected history value and accurate solve, in-place/out-of-place paths, save-start/erase-solution combinations, backwards integration, ordinary ODE wrappers with save_start=false, derivative/indexed queries, earlier restart times, and initial constant extrapolation. Main log, additional checks. CI: {'IN_PROGRESS': 5, 'SUCCESS': 11, 'QUEUED': 121, 'SKIPPED': 1}, with no completed failures; format, spelling, and docs passed. Sublibrary CI remains pending. Full local Integrators/QA/SDDE/Regression groups, integration-direction reversal during reinit, GPU, and performance were not run.
  • Independent review: codex-cli 0.163.0 gpt-6.1-sol rated it low, high confidence: the boundary comes from the internal history's actual start, generic ODE behavior is preserved, and all 129 targeted assertions pass.
  • Merge: auto-merge candidate once pending CI completes without regressions — small internal correctness fix with no blocking review findings; CI is not yet complete.

🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6.1-sol (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq

ChrisRackauckas and others added 3 commits October 2, 2026 23:24
HistoryFunction compared queries against sol.prob.tspan[1], which reinit!
does not update, so lagged values between the old and new start used the
reset solution instead of the user history. Use the actual solution start
(sol.t[1]) so reinitialized solves keep the correct history boundary.

Fixes SciML#4743

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4743-cursor/log.txt on amdci2
Using sol.t[1] for every DEIntegrator broke ordinary ODE wrappers with
save_start=false; keep that path on problem tspan and only use the saved
start for the internal DDE history integrator.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4743-cursor-fix2/log.txt on amdci2
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration)
Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_OrdinaryDiffEq.jl-4748/log.txt
@ChrisRackauckas

Copy link
Copy Markdown
Member

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

Merged the default branch into this PR (clean merge, no conflicts; head ebdb268) so CI runs on current master. Its earlier failures in SciMLSensitivity Core1 and the downgrade jobs were fixed on master after this PR's last CI run.


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 16, 2026 21:48
@ChrisRackauckas
ChrisRackauckas merged commit 9aef078 into SciML:master Oct 16, 2026
139 of 140 checks passed
ChrisRackauckas referenced this pull request Oct 18, 2026
Bump versions: DelayDiffEq 6.4.4
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Agent-Harness: Claude Code 2.1.301
Agent-Model: claude-opus-5-5
Claude-Session: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq
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.

reinit! on a DDE integrator leaves the history boundary at the old tspan[1], returning wrong history values

2 participants