Ctx architecture failure analysis

From ActiveMemory/ctx · View interactive version

Ctx architecture failure analysis is an AI agent skill from the GitHub repository ActiveMemory/ctx. Adversarial failure analysis for codebases. Generates falsifiable incident hypotheses: race conditions, ordering assumptions, cache staleness, error swallowing, ownership gaps, idempotency failures, and scaling cliffs. Produces DANGER-ZONES.md with evidence-backed, ranked findings.

How to use this skill

Skill file

Adversarial analysis that identifies where a codebase will

silently betray you. Think like a correctness chaos monkey:

someone who knows the code intimately and exploits logical

bugs, not security holes.

Design Principle

Generate falsifiable incident hypotheses. /ctx-architecture

maps what exists. /ctx-architecture-enrich improves map fidelity.

This skill generates concrete, disprovable claims about where the

map will break under real-world conditions. Every finding is a

hypothesis with evidence, not a suspicion or a vibe.

The goal is to find failure modes that code review misses: the

ones that ship, pass tests, and break in production at 3am.

This skill requires /ctx-architecture artifacts as input.

If they don't exist, stop and tell the user to run

/ctx-architecture first.

When to Use

know where the dragons are

When NOT to Use

concern: auth bypass, injection, privilege escalation)

the risk

Inputs

Required (must exist before running):

Optional (enhances analysis):

/ctx-architecture principal mode (used as starting points,

not as the final word)

sourcegraph-cody): blast radius estimation, shared-state detection

equivalents include Firecrawl, Exa, Tavily): cross-reference

against known failure patterns

Process

Phase 0: Validate Prerequisites

  1. Check that architecture artifacts exist. If missing:

> Architecture artifacts not found. Run /ctx-architecture

> first; this skill analyzes existing maps, it doesn't

> create them.

  1. Load map-tracking.json to identify which modules have

sufficient coverage (confidence >= 0.7). Low-confidence

modules get flagged as "unanalyzed, risk unknown" rather

than skipped.

  1. If .context/DANGER-ZONES.md exists, load it as seed

findings to extend, not as the complete picture.

Phase 1: Build the Attack Surface

Read architecture artifacts and identify mutation points:

places where state changes, data transforms, or side effects

occur. These are the attack surface for correctness failures.

For each module with confidence >= 0.7:

  1. Read the DETAILED_DESIGN entry for the module
  2. Identify:

caches, registries)

or swallowed)

order, shutdown sequence)

  1. For each mutation point, read the actual source code,

DETAILED_DESIGN summaries are not enough for failure

analysis. You need to see the actual lock scope, the actual

error check, the actual nil guard.

Phase 2: Adversarial Analysis

Apply each failure category systematically to the mutation

points identified in Phase 1. For each category, ask:

"How would a correctness chaos monkey make this fail silently?"

Every candidate finding must meet the evidence standard

before it can be recorded:

  1. Code path observed: Exact file, function, line range
  2. Triggering precondition: What must be true for the

failure to occur

  1. Failure path: Step-by-step sequence from trigger to

observable effect

  1. Why it is silent: Why tests, logs, or monitoring miss it
  2. Code evidence: The specific code pattern that supports

the claim (the missing lock, the unchecked error, the

unbounded loop)

If you cannot provide all five, the finding is a hypothesis,

not a confirmed hazard. Label it accordingly (see Confidence

below).

Category 1: Concurrency

without synchronization. Check: is every field of every

shared struct protected? Are map reads concurrent-safe?

that can block forever

context cancellation not propagated

Category 2: Ordering Assumptions

specific order. init() functions with side effects that

depend on other packages' init()

but insertion order isn't guaranteed

goroutines still running during cleanup

Category 3: Cache Staleness

or invalidation

the write to be visible, but a cache serves stale data

instances or processes

Category 4: Fan-out Amplification

of batching

exponentially

load

Category 5: Ownership and Lifecycle

(file handles, goroutines, temp files)

dependent resources

Category 6: Error Handling

blocks

leave inconsistent state

masks real bugs

Category 7: Scaling Cliffs

for 10 items but kills at 10,000

(in-memory lists, log files, caches)

can't be parallelized

unrelated requests

Category 8: Idempotency Failures

deduplication, causing double writes or double side effects

non-idempotent operations (increment counters, send emails,

append to lists)

keyed but aren't, making replay indistinguishable from

first execution

Category 9: State Machine and Invariant Drift

states the system never validates (half-initialized structs,

partially-migrated records)

validation (e.g., moving from "pending" to "complete"

without passing through "running")

stores (file + memory, database + cache) that can diverge

after partial updates

Phase 3: Challenge Each Finding

Before a candidate finding is accepted, attempt to disprove it.

For each candidate, explicitly check:

the race condition concern?

cancellation or a shutdown hook?

higher-level wrapper?

If the challenge succeeds (the concern is invalid), drop the

finding. If the challenge partially succeeds (the concern is

mitigated but not eliminated), note the mitigation and adjust

confidence downward.

This phase is mandatory. Skipping it produces smart fiction.

Phase 4: Quantify and Cross-Reference

For each surviving finding:

  1. Blast radius: If this fails, what breaks?

GitNexus's impact; equivalents include sourcegraph-cody),

use it to get caller chains and dependency graphs

  1. Detection gap: Would existing tests catch this?

path)

  1. Likelihood: How likely is this to trigger?

(only under load)?

for related fixes)

  1. Risk score: Assign explicit scores on a 1-3 scale:

3 (untested/silent)

  1. Cross-reference: If a web-search-with-citations MCP is

available (canonical: Gemini Search; equivalents include

Firecrawl, Exa, Tavily), search for the pattern in known

incident databases, blog posts, and similar project

post-mortems. This grounds findings in real-world evidence.

If no such MCP is connected, fall back to built-in web

search.

Phase 5: Write DANGER-ZONES.md

Write .context/DANGER-ZONES.md with findings ranked by

risk score (highest first within each tier).

# Danger Zones

_Generated YYYY-MM-DD by /ctx-architecture-failure-analysis._
_Run after /ctx-architecture for full coverage._

## Critical (risk score >= 7, silent or cascading)

### DZ-1: [Location]: [Failure Mode]

**Category**: Concurrency | Ordering | Cache | Amplification
  | Ownership | Error Handling | Scaling | Idempotency
  | State Machine
**Confidence**: High | Medium | Low
**Risk score**: L:N + B:N + D:N = N
**Location**: `package/file.go:function`
**Failure mode**: What goes wrong and why
**Triggering precondition**: What must be true for this to fire
**Failure path**: Step-by-step from trigger to effect
**Blast radius**: What breaks when this fails
**Detection gap**: Why tests don't catch it
**Evidence**: The specific code pattern (with file:line)
**Suggested fix**: Concrete code change, not vague advice

### DZ-2: ...

## Elevated (risk score < 7 or non-silent)

### DZ-3: ...

## Unanalyzed Modules

Modules with coverage < 0.7 in map-tracking.json:
- `module/path` (confidence: 0.3): risk unknown

Confidence levels:

did not weaken the finding

is hard to verify statically (may need runtime proof)

could not be fully confirmed or disproved from static reading

DZ numbering: Sequential across the file. Stable across

re-runs (findings for the same location keep their number).

Phase 6: Summary Report

Print a summary to the terminal:

## Failure Analysis Report

Modules analyzed: N (of M total)
Findings: N critical, M elevated
  High confidence: N
  Medium confidence: N
  Low confidence: N
Unanalyzed modules: K (coverage < 0.7)
Findings challenged and dropped: N

### Critical Findings
- DZ-1: [one-line summary] (L:N B:N D:N = N)
- DZ-2: [one-line summary] (L:N B:N D:N = N)

### Top Recommendation
[Single most impactful fix across all findings]

Relationship to Other Skills

| Skill | Mode |

|-------|------|

| /ctx-architecture | Map what exists |

| /ctx-architecture-enrich | Improve map fidelity |

| /ctx-architecture-failure-analysis | Generate falsifiable incident hypotheses |

| ctx-threat-model (future) | Security-focused analysis |

| /ctx-architecture P4 | Surface danger zones noticed during mapping |

The key distinction: P4 extracts danger zones that were

noticed during mapping. This skill generates hypotheses

and tests them against the code. P4 findings are

observations; this skill's findings are tested claims.

Quality Checklist

Before writing DANGER-ZONES.md, verify:

trigger, failure path, silence reason, code evidence)

might be false" pass

hypotheses via the confidence field

DETAILED_DESIGN summaries)

(not duplicated or lost)

challenge drop count

GitNexus): blast radius was verified with its impact-analysis

surface

(canonical: Gemini Search): findings were cross-referenced

against known patterns

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.