Skip to main content
Glama

what_if_revert

Simulates removing specific nodes from the head graph to compute behavioral diff and risk scores. Determines if reverting a commit or function restores prior workflow without executing the revert.

Instructions

Counterfactual reasoning: simulates removing the named nodes from the head graph, then recomputes the behavioral diff and risk scores against the actual base. Answers 'what behaviors recover if I revert this commit / function / class?'. Useful for triaging post-incident commits — quickly see whether a revert restores prior workflow shape without actually running the revert.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdsYesNode identifiers to remove from the head graph for the counterfactual simulation. Format: 'filepath::SymbolName' or 'filepath::Class::method'. Get them from export_behavioral_graph.

Implementation Reference

  • Core implementation: computes actual diff+risk between base and head, then counterfactually removes specified nodes from head, re-runs diff+risk, and returns delta metrics plus a narrative.
    public whatIfRevert(
        baseGraph: BehavioralGraph,
        headGraph: BehavioralGraph,
        removeNodeIds: string[]
    ): CounterfactualResult {
        const remove = new Set(removeNodeIds);
    
        // Actual profile
        const actualDiff = this.diff.computeDiff(baseGraph, headGraph);
        const actualRisks = this.risk.assessRisk(actualDiff, headGraph);
        const actualAvg = actualRisks.length === 0 ? 0
            : actualRisks.reduce((s, r) => s + r.score.overallRisk, 0) / actualRisks.length;
    
        // Counterfactual: head minus the specified nodes
        const cfGraph = new BehavioralGraph();
        for (const n of headGraph.getNodes()) if (!remove.has(n.id)) cfGraph.addNode(n);
        for (const e of headGraph.getEdges()) {
            if (!remove.has(e.sourceId) && !remove.has(e.targetId)) cfGraph.addEdge(e);
        }
        const cfDiff = this.diff.computeDiff(baseGraph, cfGraph);
        const cfRisks = this.risk.assessRisk(cfDiff, cfGraph);
        const cfAvg = cfRisks.length === 0 ? 0
            : cfRisks.reduce((s, r) => s + r.score.overallRisk, 0) / cfRisks.length;
    
        // Risks present in actual but absent or reduced in counterfactual
        const cfRiskMap = new Map(cfRisks.map(r => [r.nodeId, r]));
        const avoided = actualRisks.filter(r => {
            const cf = cfRiskMap.get(r.nodeId);
            return !cf || cf.score.overallRisk < r.score.overallRisk - 5;
        });
    
        const delta = actualAvg - cfAvg;
        const impactedDelta = actualDiff.impactedNodes.length - cfDiff.impactedNodes.length;
        const narrative = buildCounterfactualNarrative(removeNodeIds.length, actualAvg, cfAvg, delta, impactedDelta, avoided.length);
    
        return {
            removedNodeIds: [...remove],
            actualHeadRisk: parseFloat(actualAvg.toFixed(2)),
            counterfactualRisk: parseFloat(cfAvg.toFixed(2)),
            delta: parseFloat(delta.toFixed(2)),
            actualImpacted: actualDiff.impactedNodes.length,
            counterfactualImpacted: cfDiff.impactedNodes.length,
            impactedDelta,
            risksAvoided: avoided.slice(0, 10),
            narrative
        };
    }
  • CounterfactualResult interface defining the output schema: removedNodeIds, actual/counterfactual risk, delta, impacted counts, risksAvoided, and narrative.
    export interface CounterfactualResult {
        removedNodeIds: string[];
        actualHeadRisk: number;
        counterfactualRisk: number;
        delta: number;                       // positive = risk drops if reverted
        actualImpacted: number;
        counterfactualImpacted: number;
        impactedDelta: number;
        risksAvoided: RiskReport[];
        narrative: string;
    }
Behavior4/5

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

Despite no annotations, the description discloses that the tool simulates removal and recomputes results (no destructive action), explains the source of node IDs, and clarifies the outcome. It lacks explicit mention of read-only or rate limits, but the simulated nature is clear.

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

Conciseness5/5

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

The description is two sentences long, front-loaded with the core concept, and every phrase adds value. No redundancy or wasted words.

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

Completeness4/5

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

Given no output schema, the description covers the tool's purpose, mechanism, inputs, and practical use case. It implies the output (behavioral diff and risk scores) but does not detail format; still, it is sufficient for an agent to invoke correctly.

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

Parameters5/5

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

The input schema has 100% coverage, but the description adds critical format details ('filepath::SymbolName') and directs the user to export_behavioral_graph for node IDs. This adds substantial value beyond the schema.

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 description clearly states the tool performs counterfactual reasoning by simulating node removal from the head graph and recomputing behavioral diff and risk scores. It directly answers the 'what if reverted' question, making its purpose specific and distinct from siblings.

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

Usage Guidelines4/5

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

The description explicitly recommends the tool for triaging post-incident commits to evaluate revert impact without an actual revert. While it does not detail when not to use or list alternatives, the contextual guidance is strong enough to help an agent decide.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vighriday/Veris'

If you have feedback or need assistance with the MCP directory API, please join our Discord server