Skip to content

Persist canonical tool calls before every execution - #1637

Draft
BlueHotDog wants to merge 1 commit into
mainfrom
refactor/canonical-tool-calls
Draft

BlueHotDog wants to merge 1 commit into
mainfrom
refactor/canonical-tool-calls

Conversation

@BlueHotDog

Copy link
Copy Markdown
Collaborator

Summary

Prerequisite for refactor/wait-server, implemented directly on main. No commits from the wait-server branch are included.

Every backend, client, unavailable, and malformed tool call now follows the same persistence model:

AgentResponse(tool declaration) → ToolCall → ToolResult(success or error)
  • Insert responses and all declared calls in one transaction, before execution. Enforce call identity by task, turn, and call ID.
  • Normalize arguments at persistence. Keep original arguments in response metadata. Invalid arguments produce a canonical call with nil input, followed by an execution error.
  • Separate recording a call from starting it. Persist the execution target when execution starts. Register client executors before publishing the dispatch-ready event.
  • Dispatch only unresolved calls that started on the MCP target. Recording a call does not start it, including later calls in serial execution.
  • Read canonical call rows for ACP replay and unresolved-call queries. Delete embedded-call reconstruction, replay deduplication, duplicate argument parsing, and name-based target inference.
  • Backfill missing historical calls while preserving existing records and their relative order. Preserve existing client dispatches. Backfill legacy result-only records before their results.
  • Preserve main's timeout/pause policies. This PR does not include the interactive-wait redesign.

Deployment blocker — draft

The first rollout requires a maintenance cutover. Do not merge into the normal blue/green deployment without coordinating it.

infra/production/deploy.sh runs migrations before it stops the old slot. An old server can therefore write declaration-only history after this backfill. A database lock during the migration does not prevent those later writes.

Stop old writers before the migration. Start the new release before restoring traffic. Rollout and rollback requirements are documented in apps/frontman_server/README.md. This PR does not change deployment policy or run any production migration.

Size

Runtime code in apps/frontman_server/lib: 175 added, 211 deleted — 36 fewer lines.

The complete PR grows because it includes the data migration, regression tests, documentation, and a changeset. The line reduction is in runtime code, not the complete diff.

Verification

MIX_TEST_DB_SUFFIX=_canonical_tool_calls make -C apps/frontman_server format precommit strict-compile
make check-source-comments
  • 897 server tests passed.
  • Development and test compilation passed with warnings as errors.
  • Formatting and strict Credo passed.
  • Source-comment checks and their 30 tests passed.
  • Git commit hooks passed without bypasses.

New coverage includes transaction rollback, per-turn identity, malformed backend/client calls, resolved-call start rejection, restart before dispatch, canonical result requirements, replay, historical ordering, legacy argument formats, and result-only backfill.

The original refactor/wait-server worktree remains unchanged.

This branch has not been deployed

No deployments
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