본문으로 건너뛰기
cccskills
무료GitHub에 공개

debugging-difficult-bugs

Investigate difficult bugs by adding temporary logs to the actual execution path and reproducing the reported behavior. Analyze JSONL logs, which store one structured event per line, then fix the cause, verify regression tests, and remove debugging artifacts.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

Use early when debugging a medium or hard bug, especially when tests alone may not reveal the real runtime failure. Trigger this before extended TDD iteration when a bug involves runtime state, ordering, persistence, streaming, concurrency, UI/manual reproduction, external services, or when a red or newly passing test may not model the real issue. Skip only when the root cause is already directly proven by a stack trace or deterministic test that exercises the real runtime path.

설치 방법 보기

이럴 때 유용합니다

  • Investigating bugs that occur only during manual use
  • Tracing event order in streaming or concurrent operations
  • Checking whether passing tests cover the reported bug
  • Finding state or persistence errors across components

포함된 파일(1)

  • SKILL.md7.3 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Debugging Difficult Bugs

Use this skill early for medium or hard bugs where normal TDD may give false confidence because the test does not fully capture the real bug.

Core idea: instrument the actual runtime path, reproduce the real issue, then inspect append-only JSONL logs before deciding on a fix.

When to Use

Use this workflow near the start of debugging when any of these are true:

  • The bug is medium or hard complexity, especially if it spans multiple functions, packages, processes, or UI/runtime boundaries.
  • A test is red, but the failing test might be an incomplete model of the real bug.
  • You are tempted to make a second speculative fix without new runtime evidence.
  • The bug depends on runtime ordering, state, caching, streaming, concurrency, persistence, UI interaction, or external services.
  • The user says they can reproduce the issue manually.
  • The test passes after a change, but you are not confident it proves the actual reported bug is fixed.

Do not keep iterating only on tests if you do not understand the runtime behavior.

Skip this workflow only when the root cause is already directly proven by a stack trace or by a deterministic failing test that exercises the real runtime path. If you are tempted to make a second speculative fix, use this workflow.

Required Approach

  1. State the uncertainty

    • Acknowledge that the current test may not capture the actual bug.
    • Identify the real code path that must be observed.
  2. Add temporary unconditional instrumentation

    • Add minimal but sufficient logs through the suspected code flow.
    • Log boundaries, meaningful branch decisions, state transitions, async ordering points, return values, and caught errors; do not log every line.
    • Logs must be unconditional: do not gate them behind an env var, debug flag, or log level.
    • Each log point must append one JSON object per line to a .jsonl file in the current working directory.
    • Include enough context to reconstruct the path: event name, timestamp, relevant ids, input shape, state transitions, branch decisions, return values, and caught errors.
  3. Reproduce the real issue

    • Prefer to run the reproduction yourself if possible.
    • If the issue requires the user's environment or manual interaction, ask the user to reproduce it after instrumentation is added.
    • Tell the user exactly which .jsonl file to send or ask them to tell you when reproduction is complete so you can inspect it.
  4. Analyze the log before fixing

    • Read the JSONL log chronologically.
    • Compare expected flow vs actual flow.
    • Identify the first point where state or behavior diverges.
    • Only then implement the fix.
  5. Clean up instrumentation

    • Remove all temporary unconditional logs after root cause is understood and the fix is verified.
    • Remove debug imports, helper functions, generated .jsonl files, and any other temporary artifacts.
    • Check the final diff for instrumentation remnants.
    • Do not leave debug files, log helpers, or noisy runtime logging in the final diff unless the user explicitly asks.
  6. Keep or improve tests

    • Add or adjust a focused regression test once the real bug is understood.
    • Make the test assert the actual broken behavior discovered from logs, not the earlier incorrect assumption.

JSONL Logging Pattern

Use append-only JSONL in cwd so it works across CLIs, dev servers, tests, and manual reproduction.

Node / TypeScript

import { appendFileSync } from 'node:fs';
import { join } from 'node:path';

function debugBug(event: string, data: Record<string, unknown> = {}) {
  appendFileSync(
    join(process.cwd(), 'debug-difficult-bug.jsonl'),
    `${JSON.stringify({
      ts: new Date().toISOString(),
      event,
      ...data,
    })}\n`,
  );
}

Call it at every meaningful branch or state transition:

debugBug('workflow.start', { runId, stepId, inputKeys: Object.keys(input ?? {}) });

debugBug('workflow.beforeStep', {
  runId,
  stepId,
  status: step.status,
  hasResumeData: Boolean(resumeData),
});

try {
  const result = await executeStep();
  debugBug('workflow.afterStep', { runId, stepId, resultShape: Object.keys(result ?? {}) });
  return result;
} catch (error) {
  debugBug('workflow.stepError', {
    runId,
    stepId,
    errorName: error instanceof Error ? error.name : typeof error,
    errorMessage: error instanceof Error ? error.message : String(error),
  });
  throw error;
}

What to Log

Prefer compact, structured data over huge dumps.

Log:

  • Function or phase name.
  • Stable ids: request id, run id, thread id, resource id, step id, tool call id.
  • Input/output shape: keys, counts, lengths, statuses.
  • Branch decisions and the data that caused them.
  • State before and after mutation.
  • Error names/messages and relevant metadata.
  • Ordering markers for async, streaming, or concurrent flows.

Avoid logging:

  • API keys, auth headers, tokens, cookies, credentials.
  • Full user content unless necessary and safe.
  • Large payloads that make the log unreadable.
  • Binary data or full model responses unless the bug requires it.

Treat debug logs as potentially sensitive. Do not ask the user to paste them into public issues, PRs, or shared channels unless they have reviewed/redacted them first.

If sensitive data might appear, log redacted summaries:

debugBug('request.received', {
  hasAuthHeader: Boolean(headers.authorization),
  bodyKeys: Object.keys(body ?? {}),
  messageCount: body?.messages?.length,
});

Reproduction Handoff to User

When the user needs to reproduce manually, say exactly this shape:

I added temporary unconditional JSONL instrumentation. Please reproduce the issue once, then send me or point me at:

<cwd>/debug-difficult-bug.jsonl

After I inspect that log, I’ll remove the instrumentation and make the actual fix.

If multiple processes have different working directories, either:

  • log the absolute process.cwd(), process role, and pid at startup, or
  • write distinct files like debug-server-flow.jsonl, debug-worker-flow.jsonl, and debug-client-flow.jsonl.

Analysis Checklist

Before writing the fix, answer:

  • Did the instrumented code path actually run?
  • What was the expected sequence of events?
  • What was the actual sequence?
  • What is the first incorrect state, missing value, duplicate event, or wrong branch?
  • Does the original red test capture that exact divergence?
  • If not, how should the regression test change?

Final Verification

A difficult bug is not done until:

  • The real reproduction path passes.
  • The regression test fails before the fix and passes after the fix, when feasible.
  • Temporary unconditional instrumentation is removed.
  • The final diff contains only the fix and intentional tests.
  • You can explain the root cause using evidence from the JSONL log.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Design and audit an agent's system prompt, the instructions that guide its work. Define a concrete outcome, starting input, available tools, completion checks, fallback behavior, and final report so the prompt describes a complete run.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Designing the core instructions for a new agent
  • Auditing a prompt before saving it
  • Defining behavior when tools or permissions are missing
mastra-ai/mastra2.9만2026년 10월 19일 업데이트

Create a dedicated test project linked to the current worktree and check Agent Builder through APIs and browser interactions. It covers agent and skill management, permissions, defaults, and related features, with selectable test sections.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Validate an Agent Builder feature branch before review
  • Check role-based permissions and authentication
  • Test agent and skill management through APIs and the UI
mastra-ai/mastra2.9만2026년 10월 19일 업데이트

Reviews pull requests for bugs, error handling, code quality, and style consistency. Organizes feedback into an overview, must-fix issues with file locations, improvement suggestions, and positive notes so reviewers can distinguish urgent problems from refinements.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Finding bugs that must be fixed before merging
  • Reviewing TypeScript types and asynchronous code
  • Checking naming, imports, and leftover debug statements
mastra-ai/mastra2.9만2026년 10월 19일 업데이트

Design instructions for agents that write, fix, review, or refactor code. Define behavior based on file access, select suitable tools, and set clear verification and completion rules for repository changes or copyable code output.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Designing an agent for repository bug fixes
  • Defining a pull request review agent
  • Creating a code generator without workspace access
mastra-ai/mastra2.9만2026년 10월 19일 업데이트

Configure Factory board behavior and GitHub or Linear event handlers in deployment code. Adjust stage transitions, phase meanings, and tool-result handling, then check the changes with focused tests and versioned audit records.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Add approval requirements to board transitions
  • Change GitHub or Linear event handling
  • Define custom board phases and tool-result rules
mastra-ai/mastra2.9만2026년 10월 19일 업데이트

Design agents that draft blog posts, social posts, newsletters, and marketing copy. Define the audience, brand voice, length, and required output so each agent delivers a complete draft with a headline and supporting notes.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Build a blog writing agent with a consistent brand voice
  • Design an agent for LinkedIn product posts
  • Define delivery rules for newsletter drafts
mastra-ai/mastra2.9만2026년 10월 19일 업데이트

mastra-ai의 스킬 모두 보기

이 스킬의 문제 신고