Skip to main content
Glama
Cohexa-ai

Agent Coherence — Stale Write Guard (FS)

Official
by Cohexa-ai

swg_write_cas

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).

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. 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.

Input Schema

NameRequiredDescriptionDefault
pathYes
new_contentYes
expected_versionYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.12.0

TDQS

A4.8/5.0
Behavior5/5

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

Annotations only declare readOnlyHint=false, so the description carries the behavioral burden, and it does so richly: typed conflict semantics (reason=version_mismatch, current_version returned) instead of auto-merge, handoff outcome behavior, single-host scoping, and an explicit out-of-guarantee list (cross-host writers, divergent history, semantic correctness). These are exactly the failure modes an agent needs before invoking a CAS write.

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?

Content is front-loaded: protocol first, then failure semantics, then scope limits. Given the genuine complexity, nearly every clause earns its place, but the dense capitalization and stacked parentheticals make it harder to parse than necessary.

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?

With no output schema and minimal annotations, the description still covers the protocol, conflict outcomes, concurrency guarantees, and explicit non-guarantees. An agent has everything required to call it correctly and interpret a rejection.

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% with all three parameters undocumented, so the description must compensate. It explains expected_version as the version comparand returned by swg_read and new_content as the merged value, plus the conflict path that returns current_version; only 'path' is left implicit, hence not a full 5.

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?

The opening sentence gives a precise verb and mechanism: 'Concurrent same-key write via compare-and-set.' It then explicitly names the sibling tools it is and is not (swg_read provides the comparand; swg_reacquire does not), letting an agent distinguish it from swg_write and swg_reacquire without opening a schema.

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?

The description prescribes the exact workflow ('You read..., MERGE, then call swg_write_cas(path, expected_version, new_content)') and names the alternatives with their differing semantics. It also states the recovery path on failure (stale-write -> re-read, re-merge, retry) rather than leaving the agent to infer it.

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