Skip to content

Worker agents change patches, and a retried change is applied once #855

Closed

Description

@allisonmahmood

Part of #833. Implements change_patch and Change keys in The door, from the MCP surface. The context map puts change keys in Patchy MCP, so their table lives in packages/mcp.

What to build

  • change_patch { patch, tool, args, key } runs a change tool on Worker agents read patches through their agent tools #854's call path. key is required. It is marked destructive and not idempotent. A read tool named here is refused, naming read_patch.
  • Keys are mapped, not passed through. A change key is any string the agent picks. Runtime's mutation keys have their own shape (packages/runtime/src/MutationTransaction.ts), which stays as it is. So the first try of each change key gets a fresh mutation key from Patchy.
  • The record. A new table in packages/mcp, with its migration allocated in landing order and composed into apps/server/src/migrations.ts.
    • It keeps each change key for its connection and patch for 24 hours.
    • It stores the first try's version, tool and arguments, and the mutation key it was given.
    • So every host replica answers a retry the same way, and page keys are unchanged.
  • Mutations.
    • Retrying a committed change returns the original result with replayed: true and writes nothing.
    • An unknown_outcome resolves on retry.
    • A change whose result is too large reports success, with the result left out.
  • Refusals.
    • The same key with a different tool or arguments: "that key was used for a different change; pick a new one".
    • A retry after a publish: "published since your first try; read before retrying", Runtime's rule that a key is bound to its version.
    • A try whose first try is still running is refused busy, with retryAfterSeconds: 1.
  • Actions that write get no replay.
    • A timed-out action's refusal says it may have partly happened: read first, then retry with a new key.
    • Any later try with an action's key is refused without running.
  • Events record replayed, and never the key.
  • Skills. patchy-server's "The agent area" gains, in the tested skill text's words, that a change key makes a mutation's retry write once, and that an action that writes is not safe to retry.

Done means

  • Codex logs three calls in one change_patch on a dev instance.
  • It retries with the same key, on another replica, and gets replayed: true with nothing written twice.
  • key: "import-monday" works.
  • Each refusal above is answered as specified.

Surfaces

packages/mcp (migration, glossary Change key as written), apps/server/src/migrations.ts, the vitest template, the rollback rehearsal, packages/analytics, patchy-server, and docs/API.md for the shared shapes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions