state-modification-audit

Audits all read and write paths of a state variable to trace unexpected modifications.

Updated Mar 4, 2026
One-click install
npx skills add https://github.com/chisuhua/home --skill state-modification-audit-chisuhua
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: state-modification-audit
Source: https://github.com/chisuhua/home/tree/main/.config/opencode/skills/state-modification-audit
Command: npx skills add https://github.com/chisuhua/home --skill state-modification-audit-chisuhua

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When a getter like get_pc() returns an unexpected value, developers often only inspect the call site and miss hidden writers. This Skill performs a full cross-reference audit of every read and write path for a target state variable, exposing concurrent, aliased, or side-effect-driven modifications. ## Core Features & Use Cases - Write-point discovery: Uses grep patterns to find direct field assignments, setter calls, and indirect writes through references or aliases across C++ source files. - Read/write cross-referencing: Pairs each write point with your read point, analyzing trigger timing, call-stack relationships, and ordering to explain value drift. - Structured audit report: Produces a Markdown report with a write-point table, conflict analysis, and a modification timeline diagram. - Use Case: A simulator's get_pc() returns a stale value during pipeline execution. The audit reveals that a barrier handler's set_thread_pc() runs before the pipeline read point, explaining the drift. ## Quick Start Ask the AI to audit why get_pc returns an unexpected value by finding all code paths that modify warp_state.threads[lane].pc.

Frequently Asked Questions about state-modification-audit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find all code that modifies a variable in C++?▼

Search for direct field assignments, setter method calls, and indirect writes through references using grep patterns like "set_X", "X =", and "auto&". This Skill automates that search and classifies each write point by trigger timing and call-stack relationship.

Why does my getter return a stale or unexpected value?▼

A getter returns unexpected values when another write path executes before your read point, such as a barrier handler, sync function, or aliased reference mutation. Cross-referencing all writers against your read point's timing reveals which modification caused the drift.

How to debug race conditions and concurrent variable modification?▼

List every write point for the shared variable, then map each one's trigger timing relative to your read point in a timeline. Writes occurring before the read from a different handler or thread explain the race; the audit report format captures this ordering explicitly.

Can a getter or sync function secretly modify state?▼

Yes. Getters with null-check fallbacks can mask real state, and sync functions that read then write back can produce side effects that look like no-ops. The audit flags these hidden-alias and sync-overwrite traps as common pitfalls.

What are the limitations of grep-based code auditing?▼

Grep-based auditing relies on textual patterns, so it can miss writes through macros, function pointers, or heavily templated indirection. It works best as a first-pass cross-reference before deeper dynamic analysis with debuggers or sanitizers.