Investigation patterns

From takeokunn/nixos-configuration · View interactive version

Investigation patterns is an AI agent skill from the GitHub repository takeokunn/nixos-configuration. Use when tracing a symptom to its cause: debugging, bisecting, working out how an unfamiliar implementation behaves, deciding whether something is absent or unused, or checking a completion claim against the artifact.

How to use this skill

Skill file

How to reach a cause you can defend. The standard debugging arc (reproduce, isolate, investigate, hypothesize,

fix) is assumed; this file covers where that arc yields a confident wrong answer.

Evidence

Evidence tiers, citations, and scores: CLAUDE.md evidence. In an investigation, a verified finding carries the

command and its output or the citation so anyone can re-run it; an inferred finding states the evidence *and

the inferential step*, so the step can be disputed; an assumed finding states what would confirm it.

Coverage is an observable boundary, not a percentage: name the files and symbols actually read, what was not

examined and why, and the query that established the boundary (the aitools search pattern, the

ast-grep rule, the directory walked) so a reader can re-run it and judge whether it was

exhaustive.

Prefer structural search through the ast-grep MCP server to reading whole files, and follow an

aitools search hit with a structural query rather than treating the hit as the answer.

Name the suspected layer before adding a signal

When behavior differs between settings (local or CI, a double or the live service, one configuration or

another), add a signal that tests a named suspicion instead of changing code on a guess.

  1. Name the suspected layer: configuration, object construction, request payload, transport, stream, runtime,

build artifact, or CI environment.

  1. Add the narrowest signal that confirms or clears it: a targeted debug flag, not global debug logging.
  2. Reproduce with the same configuration and inputs, varying only the variable under test; switching model,

version, or environment midway adds a second variable.

  1. Compare the configured state with what took effect in the failing run: a feature enabled in configuration

can be off for that run. Which implementation actually loaded

is the same check for code.

  1. Fix the cause, rerun the exact failing probe, and widen only as far as the contract requires.
  2. If the same mechanism needs fixes in two locations, propose fixing the mechanism itself.

Signals at adjacent layers bracket a fault: response headers show the transport answered, the first body event

shows the remote side progressed, and a long gap between them points at the stream, not its consumer.

Report the layer tested, the command and environment shape (secrets: CLAUDE.md hard_rules), the signal

observed, the fix location, and the remaining risk.

A moving boundary invalidates the observation, not the hypothesis

Bisection (over commits, over input size, over a file's forms) assumes a deterministic oracle. **Once the

boundary shifts under re-probing, every subsequent narrowing step is fitting noise.**

Before narrowing further, re-run the identical probe twice and require the identical boundary. If it moves, the

oracle is noisy and the next reduction target is meaningless. Check for interference first:

tool under test before trusting any timing-sensitive result.

path.

**The failure signature is a long log of "the next reduction target is…" entries with no reproducibility

re-check.** The accumulated narrowing feels like progress and pressures you to continue, but every entry after

the boundary first moved is unusable. If the symptom disappears without a fix, record "no longer reproduces"

and the conditions checked. That alone does not distinguish environmental interference from an intermittent

code defect; a causal conclusion needs a controlled reproduction.

A probe inside a guard measures the guard

A counter, sampler, or health check inside a conditionally-executed body measures the gate, not the phenomenon.

Symptom: a metric reads flat zero, or stuck far below threshold, while the thing it counts is obviously

occurring. Find where the instrumentation sits relative to the guard: if the increment is inside a

rate-limited, coalesced, debounced, or sampled body, its ceiling is the gate's rate, not the event's. Move

the measurement outside the gate, or count gate-closed events explicitly as a separate signal.

Two independent limiters in the same path compose into a dead zone. A producer with its own rate limit

calling a consumer with its own coalescing gate: each is defensible alone, and their product makes a downstream

threshold unreachable. Neither component is wrong; the composition is.

Unit tests miss this: tests that call the detection function directly with synthetic counts bypass both gates,

so they pass while the live path never reaches the threshold.

A registry that gained a second member kind

A consumer iterating a registry works for most members and yields meaningless or empty results for some. Check

whether every member satisfies the property the consumer reads. **A docstring narrowing the contract ("members

must be defined with X") is documentation, not enforcement, and is routinely violated.** Guard the

variant-specific read, which is a reachable branch rather than a defensive one (CLAUDE.md output_discipline),

and give the discrimination a name.

The signal is duplication: the same inline property-presence check at several call sites to tell variants

apart means a named predicate is missing. A registry with mixed member kinds is also a likely source of "passes

but tests nothing" behavior: see testing-patterns for tests that enumerate a

production registry.

Trace the registration before concluding absence or role

Code is often reached through registration rather than a direct call: wiring (dependency injection, module

imports, plugin manifests), configuration (option values, feature flags, generated settings), or a dispatch

table (routes, command maps, hook lists, registries keyed by name). A text search for direct calls misses all

three.

name the ones checked. A search that found no call site establishes only that no direct call exists.

registration to confirm the production path actually reaches it; a test, an example, or a disabled

configuration branch is also a call site.

Inspect its generator, or the source the generator reads, and treat the generated text as a pointer to that

source.

discovery path and name every touch point the new member needs.

Verify a completion claim against the artifact, not the summary

This applies to your own prior work as much as to a claim arriving as a summary.

a build output), read the artifact. "The temporary directories were removed" beside a listing showing them

present is exactly the gap a skeptical check exists to close.

few genuinely unexercised branches, and those branches are where the untested behavior lives.

test whose doubles substitute the fixed component passes for unrelated reasons and is evidence of nothing.

State which verification tier was actually reached rather than implying the highest; see

execution-workflow for the reporting form.

Before adding a feature to an unfamiliar codebase

Locate the relevant patterns and integration points before editing. Produce a written architecture analysis

when explicitly requested or when the change crosses interfaces, affects security or data, or has uncertain

behavior. For a bounded local change, cite the relevant evidence without a separate analysis artifact. When an

analysis is needed, cover the applicable items:

boundaries) with file:line evidence.

to imitate; a near-neighbour already-solved feature is the strongest guide to conventions.

already has in scope.

set bounds the blast radius and is as valuable as the change list.

CLAUDE.md evidence).

second plugin in a family), enumerate the divergences that must survive before starting: a different auth

scheme, a fixed rather than configurable endpoint, an extra handler the reference lacks, files the reference

has that this project should not. The failure mode of conformance work is over-normalization: erasing a

divergence that existed for a reason. A protected list written up front turns an implicit judgement call into

a checkable constraint.

Prefer reusing an existing abstraction to inventing one. If it is fundamentally incompatible with the new

requirement, say so and justify a rewrite rather than forcing an ill-fitting extension.

Deferred decisions

When work is blocked on an external dependency maturing, report the decision and revisit conditions

(persisting them: CLAUDE.md memory_policy):

release page, a changelog, a capability list.

Make the revisit conditions checkable without re-investigation: name the exact capability (a required protocol

method) or version threshold, so a future review is a lookup rather than a fresh analysis.

Removing dead code

and re-exported symbols make token counting produce false positives.

wrongly mark a symbol dead.

Deleting a file cleanly usually requires updating the manifest listing it.

foreign-function export is boundary noise, not proof.** The compiler does not treat the generated

registration path as a call site, so the true caller lies outside the language's reference graph. Verify the

registration or export path before deleting.

Two reliable candidates: thin compatibility barrels that only re-export concrete modules (point each consumer

at the concrete module, then delete the barrel), and single-use private helpers whose only call sites are local

(inline them, keeping the public entry point as the sole behavioral surface).

Rules

Related

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.