Skip to content

fix(core): validate scan sequence bounds and array dimensions across FTL, latent WM, CBP, and Step 4 - #2039

Open
rama0x1 wants to merge 1 commit into
elizaOS:mainfrom
rama0x1:fix/scan-sequence-bounds-validation-20260820-0022-agy
Open

fix(core): validate scan sequence bounds and array dimensions across FTL, latent WM, CBP, and Step 4#2039
rama0x1 wants to merge 1 commit into
elizaOS:mainfrom
rama0x1:fix/scan-sequence-bounds-validation-20260820-0022-agy

Conversation

@rama0x1

@rama0x1 rama0x1 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Hardens array-based transition scanning and learning loop routines against untrusted array types, incompatible array dimensions/ranks, invalid sequence lengths (num_steps < 1 or overflow), and potential signed-int32 scalar/byte allocation overflows across:

  1. alberta_framework.core.ftl_world_model.run_sparse_ftl_world_model
  2. alberta_framework.core.latent_world_model.run_latent_world_model_learning_loop
  3. alberta_framework.core.continual_backprop.run_cbp_learning_loop
  4. alberta_framework.core.option_value_duration.run_option_value_duration_from_arrays
  5. alberta_framework.steps.step4.run_step4_scan
  6. alberta_framework.core.learners (run_learning_loop, run_learning_loop_batched, run_mlp_learning_loop, run_mlp_learning_loop_batched, run_td_learning_loop, run_true_online_td_loop)

Key Changes

  • Exact component/state type verification: Checks model/learner and state objects to prevent silent state mismatches.
  • Array metadata enforcement: Verifies input transitions are trusted np.ndarray, jax.Array, or jax.core.Tracer instances with conforming shapes.
  • Sequence bounds validation: Ensures 1 <= num_steps <= 2**31 - 1 with canonical int index coercion rejecting boolean/float scalar aliases.
  • Resource preflight: Validates that output scalar/byte sizes fit signed int32 bounds prior to scanning.
  • Test coverage: Added tests/test_scan_sequence_bounds_validation.py covering positive evaluation and negative invalid type/shape/length error paths.

Validation

  • pytest tests/test_scan_sequence_bounds_validation.py -> 6/6 passed
  • pytest tests/test_ftl_world_model.py tests/test_latent_world_model.py tests/test_continual_backprop.py tests/test_option_value_duration.py tests/test_step4_production.py tests/test_td_learners.py tests/test_scan_sequence_bounds_validation.py -> 371/371 passed
  • ruff check . -> passed
  • mypy -> passed

…FTL, latent WM, CBP, and Step 4

Add explicit sequence length bounds checking (1 <= num_steps <= INT32_MAX), exact component/state type verification, trusted array metadata enforcement, rank/shape compatibility checking, and output resource preflight to array scan and learning loop functions in SparseFTLWorldModel, LatentWorldModel, ContinualBackprop, OptionValueDurationLearner, Step 4 SARSA, and core learners.
@github-actions

Copy link
Copy Markdown

Automated review ran but produced no report; leaving for a maintainer.

@github-actions github-actions Bot added the needs-human-review Claude triage: controversial, needs a human label Aug 19, 2026
@lalalune

Copy link
Copy Markdown
Member

Blocking: the new validators do not impose a finite scan ceiling. The affected paths call _require_int(..., minimum=1), _require_int32(..., minimum=1), or _require_positive_int(...) without an explicit maximum. Consequently, sequences with hundreds of thousands or millions of steps still pass and can trigger the same pathological JAX trace/compile this PR claims to prevent; the Step 4 path is unbounded as well.

Please use a documented finite ceiling at every affected scan (the sibling convention is 10,000), validate type/rank/leading length before materialization where applicable, and add regression tests that prove an oversized input is rejected before jax.lax.scan/allocation. The companion shape checks are useful, but this is not yet a scan-hang bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-human-review Claude triage: controversial, needs a human

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants