feat(recursion): add controlled depth >1 experiments #43
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/prolog-rlm!43
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/issue-20-deep-recursion-experiments"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
max_recursion_depthalone is no longer enough; callers must also passexperimental_deep_recursion(true)rlm_deep_experimentwithout introducing a second executor; it reuses the production typed-plan, agent, artifact, and benchmark runtimeshelps,hurts, orneutralinstead of assuming depth is beneficialbenchmark/run.pl -- deep-experimentfor deterministic structural evidencebenchmark/run.pl -- deep-integrationfor REAL OpenRouter depth 0/1/2 measurements using a trusted injected planner and real provider calls inside the measured treerlm_plannow records an append-onlymodel_responsesledger that survives nested lexical scope restoration, andrlm_completionaggregates that ledger instead of inferring all calls from top-level varsSafety boundary
experimental_deep_recursion(true)is an opt-in marker only. It grants no model, tool, context, agent, parallel, retry, graph, or filesystem capability and does not widen any runtime budget.The supported public facade rejects requested depth >1 before planner execution unless that explicit marker is present.
Nested typed plans continue to execute through the existing shared
rlm_planstate, so recursive children do not receive fresh step/model/tool/context budgets.Accounting defect found during live validation
The first REAL depth-2 run executed successfully, but reported only 2 provider calls where the tree had actually made 3. The root cause was a legacy assumption in
plan_usage/2: it scanned only final top-level variables. Nestedrlm(...)scopes intentionally restore child-local variables, so the intermediate depth-2 model response disappeared from the final lexical scope even though its provider call, tokens, and cost were real.The fix is an append-only model-response ledger in the plan execution state. Every successful provider response is recorded before lexical binding. Nested scope restoration does not remove ledger entries. Successful plan results expose the ledger, and completion usage now sums it exactly once per recorded provider response. Error plan results also retain the ledger for follow-up error-path accounting work (#44).
Regression tests verify:
Deterministic evidence
Exact head
158716e07196cb94f4dad5ff7192d02ea948f845passes:The deterministic experiment intentionally labels token/call/cost numbers as modeled fixture data; it does not claim provider economics. Its promotion evidence sets
live_trials:0, so deterministic success cannot promote depth >1.REAL OpenRouter evidence
The exact-head credentialed lane is fully green: core, structured repair, normal provider benchmark, depth 0/1/2 experiment, and one-command RLM CLI smoke.
The fixed live experiment planner is injected locally and makes zero network calls. The recursive tree itself produced the expected exact provider-call cardinality:
All three returned
LIVE_DEEP_OK, had the requested recursion depth, HTTP-successful provider responses, and quality 1.0. Free-route provider-reported cost was $0 for this run. Total experiment usage was 6 provider calls and 467 tokens.The latency result is intentionally not treated as evidence that depth 2 is faster than depth 1:
openrouter/freedynamically selected different models and one run is noisy. The encoded promotion rule still requires at least 20 live trials across at least 3 independent fixtures, positive quality delta, bounded cost/latency ratios, and zero safety failures.Follow-ups discovered during this work
These are explicit follow-up correctness items. They do not weaken #20's execution, global-budget, capability-narrowing, cancellation, or successful-call accounting acceptance evidence.
Closes #20