Skip to content

fix(js): return normally when bounded simulations stop - #1490

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/fix/bounded-run-stop/return-normally-bounded-simulations-stop--3756bef6
Oct 18, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/fix/bounded-run-stop/return-normally-bounded-simulations-stop--3756bef6

Conversation

@tignear

@tignear tignear commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Simulation.runUntil(endTime, { maxSteps }) treated the Rust bounded loop's
false result as a timeout even when a design executed $stop. Return normally
when an allowed step suspends the simulation, so callers can inspect
isStopped() and resume it. Normalize fractional, negative and NaN budgets
before the native call and the stop check so effective zero-step budgets
still time out, including while a previous stop is pending.

A resumed time slot can stop again or exhaust its budget before consuming
pending host writes. Preserve dirty inputs after these interrupted resumptions
so output reads still perform lazy combinational evaluation.

Add TypeScript regressions for stop and resumption, normalized budgets, and
pending input writes across repeated stops and budget exhaustion. Extend the
Rust SystemVerilog $stop regression to verify bounded-loop results with
actual stopped processes.

Validation:

  • TypeScript Simulation unit tests (54 passed), package type checks, and Biome.
  • NAPI Simulation, timing-addon, cascaded-clock-addon, and e2e tests (168 passed).
  • Rust stop_suspends_the_simulation_until_it_continues regression.
  • cargo fmt and Clippy for the SystemVerilog integration test.
  • Reused the successful NAPI build and Rust checks from the prior revision;
    native sources are unchanged by this review fix.

Fixes #1464

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T10:00:39.295487Z 85a9753 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 142d77198f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +469 to +471
if (max > 0) {
this._state.dirty = false;
if (this.isStopped()) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize maxSteps before treating a stop as newly encountered

When a caller resumes an already-stopped simulation with a fractional positive budget below 1, the NAPI boundary truncates max_steps to zero (crates/celox-napi/src/lib.rs:2048), so the bounded run returns false without executing a step and leaves the old stopped state set. Because the original JavaScript value still satisfies max > 0, this branch mistakes that old state for a newly encountered $stop and returns normally instead of reporting budget exhaustion. Validate or normalize maxSteps before both the native call and this test so the effective zero-step budget retains the documented timeout behavior.

Useful? React with 👍 / 👎.

Comment thread packages/celox/src/simulation.ts Outdated
Comment on lines +470 to +471
this._state.dirty = false;
if (this.isStopped()) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve dirty inputs when resuming into another stop

When an input is written while the simulation is already suspended and the allowed step resumes directly into another $stop, the runtime prioritizes the suspended time slot and returns before processing the pending host write (crates/celox-runtime/src/simulation/time.rs:92-103). This new normal-return path nevertheless clears _state.dirty, so a subsequent output read skips its lazy evalComb() and can expose stale combinational outputs. Preserve the dirty state unless the bounded run actually consumed the host write.

Useful? React with 👍 / 👎.

Simulation.runUntil(endTime, { maxSteps }) treated the Rust bounded loop's
false result as a timeout even when a design executed $stop. Return normally
when an allowed step suspends the simulation, so callers can inspect
isStopped() and resume it. Normalize fractional, negative and NaN budgets
before the native call and the stop check so effective zero-step budgets
still time out, including while a previous stop is pending.

A resumed time slot can stop again or exhaust its budget before consuming
pending host writes. Preserve dirty inputs after these interrupted resumptions
so output reads still perform lazy combinational evaluation.

Add TypeScript regressions for stop and resumption, normalized budgets, and
pending input writes across repeated stops and budget exhaustion. Extend the
Rust SystemVerilog $stop regression to verify bounded-loop results with
actual stopped processes.

Validation:
- TypeScript Simulation unit tests (54 passed), package type checks, and Biome.
- NAPI Simulation, timing-addon, cascaded-clock-addon, and e2e tests (168 passed).
- Rust stop_suspends_the_simulation_until_it_continues regression.
- cargo fmt and Clippy for the SystemVerilog integration test.
- Reused the successful NAPI build and Rust checks from the prior revision;
  native sources are unchanged by this review fix.

Fixes #1464

Change-Id: I3756bef676de6da4b8e9884f9025a72083dc21ae
@tignear
tignear force-pushed the stack/tignear/fix/bounded-run-stop/return-normally-bounded-simulations-stop--3756bef6 branch from 142d771 to 85a9753 Compare October 18, 2026 09:58
@tignear

tignear commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 142d771 2026-10-18 09:57 UTC
2 content 142d771 → 85a9753 Address PR #1490 review: normalize native step budgets and preserve pending input evaluation across interrupted resumptions. 2026-10-18 09:57 UTC

@mergify mergify Bot added the queued Mergify queue entry label Oct 18, 2026
@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 42 minutes 24 seconds in the queue, including 36 minutes 45 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit 4fb8f67 into master Oct 18, 2026
30 checks passed
@mergify
mergify Bot deleted the stack/tignear/fix/bounded-run-stop/return-normally-bounded-simulations-stop--3756bef6 branch October 18, 2026 10:59
@mergify mergify Bot removed the queued Mergify queue entry label Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runUntil with maxSteps reports $stop as a timeout

1 participant