Repository navigation
C4a: enforce MaxCallDepth on bytecode CALL (default 1000, --max-call-depth) - #111
Merged
Merged
Conversation
…depth)
Review C4a (S5): ordinary bytecode CALL recursion was unbounded and could
end in a Go stack overflow when the runner raised the instruction budget.
BCVM now tracks active CALL frames and fails with structured
LIMIT_EXCEEDED ("call depth limit exceeded (max N)") at the CALL that
would exceed VMLimits.MaxCallDepth. N permits exactly N active frames;
non-positive ceilings fail closed. Depth unwinds on return, VmReturn and
propagating panics; SPAWN_AGENT children inherit the active call depth.
DefaultLimits.MaxCallDepth rises 128 -> 1000. The field was already
shared with SPAWN_AGENT nesting, so spawn nesting also defaults to 1000
(separate counters, same ceiling; existing spawn tests unchanged).
`--max-call-depth` is wired on -run-bc and `run` (bytecode target),
rejecting zero/negative like --max-instructions.
No C4b (alloc/deadline/fetch/exec caps), no AST interpreter change, no
HFBC/opcode change, no production -compile-bc flip; #90 stays Partial.
Journal: docs/journals/2026-10-06_c4a_max_call_depth.md
Co-authored-by: howlcipher <howlcipher@users.noreply.github.com>
howlcipher
commented
Oct 6, 2026
howlcipher
left a comment
Owner
Author
There was a problem hiding this comment.
Dev-lead COMMENT (head 8b00cd2d886eb47dd0cc0eab669f13ba081b39aa)
Verdict: merge-ready. Diff matches claimed C4a scope. CI build green on Go 1.21. Undraft + squash-merge when you are ready.
What matches
- Bytecode
CALLchecksMaxCallDepthbefore entering;LIMIT_EXCEEDEDwithopcode:"CALL"andcall depth limit exceeded (max N). - Depth increment + deferred decrement (LIFO with VmReturn recover) restores on normal return,
VmReturn, and propagating panic.TestCallDepthRestoredOnAllExitscovers the three exit shapes. - Semantics: main at 0; ceiling N allows N active CALL frames. Fail-closed for
<=0on CALL; programs without CALL still run. Boundary tests (5 pass / 6 fail, 999 under default, sequential shallow under ceiling 3) look right. SPAWN_AGENTchildren inherit parentcallDepth(no spawn-boundary reset). Spawn nesting still uses the separatespawnDepthcounter against the sameMaxCallDepthceiling.--max-call-depthon-run-bcandhowlframe run(bytecode), default 1000, rejects zero/negative. CLI test covers both runners.- Docs/journal/S5 PARTIAL + C4a status note are accurate. C4b, AST
-run, HFBC wire, prod-compile-bc/ #90 left alone.
Shared spawn default 128→1000
Non-blocker, noted as intentional. Raising DefaultLimits.MaxCallDepth softens SPAWN nesting ~8× because the field is shared. Mitigations already in place: separate counters, shared instruction budget still bounds spawn work, existing spawn depth-guard tests pass, runner can still lower via --max-call-depth. If spawn needs a tighter ceiling later, split MaxSpawnDepth from MaxCallDepth (out of C4a).
Hard nos
Intact: no prod HFIR / -compile-bc flip, #90 stays Partial, no HFBC wire/opcode change, no C5/harness/DOM.
No blockers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Review candidate C4a only (first bullet of C4 in
docs/ai-native-language-review/11-implementation-candidates.md; finding S5).CALLnow enforcesVMLimits.MaxCallDepth. Exceeding it fails with structuredLIMIT_EXCEEDED("opcode":"CALL","message":"call depth limit exceeded (max N)") instead of a Gofatal error: stack overflow.VmReturn, and propagating panics.SPAWN_AGENTchildren inherit the parent's active call depth.DefaultLimits.MaxCallDepthgoes from 128 to 1000. The field was already shared withSPAWN_AGENTnesting, so spawn nesting also defaults to 1000. The two counters are separate and use the same ceiling. Existing spawn tests (including the depth-2 guard) pass unchanged.--max-call-depthflag (default 1000) on-run-bcandhowlframe run(bytecode target). Zero and negative values are rejected, the same way as--max-instructions.Tests
internal/vm/call_depth_test.go: default value; unbounded recursion with a 10M budget gives LIMIT_EXCEEDED; exact boundary (5 frames pass, 6 fail); 999 frames pass under the default; sequential shallow calls under ceiling 3; zero and negative ceilings with CALL fail; zero without CALL runs; spawn inherits call depth; depth restored on every exit path.howlframe_test.goTestRunBytecodeMaxCallDepthFlag:-run-bcandrunwith default (pass),3(LIMIT_EXCEEDED),0and-1(rejected).gofmt -l .empty,go vet ./...clean,go test ./... -count=1green.(call f)with-run-bc --max-instructions 2000000000now exits 1 in ~50 ms with LIMIT_EXCEEDED.Not in this PR
--deadline, fetch/exec byte caps), C5 receipts.-run/run --target=interpreter) recursion is still not bounded by this limit.-compile-bcis not flipped, and Write flagged http_server bytecode and stop #90 stays Partial.Journal:
docs/journals/2026-10-06_c4a_max_call_depth.md