Skip to content

[fix] preserve the step budget and script-cache choice across Reset - #29

Merged
vt128 merged 1 commit into
masterfrom
fix/reset-preserves-limits
Jul 13, 2026
Merged

vt128 merged 1 commit into
masterfrom
fix/reset-preserves-limits

Conversation

@vt128

@vt128 vt128 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Problem

SetMaxExecutionSteps pushed the CPU-step budget onto the current starlet.Machine only — the Starbox kept no copy. Reset() swaps in a fresh machine (newStarMachine), which defaults to no step limit and an enabled script cache. So after the first run the guard silently vanished:

New → SetMaxExecutionSteps(1000) → Run → Reset → Run   // 2nd run had NO step guard

This directly contradicts Reset's own doc ("keeping the Box's limits"), and Reset is exactly the sanctioned path for serially reusing one Box across untrusted scripts — so a security-minded host hits the dangerous case. SetScriptCache(nil) (disable) had the symmetric bug: Reset re-enabled the cache.

maxOutputEntries did not have this bug because it is a struct field re-read at run time — the asymmetry confirmed the root cause.

Fix

  • Promote maxSteps / scriptCache / scriptCacheSet to Starbox fields; the setters store them.
  • Reset() re-applies both to the fresh machine eagerly (right after newStarMachine), not lazily at the next run — so a caller that reaches for the raw machine via GetMachine() immediately after Reset() also sees the guard, closing that bypass.
  • applyScriptCache() respects scriptCacheSet: an untouched cache stays default-enabled; an explicit SetScriptCache(nil) stays disabled across every Reset.

Test

TestMaxExecutionStepsSurvivesReset (test-first): set budget → Run (hits MaxStepsExceededError) → Reset() → Run → still hits MaxStepsExceededError.

Verification

gofmt/go vet clean; go test, go test -race -count=2, and docker golang:1.19 go test -race all green.

Reset replaces the machine with a fresh one that defaults to no step budget,
but SetMaxExecutionSteps only ever pushed the budget onto the current machine
with no field on the Box, so New -> SetMaxExecutionSteps -> Run -> Reset -> Run
left every run from the second onward with NO CPU-DoS guard — on exactly the
serial-reuse-of-one-Box path Reset is meant for. That contradicts Reset's own
doc ("keeping the Box's ... limits"), and it is asymmetric with maxOutputEntries,
which is a Box field read at run time and therefore already survived Reset.

The budget is now a Box field (maxSteps), and prepareEnv re-applies it to each
machine on the first run after construction/Reset, the same shape as the other
Box-level configuration. SetScriptCache had the same machine-only flaw (Reset's
newStarMachine re-enables the cache), so its choice is stored on the Box and
replayed too.

Test: TestMaxExecutionStepsSurvivesReset — set a budget, hit it, Reset, and the
next run still hits MaxStepsExceededError.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Jul 13, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation +0.01% coverage variation (-1.00%)
Diff coverage 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (fd18a0f) Report Missing Report Missing Report Missing
Head commit (fb4d38b) 1169 (+15) 1160 (+15) 99.23% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#29) 17 17 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.96%. Comparing base (fd18a0f) to head (fb4d38b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #29      +/-   ##
==========================================
+ Coverage   98.95%   98.96%   +0.01%     
==========================================
  Files          12       12              
  Lines         862      871       +9     
==========================================
+ Hits          853      862       +9     
  Misses          5        5              
  Partials        4        4              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vt128
vt128 merged commit b90ec7d into master Jul 13, 2026
11 checks passed
@vt128
vt128 deleted the fix/reset-preserves-limits branch July 13, 2026 06:45
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.

1 participant