Repository navigation
feat(engine): per-call amended decisions and deferred model calls - #71
Merged
Merged
Conversation
An approval can now carry AmendedArguments. They replace the whole argument object of the one pending call, and ContinueRun runs the tool with them instead of the model's. The authorizer, the tool call row and the model's history all see the amended arguments, and the row records who amended them. Arguments that are not a JSON object, or an edit on a suspension with more than one pending call, are refused with ErrInvalidDecision. A rejection ignores the edit and does not record it.
A decision can carry Calls, keyed by pending tool call id. Each call is approved, approved with edited arguments, or rejected with a reason the model reads. A pending call with no entry, an entry for a call that is not pending, or a non-object edit is refused with ErrInvalidDecision before anything moves.
postgres stores a decision as jsonb, which re-spaces the arguments. The conformance check now compares the decoded objects.
… decision A retry, or a racing decision, only counts as the same decision when its outcome, decider, edited arguments (compared as JSON) and per-call outcomes match what the run was made ready on. Anything else is refused as already decided, so the stored record always matches what ran. A lost record is rebuilt with its edits and per-call outcomes. A caller's own results can no longer set edited arguments or the mark of a reviewer's denial.
A model client can now return cortex.DeferredModelCall (or wrap cortex.ErrDeferModelCall) when it will not make a call yet, for example when the workspace is out of AI credits. The run pauses before that call with a deferred_model_call checkpoint that carries the reason and kind. Approving it continues the run with the same call, and nothing already run is repeated or counted twice. Rejecting it stops the run as cancelled with the decision's reason. Per-call decisions and amended arguments on it are refused with ErrInvalidDecision.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
juicycleff
marked this pull request as ready for review
November 14, 2026 00:43
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.
What this does
Two engine changes that let a caller pause an agent run and continue it later with nothing repeated.
checkpoint.DecisiongainsAmendedArguments(must be a JSON object, elseErrInvalidDecision) andCalls map[string]CallDecision, so each pending tool call is approved, amended or rejected on its own. A pending call missing fromCallsis refused. A rejected call returns its reason to the model.ErrDeferModelCall(DeferredModelCallError{Reason, Kind}), the loop saves the state from before that call and suspends the run with adeferred_model_callcheckpoint.ContinueRunwith an approved decision retries the same call; no earlier tool or model call runs again. A rejected deferral ends the run cancelled.Commits
After merge
foundry's agent step (xraph/foundry#43) is built on this and needs a release tag to require it.
Also fixed
suspension.RunConfig.Toolsisomitemptybut the prepared snapshot keeps an empty tools slice, so a run started withTools: []string{}and then continued failed withcontinuation changed frozen inputs. The frozen compare now treats an empty tool list as none on both sides (ToolsRestrictedstill says whether it is an explicit allowlist). Test:TestModelCallDeferral_continuesARunWithAnEmptyToolList.Tests
go test ./...passes in the root module and every sub-module; golangci-lint v2.12.2 (Go 1.26) reports 0 issues in all modules. grove is v1.10.3 everywhere.