Skip to main content
Glama
Agent Coherence — Stale Write Guard (FS)

Agent Coherence — Stale Write Guard (FS)

Official
by Cohexa-ai

swg_write_cas

Writes a file only if its version matches the expected comparand, rejecting stale concurrent writes with a typed version-mismatch conflict so you re-read, re-merge, and retry instead of overwriting.

Instructions

Concurrent same-key write via compare-and-set. You read (swg_read returns the version comparand; swg_reacquire does NOT — it is for swg_write recovery), MERGE, then call swg_write_cas(path, expected_version, new_content). Stale-write-rejected: if a peer committed since your read, the CAS is a TYPED CONFLICT (reason=version_mismatch, current_version returned) — NOT an auto-merge; re-read at current_version, re-merge, and retry. A win on a path with a live handoff carries handoff: outcome=completed when this session is its successor, overtaken (with counterparty) otherwise. The per-session conflict counter bounds only a COOPERATING agent (one session, stops on retryable=false); it is NOT livelock-proof against a fresh session or one that ignores retryable=false. A call that reaches the coordinator drops every hold this session has: it starts a new attempt, which gives back the write grant swg_write took on every path, as swg_reacquire does. SINGLE-HOST only. Out of guarantee and NOT detected in v1: writers on different hosts or across a synced/network mount, divergent-history reconciliation, semantic correctness, server-enforced auto-merge.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "path": "<path>",
      "expected_version": "<expected_version>",
      "new_content": "<new_content>"
    },
    "name": "swg_write_cas"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYes
new_contentYes
expected_versionYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.12.0

TDQS

A4.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations supply only readOnlyHint=false, so the description carries the behavioral load and does so richly: typed conflict with reason=version_mismatch and current_version returned, no auto-merge, handoff outcome reporting, and the note that a call reaching the coordinator releases this session's write grants. The SINGLE-HOST limitation and the explicit out-of-guarantee list (cross-host writers, synced mounts, divergent history, semantic correctness) are unusually candid. It stops short of describing response shape beyond the conflict fields, but that is a minor omission given no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the core operation and call signature before descending into edge cases, and the emphasis markers (TYPED CONFLICT, NOT an auto-merge, SINGLE-HOST) are well placed. It is dense and the conflict-counter/livelock caveat is a long clause that could be tightened without losing meaning.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a concurrency-primitive tool with three undocumented parameters and no output schema, the description covers the failure modes an agent must handle: conflict detection, the returned current_version, handoff/overtaken outcomes, grant release side effects, and the single-host boundary. An agent could implement correct retry logic from this text alone.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate. It does for the hardest parameter: expected_version is defined as the version comparand obtained from swg_read, and new_content is implicitly the merged result via the 'MERGE' instruction. path gets no elaboration beyond appearing in the signature, but the semantically ambiguous parameter is covered.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a precise verb and mechanism: 'Concurrent same-key write via compare-and-set,' and immediately names the calling sequence swg_write_cas(path, expected_version, new_content). It distinguishes itself from sibling write paths by stating swg_read supplies the comparand while swg_reacquire does not, so an agent can route between them without opening schemas.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives an explicit when-to-use procedure (read, MERGE, then CAS) and explicitly rules out the tempting wrong alternative (swg_reacquire for the comparand, which is stated to be for write recovery). It also specifies the retry protocol on conflict (re-read at current_version, re-merge, retry), which is when/when-not guidance at the operational level.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.