Skip to content

Fix silent lcons/ucons length mismatch and undef constraint buffers - #1403

Draft
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:opt-cons-bounds-checks
Draft

ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:opt-cons-bounds-checks

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Summary

When cons! writes fewer entries than length(ucons), the DifferentiationInterface out-of-place constraint wrappers allocated Vector{T}(undef, num_cons), leaving garbage in unwritten slots that Ipopt/IPNewton can turn into silent Failure/NaN results. Those wrappers now use zero-initialized buffers (dense and sparse paths). Separately, mismatched lcons/ucons lengths were accepted by SciMLBase and then silently broadcast or crashed opaquely in solvers; _check_opt_alg now throws a clear ArgumentError when both are provided with different lengths (both-nothing and existing one-missing checks unchanged).

Regression evidence

  • Before (src stashed, tests present): OptimizationBase Core 61 passed, 6 failed — _check_opt_alg missing lcons/ucons 4 fail; zero-init buffer test failed with J[3,:] == [2.0e-323, 6.9e-310] style garbage. Logs: opt-cons/before.txt.
  • After: OptimizationBase Core 67 passed (Testing OptimizationBase tests passed). Logs: opt-cons/after.txt.
  • Julia 1.10.12 x64: regression tests (buffer + length mismatch) passed in an isolated temp env.

Test-group tails

  • OPTIMIZATION_TEST_GROUP=Core / Pkg.test(OptimizationBase): Test Summary: Core | Pass 67 Total 67 — tests passed
  • OPTIMIZATION_TEST_GROUP=QA on OptimizationBase: Test Summary: QA | Pass 20 Broken 1 Total 21 — tests passed
  • Root GROUP=QA / Pkg.test(Optimization): Test Summary: QA | Pass 21 Total 21 — tests passed
  • Runic --inplace + typos on touched files: clean

What was NOT verified

  • Full Ipopt/IPNewton/LBFGSB end-to-end re-run of auditor a3_safety.jl after the fix (unit regressions cover the two root causes).
  • OptimizationBase AD group / GROUP=All.
  • Whether SciMLBase should eventually own the length check (intentionally left in OptimizationBase per task).
  • SymbolicAnalysis Array{Num}(undef, num_cons) path (different type; not the float-garbage AD path).

Reviewer pushback

  • Is zero-filling the right semantic when num_cons exceeds what cons! writes (masks a user bug as constraint value 0), or should we also warn/error on write undercount?
  • Should length mismatch be rejected at OptimizationProblem construction in SciMLBase instead of only on solve/init?
  • Sparse DI path has the same zero-init change but no dedicated sparse regression beyond Core coverage.

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

Independent review: Claude Code (claude-opus-5-5) MERGE, risk low (confidence medium-high): every valid constraint path (inequality, equality, mixed; MOI-Ipopt, OptimizationIpopt, IPNewton, AugLag, LBFGSB; unconstrained) gives identical results to master; zero-fill has no measurable cost. Deliberate tightening: the lcons/ucons length check now rejects mismatched lengths even when they were previously tolerated (e.g. lcons length 1 with ucons length 2 through MOI-Ipopt, or bounds given without a constraint function); both are malformed inputs and no in-repo usage relies on them.

🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-cons/log.txt on amdci2; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Made with Cursor

Zero-initialize OOP constraint buffers used for AD Jacobians so undersized
cons! writes cannot leak undef memory into solvers, and reject mismatched
lcons/ucons lengths with a clear ArgumentError in _check_opt_alg.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Cursor Agent <noreply@cursor.com>
Agent-Harness: Cursor Agent 2026.10.01-14929f9
Agent-Model: unknown (Cursor auto)
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-cons/log.txt on amdci2

This branch has not been deployed

No deployments
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