Skip to content

feat(engine): per-call amended decisions and deferred model calls - #71

Merged
juicycleff merged 9 commits into
mainfrom
feat/approval-amend-and-deferred-calls
Nov 14, 2026
Merged

juicycleff merged 9 commits into
mainfrom
feat/approval-amend-and-deferred-calls

Conversation

@juicycleff

@juicycleff juicycleff commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Two engine changes that let a caller pause an agent run and continue it later with nothing repeated.

  • Decisions can amend arguments, per call. checkpoint.Decision gains AmendedArguments (must be a JSON object, else ErrInvalidDecision) and Calls map[string]CallDecision, so each pending tool call is approved, amended or rejected on its own. A pending call missing from Calls is refused. A rejected call returns its reason to the model.
  • A model call can be deferred. When the model client returns an error matching ErrDeferModelCall (DeferredModelCallError{Reason, Kind}), the loop saves the state from before that call and suspends the run with a deferred_model_call checkpoint. ContinueRun with an approved decision retries the same call; no earlier tool or model call runs again. A rejected deferral ends the run cancelled.

Commits

  • 511e6db feat(checkpoint): decide each pending call on its own
  • be0f0ad test(store): compare amended call arguments as JSON, not bytes
  • d889ccb fix(checkpoint): treat a decision with different edits as a different decision
  • 6680df7 feat(engine): suspend before a model call the client defers
  • f83df9f fix(engine): treat an empty tool list as none when continuing a run
  • 5c377cd fix(lint): name deferral errors and stop shadowing err
  • afb78dd build(deps): move to grove v1.10.3
  • d6e4f7b build(deps): tidy mcpbridge and grpcbind for grove v1.10.3

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.Tools is omitempty but the prepared snapshot keeps an empty tools slice, so a run started with Tools: []string{} and then continued failed with continuation changed frozen inputs. The frozen compare now treats an empty tool list as none on both sides (ToolsRestricted still 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.

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

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

@juicycleff
juicycleff marked this pull request as ready for review November 14, 2026 00:43
@juicycleff
juicycleff merged commit 2cac2ad into main Nov 14, 2026
24 checks passed
@juicycleff
juicycleff deleted the feat/approval-amend-and-deferred-calls branch November 14, 2026 02:14
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.

1 participant