[P2] Preserve provider usage when completion plan execution fails #44

Closed
opened 2026-08-13 07:08:06 +00:00 by lost-rob0t · 0 comments
lost-rob0t commented 2026-08-13 07:08:06 +00:00 (Migrated from github.com)

Problem

Issue #20 added an append-only model_responses ledger in rlm_plan so nested model calls remain accountable even when child lexical vars are restored. Successful rlm_completion/4 results now aggregate that ledger correctly.

However, completion_after_execution/8 currently returns error(Error) immediately when plan_run/5 fails. The plan error now contains model_responses, but rlm_completion does not aggregate or attach their usage on the error path.

Therefore a plan that successfully consumes provider tokens/cost and then fails on a later tool/context/final operation can lose those provider usage totals from the completion outcome.

Desired behavior

  • aggregate planner + executed model usage on both success and error paths;
  • preserve the original execution failure as structured cause/detail;
  • surface any post-call token/cost/model-call budget violation without hiding the original failure;
  • keep cancellation/time-limit control semantics intact;
  • add deterministic regression coverage for provider call(s) followed by a plan execution failure.

Constraints

Do not double-count retries or responses. Reuse the model_responses ledger introduced during #20 instead of reconstructing usage from visible vars.

Discovered by

PR #43 / issue #20 deep-recursion accounting audit.

## Problem Issue #20 added an append-only `model_responses` ledger in `rlm_plan` so nested model calls remain accountable even when child lexical vars are restored. Successful `rlm_completion/4` results now aggregate that ledger correctly. However, `completion_after_execution/8` currently returns `error(Error)` immediately when `plan_run/5` fails. The plan error now contains `model_responses`, but `rlm_completion` does not aggregate or attach their usage on the error path. Therefore a plan that successfully consumes provider tokens/cost and then fails on a later tool/context/final operation can lose those provider usage totals from the completion outcome. ## Desired behavior - aggregate planner + executed model usage on both success and error paths; - preserve the original execution failure as structured cause/detail; - surface any post-call token/cost/model-call budget violation without hiding the original failure; - keep cancellation/time-limit control semantics intact; - add deterministic regression coverage for provider call(s) followed by a plan execution failure. ## Constraints Do not double-count retries or responses. Reuse the `model_responses` ledger introduced during #20 instead of reconstructing usage from visible vars. ## Discovered by PR #43 / issue #20 deep-recursion accounting audit.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nsaspy/prolog-rlm#44
No description provided.