Skip to content

Fix metta_calculus step budget - #58

Closed
MesTTo wants to merge 3 commits into
trueagi-io:mainfrom
MesTTo:pr/mork-semantic-regression-tests
Closed

Fix metta_calculus step budget#58
MesTTo wants to merge 3 commits into
trueagi-io:mainfrom
MesTTo:pr/mork-semantic-regression-tests

Conversation

@MesTTo

@MesTTo MesTTo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Makes Space::metta_calculus(steps) honor its budget exactly: the loop checked done < steps only after fetching and interpreting an exec, so budget 0 still ran one redex and budget k ran k+1. The fix checks before interpreting, so 0 does nothing and k runs exactly k. Ten regression tests pin the semantics, including a pending-surplus case (five execs pending, budget 3: return 3, three rewrites, two still scheduled) that fails on the unfixed loop.

Two main.rs call sites relied on the old off-by-one (bench_flybase and the meta-exec staging case in mork test, both passing 0 to run one exec); they now pass 1, and mork test exits 0.

Benchmark impact, disclosed: every benchmark in mork bench all uses a run-to-fixpoint budget and is byte-identical under the fix (verified: bfc steps 801 / size 2872847, counter_machine 1813/2753, fringe 46/803777, and the rest) — except exponential, whose budget binds: it previously executed 33 steps while reporting 32 (size 265723), and now executes exactly the 32 it reports (size 206675). The old number was the bug made visible; work now equals the report. The two budget-limited chainer prints in mork test shift one frontier step for the same reason.

Sequencing: #110 carries this same fix byte-identically plus the chaining-semantics tests; land either first and the other rebases (comments on both PRs).

@MesTTo
MesTTo marked this pull request as ready for review June 23, 2026 10:23
@MesTTo

MesTTo commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Note for review order: #110 contains this same step-budget fix (its diff is a superset: the fix plus the query/chaining semantics tests). Land this one first and #110 rebases to tests-only, or land #110 and this closes.

MesTTo added 3 commits July 4, 2026 23:25
bench_flybase and the meta-exec staging test in mork test both called
metta_calculus(0) depending on the pre-fix loop running one exec anyway. Under
the exact budget they become no-ops and the staging test's assert fails; both
want exactly one redex, so pass 1. mork test exits 0 again with the fix.
Five independent execs pending, budget 3: exactly three interpret (return 3,
three rewrites in the space, two execs still scheduled). The old loop ran
budget+1, which is the divergence the exponential bench made visible (33 steps
of work reported as 32). Counts are line-anchored because the pending execs'
templates also contain the output pattern text.
@MesTTo
MesTTo force-pushed the pr/mork-semantic-regression-tests branch from aac6a9a to ffefb5a Compare July 4, 2026 13:29
@Adam-Vandervorst

Copy link
Copy Markdown
Collaborator

Yeah, in hindsight, this would've been a better interpretation than "repetitions" to be performed after a rewrite. However, I'm not sure we can change this now given how many places downstream rely on this interpretation. In any case, ths is not a bug, and all usage sites should be updated accordingly (instead of changing the semantics).

@MesTTo

MesTTo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

fair, it's not a bug then, the repetitions interpretation is load-bearing downstream. closing, i'll leave the semantics alone.

@MesTTo MesTTo closed this Jul 15, 2026
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