本文へ移動
cccskills
無料GitHub で公開

failure-oriented-instrumentation

Selectively instruments code to capture runtime data for debugging failures and bugs. Use when investigating crashes, exceptions, unexpected behavior, test failures, or performance issues. Analyzes stack traces and error messages to identify suspicious code regions, then adds targeted logging, tracing, and assertions to capture variable values, execution paths, timing, and conditional branches. Supports Python, JavaScript/TypeScript, Java, and C/C++.

インストール方法を見る

含まれるファイル(5)

  • SKILL.md8.3 KB
  • references/c-cpp.md4.7 KB
  • references/java.md4.6 KB
  • references/javascript.md4.0 KB
  • references/python.md3.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Failure-Oriented Instrumentation

Strategically instrument code to capture high-signal runtime data for debugging failures, focusing only on suspicious regions rather than comprehensive instrumentation.

Workflow

1. Analyze the Failure

Gather and analyze failure information:

  • Error message and exception type
  • Stack trace showing call chain
  • Failure location (file, line, function)
  • Reproduction steps or test case
  • Expected vs actual behavior

Identify suspicious code regions:

  • Functions in the stack trace
  • Code paths leading to the failure
  • Variables involved in the error
  • Conditional branches that may affect the outcome

2. Determine Instrumentation Strategy

Based on the failure type, choose instrumentation targets:

For crashes/exceptions:

  • Function entry/exit in stack trace
  • Variable values before the crash
  • Conditional branches leading to error path
  • Exception handling blocks

For incorrect results:

  • Variable values at key computation points
  • Conditional branch decisions
  • Loop iterations and state changes
  • Function return values

For performance issues:

  • Timing information for slow operations
  • Loop iteration counts
  • Resource allocation/deallocation
  • Function call frequency

For intermittent failures:

  • State variables that may cause non-determinism
  • Thread/concurrency information
  • External dependencies (I/O, network, time)
  • Retry logic and error recovery paths

3. Select Instrumentation Patterns

Choose appropriate patterns based on language and context. See language-specific references:

Common patterns:

  • Function entry/exit logging
  • Variable value tracking
  • Conditional branch tracking
  • Loop iteration monitoring
  • Timing measurements
  • Assertions for invariants

4. Insert Instrumentation

Apply instrumentation to identified code regions:

Minimal approach (start here):

  • Instrument only the immediate failure location
  • Add 2-3 key variable logs
  • Track the critical conditional branch

Expanded approach (if minimal is insufficient):

  • Instrument entire call chain from stack trace
  • Add comprehensive variable tracking
  • Monitor all branches and loops in suspicious functions

Principles:

  • Start minimal, expand as needed
  • Focus on high-signal data (variables that affect control flow)
  • Avoid instrumenting stable, well-tested code
  • Minimize performance overhead

5. Run and Collect Data

Execute the instrumented code:

  • Run the failing test case or reproduction steps
  • Capture all instrumentation output (logs, traces)
  • Ensure instrumentation doesn't change behavior (except performance)

6. Analyze Results

Review captured data to identify root cause:

  • Compare variable values against expectations
  • Identify which branch was taken and why
  • Look for unexpected state transitions
  • Check timing for performance issues
  • Correlate multiple data points

Quick Start Examples

Example 1: NullPointerException in Java

Failure:

NullPointerException at UserService.java:45
  at UserService.processUser(UserService.java:45)
  at UserController.handleRequest(UserController.java:23)

Instrumentation:

public void processUser(String userId) {
    logger.debug("ENTER processUser: userId={}", userId);

    User user = userRepository.findById(userId);
    logger.debug("Retrieved user: {}", user);  // Check if null

    if (user == null) {
        logger.warn("User not found for userId={}", userId);
        return;
    }

    String email = user.getEmail();  // Line 45 - was failing here
    logger.debug("User email: {}", email);

    sendNotification(email);
}

Example 2: Incorrect Calculation in Python

Failure:

AssertionError: Expected 100, got 95
  at test_calculate_total (test_billing.py:12)
  at calculate_total (billing.py:34)

Instrumentation:

def calculate_total(items, discount_rate):
    logger.debug(f"ENTER calculate_total: items={items}, discount_rate={discount_rate}")

    subtotal = sum(item.price for item in items)
    logger.debug(f"Subtotal: {subtotal}")

    if discount_rate > 0:
        logger.debug(f"Applying discount: rate={discount_rate}")
        discount = subtotal * discount_rate
        logger.debug(f"Discount amount: {discount}")
    else:
        logger.debug("No discount applied")
        discount = 0

    total = subtotal - discount
    logger.debug(f"Final total: {total}")

    return total

Example 3: Intermittent Test Failure in JavaScript

Failure:

Test "should process async data" fails randomly
Expected: data processed
Actual: timeout

Instrumentation:

async function processAsyncData(dataId) {
    console.log(`ENTER processAsyncData: dataId=${dataId}, time=${Date.now()}`);

    const data = await fetchData(dataId);
    console.log(`Fetched data: ${JSON.stringify(data)}, time=${Date.now()}`);

    if (!data) {
        console.warn(`No data returned for dataId=${dataId}`);
        return null;
    }

    const processed = await processData(data);
    console.log(`Processed data: ${JSON.stringify(processed)}, time=${Date.now()}`);

    return processed;
}

Instrumentation Guidelines

What to Instrument

High priority:

  • Functions in the stack trace
  • Variables mentioned in error messages
  • Conditional branches near the failure
  • Loop conditions and iteration variables
  • Function parameters and return values

Medium priority:

  • State variables that affect control flow
  • Resource allocations (memory, files, connections)
  • External dependencies (API calls, database queries)
  • Error handling and recovery logic

Low priority:

  • Stable utility functions
  • Simple getters/setters
  • Well-tested library code
  • Performance-critical hot paths (unless investigating performance)

What NOT to Instrument

  • Code unrelated to the failure
  • Third-party libraries (unless suspected)
  • Trivial operations (assignments, simple math)
  • Code that would generate excessive output
  • Security-sensitive operations (passwords, tokens)

Instrumentation Best Practices

  1. Use appropriate log levels: DEBUG for detailed tracing, INFO for key events, ERROR for exceptions
  2. Include context: Variable names, values, types, and relevant state
  3. Mark entry/exit: Clear boundaries for function execution
  4. Timestamp when relevant: For timing and ordering issues
  5. Avoid side effects: Instrumentation should not change program behavior
  6. Clean up after: Remove temporary instrumentation once bug is fixed
  7. Consider permanence: Some instrumentation may be valuable long-term for observability

Language-Specific References

Load these references for detailed instrumentation patterns:

Tips

  • Start small: Instrument one function, run, analyze, then expand if needed
  • Be specific: Log exact variable values, not just "processing data"
  • Use structured logging: Include variable names and context, not just values
  • Test instrumentation: Verify logs appear and contain expected information
  • Iterate quickly: Add instrumentation, run, analyze, repeat
  • Consider performance: For production code, use conditional compilation or feature flags
  • Document findings: Comment why instrumentation was added and what it revealed

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

日本語の概要は準備中です。原文の説明を表示しています。

ArabelaTso/Skills-4-SE2532026年8月21日 更新

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

日本語の概要は準備中です。原文の説明を表示しています。

ArabelaTso/Skills-4-SE2532026年8月21日 更新

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

日本語の概要は準備中です。原文の説明を表示しています。

ArabelaTso/Skills-4-SE2532026年8月21日 更新

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

日本語の概要は準備中です。原文の説明を表示しています。

ArabelaTso/Skills-4-SE2532026年8月21日 更新

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

日本語の概要は準備中です。原文の説明を表示しています。

ArabelaTso/Skills-4-SE2532026年8月21日 更新

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

日本語の概要は準備中です。原文の説明を表示しています。

ArabelaTso/Skills-4-SE2532026年8月21日 更新

ArabelaTso のスキルをすべて見る

このスキルの問題を報告する