Skillpedia
الاختبار29k · #9360

debugging-difficult-bugs

ما الذي تفعله

ترشد هذه المهارة إلى طريقة تصحيح دقيقة للأخطاء المتوسطة أو الصعبة. تطلب من الوكيل إعادة إنتاج المشكلة الحقيقية وقراءة سجلات التشغيل قبل محاولة الإصلاح.

متى تستخدمها

  • ✓عندما يتعلق الخلل بالتوقيت أو الحالة أو البث أو سلوك التشغيل الذي قد لا تلتقطه الاختبارات.
  • ✓عندما يفشل اختبار وقد لا يمثل المشكلة الحقيقية.
  • ✓عندما تكون مغريًا بإصلاح آخر قائم على التخمين دون دليل جديد.

رابط المهارة

https://github.com/mastra-ai/mastra/blob/main/.claude/skills/debugging-difficult-bugs/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/mastra-ai/mastra/blob/main/.claude/skills/debugging-difficult-bugs/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“هذا الخلل يحدث فقط عندما يصل طلبان في الوقت نفسه. ساعدني في إيجاد السبب الحقيقي قبل أن نغيّر أي شيفرة.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

debugging-difficult-bugs: دليل كامل

بعض الأخطاء لا تظهر في الاختبار. تظهر فقط عندما تتداخل الطلبات، أو عندما تُقرأ البيانات بترتيب مختلف، أو عندما يُقطع التدفق في منتصفه. الوكيل الذي يكتب اختبارات لهذه الأخطاء فقط قد ينتهي باختبار يفشل لسبب خاطئ، أو بإصلاح يجعل الاختبار ناجحا بينما تبقى المشكلة الحقيقية قائمة.

تغيّر هذه المهارة ترتيب العمل. قبل أن يعدّل الوكيل أي شيء في الكود، يضيف تسجيلا مؤقتا إلى المسار الفعلي للكود، ويعيد إنتاج المشكلة، ثم يقرأ السجل من البداية إلى النهاية ليحدد أول نقطة تبدأ عندها الأمور بالخطأ. وهي موجهة للمطورين وغير المبرمجين الذين يوجهون وكيلا ويحصلون باستمرار على إصلاحات لا تصمد. ولا حاجة إليها عندما يُظهر تتبع الأخطاء السبب بالفعل.

حالات الاستخدام

خطأ لا يظهر إلا أحيانا

يحفظ تطبيقك الطلب مرتين، لكن فقط عندما يصل طلبان متقاربان في الوقت. اختبار الوحدة ينجح في كل مرة. يسجل الوكيل كل خطوة في عملية الحفظ مع الطوابع الزمنية والمعرّفات، ثم تُشغّل المشكلة بنفسك، ويُظهر السجل أي طلب كتب أولا.

إصلاح لم يحل المشكلة

أجرى الوكيل تعديلين بالفعل، ولا يزال المستخدم يبلغ عن الخطأ نفسه. بدلا من تخمين ثالث، تطلب منه إضافة التسجيل إلى المسار الفعلي وإعادة الإنتاج. يوضح السجل ما إذا كان الكود المعدّل يُنفَّذ أصلا.

مشكلة لا تستطيع إعادة إنتاجها إلا أنت

تتعطل ميزة المحادثة عندما تنقر زرا معينا في المتصفح. يضيف الوكيل التسجيل، ثم يطلب منك تكرار النقرة. تخبره حين تنتهي، فيقرأ ملف السجل في مجلد المشروع.

خطوة بخطوة

  1. 1ضع المهارة في ~/.claude/skills/debugging-difficult-bugs/، أو في مجلد .claude/skills/ الخاص بمشروعك، ثم ابدأ جلسة جديدة.
  2. 2صف الخطأ واذكر كيف يظهر، مثلا فقط تحت الضغط أو فقط في المتصفح. اطلب من الوكيل أن يجد السبب قبل أن يغيّر الكود.
  3. 3يضيف الوكيل تسجيلا مؤقتا يكتب إلى ملف .jsonl في مجلد العمل. دعه يشغّل خطوات إعادة الإنتاج، أو كرر الخطوات بنفسك عندما يطلب ذلك.
  4. 4أخبر الوكيل حين تنتهي. يقرأ السجل بحسب ترتيب الزمن ويسمي أول نقطة يختلف فيها المسار الفعلي عن المسار المتوقع.
  5. 5بعد وضوح السبب، يصلح الوكيل الخطأ، ويضيف اختبارا للتراجع مبنيا على ما أظهره السجل، ثم يحذف كل التسجيل وملف .jsonl.

مثال

ماذا تطلب

“أحيانا يستأنف سير العمل ببيانات قديمة بعد إعادة التشغيل. الاختبارات تنجح. استخدم مهارة التصحيح: أضف تسجيلا، وأخبرني كيف أعيد الإنتاج، ولا تصلح أي شيء قبل أن تقرأ السجل.”

ما الذي ستحصل عليه

يضيف الوكيل التسجيل حول بداية الخطوة، والاستئناف، والحفظ. يطلب منك إعادة تشغيل الخادم واستئناف عملية. يوضح السجل أن الخطوة قرأت حالتها قبل أن ينتهي الحفظ. ثم يقترح إصلاحا، ويضيف اختبارا لهذا الترتيب، ويحذف السجلات.

نصائح

  • ✓اجعل إعادة الإنتاج قريبة من الحالة الحقيقية قدر الإمكان. قد يبدو السجل من تشغيل مبسط سليما ويغفل الخطأ مع ذلك.
  • ✓التسجيل مؤقت. تحقق من الفرق النهائي ومن المجلد بحثا عن أي كود تسجيل متبقٍ وملفات .jsonl قبل أن ترفع التعديلات.
  • ✓لا تسجل محتوى خاصا. اطلب من الوكيل تسجيل المعرّفات والأحجام والحالات بدلا من الرسائل الكاملة، لأن ملف السجل قد يُشارك.

بدائل

  • test-driven-development

    اختره عندما يكون الخطأ بسيطا ويمكن للاختبار أن يُظهره بدقة. هذه المهارة للحالات التي قد لا يطابق فيها الاختبار الفشل الحقيقي.

  • browser-testing-with-devtools

    اختره عندما تكون المشكلة في طريقة عمل الصفحة داخل متصفح حقيقي وتريد فحصها هناك، بدلا من قراءة ملف سجل.

  • webapp-testing

    اختره عندما تحتاج إلى تشغيل تطبيق ويب محلي، وفحص سلوكه، والتقاط لقطات شاشة أو سجلات المتصفح أثناء الاختبار.

أسئلة وأجوبة

أين يوجد ملف السجل، وهل يمكنني قراءته بنفسي؟

هو ملف .jsonl في المجلد الذي يعمل فيه الوكيل، وفيه حدث JSON واحد في كل سطر. يمكنك فتحه في أي محرر نصوص. يحتوي كل سطر على وقت واسم للحدث.

هل يستحق استخدامها لخطأ صغير؟

عادة لا. المهارة مخصصة للأخطاء المتوسطة أو الصعبة. إذا كان تتبع الأخطاء أو اختبار فاشل يشير إلى السبب أصلا، فأصلحه مباشرة.

هل سيبقى التسجيل في كودي؟

لا. تطلب المهارة من الوكيل إزالة مساعدات التسجيل والاستيرادات والملفات المولدة بعد التحقق من الإصلاح، والتأكد من عدم بقاء أي أثر في الفرق النهائي. ويمكنك مراجعته أيضا.

كيف تعمل

يذكر وكيلك ما هو غير متأكد منه، ويضيف تسجيلًا مؤقتًا إلى مسار الشيفرة الحقيقي، ويعيد إنتاج المشكلة. ثم يقرأ السجلات ويكوّن استنتاجًا قبل اقتراح الإصلاح.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

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 err
الأسئلة الشائعة

هل يتخطى كتابة الاختبارات؟

لا. تقول إن الاختبارات وحدها قد تعطي ثقة زائفة، لذلك تأتي أدلة التشغيل أولًا، ثم تُضاف الاختبارات بعد ذلك.

متى يمكن تخطيها؟

فقط عندما يثبت تتبع المكدس أو اختبار فاشل حتمي السبب.

هل ينبغي أن تحتوي السجلات على بيانات خاصة؟

توصي الطريقة بتسجيل البيانات الوصفية فقط، لا المطالبات أو المحتوى.

التفاصيل

الوصف الأصلي من المؤلف

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.

repo: mastra-ai/mastra

الشعبية

نجوم GitHub
29k
الترتيب
#9360
الترخيص
—
آخر تحديث
2‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة