|
| 1 | +--- |
| 2 | +name: gitnexus-debugging |
| 3 | +description: "Use when the user is debugging a bug, tracing an error, or asking why something fails. Examples: \"Why is X failing?\", \"Where does this error come from?\", \"Trace this bug\"" |
| 4 | +--- |
| 5 | + |
| 6 | +# Debugging with GitNexus |
| 7 | + |
| 8 | +## When to Use |
| 9 | + |
| 10 | +- "Why is this function failing?" |
| 11 | +- "Trace where this error comes from" |
| 12 | +- "Who calls this method?" |
| 13 | +- "This endpoint returns 500" |
| 14 | +- Investigating bugs, errors, or unexpected behavior |
| 15 | + |
| 16 | +## Workflow |
| 17 | + |
| 18 | +``` |
| 19 | +1. query({search_query: "<error or symptom>"}) → Find related execution flows |
| 20 | +2. context({name: "<suspect>"}) → See callers/callees/processes |
| 21 | +3. READ gitnexus://repo/{name}/process/{name} → Trace execution flow |
| 22 | +4. cypher({statement: "MATCH path..."}) → Custom traces if needed |
| 23 | +``` |
| 24 | + |
| 25 | +> If "Index is stale" → run `node .gitnexus/run.cjs analyze` in terminal. |
| 26 | +
|
| 27 | +## Checklist |
| 28 | + |
| 29 | +``` |
| 30 | +- [ ] Understand the symptom (error message, unexpected behavior) |
| 31 | +- [ ] query for error text or related code |
| 32 | +- [ ] Identify the suspect function from returned processes |
| 33 | +- [ ] context to see callers and callees |
| 34 | +- [ ] Trace execution flow via process resource if applicable |
| 35 | +- [ ] cypher for custom call chain traces if needed |
| 36 | +- [ ] Read source files to confirm root cause |
| 37 | +``` |
| 38 | + |
| 39 | +## Debugging Patterns |
| 40 | + |
| 41 | +| Symptom | GitNexus Approach | |
| 42 | +| -------------------- | ---------------------------------------------------------- | |
| 43 | +| Error message | `query` for error text → `context` on throw sites | |
| 44 | +| Wrong return value | `context` on the function → trace callees for data flow | |
| 45 | +| Intermittent failure | `context` → look for external calls, async deps | |
| 46 | +| Performance issue | `context` → find symbols with many callers (hot paths) | |
| 47 | +| Recent regression | `detect_changes` to see what your changes affect | |
| 48 | +| "How does A reach B?" | `trace` between the two symbols — shortest call chain in one call | |
| 49 | + |
| 50 | +## Tools |
| 51 | + |
| 52 | +**query** — find code related to error: |
| 53 | + |
| 54 | +``` |
| 55 | +query({search_query: "payment validation error"}) |
| 56 | +→ Processes: CheckoutFlow, ErrorHandling |
| 57 | +→ Symbols: validatePayment, handlePaymentError, PaymentException |
| 58 | +``` |
| 59 | + |
| 60 | +**context** — full context for a suspect: |
| 61 | + |
| 62 | +``` |
| 63 | +context({name: "validatePayment"}) |
| 64 | +→ Incoming calls: processCheckout, webhookHandler |
| 65 | +→ Outgoing calls: verifyCard, fetchRates (external API!) |
| 66 | +→ Processes: CheckoutFlow (step 3/7) |
| 67 | +``` |
| 68 | + |
| 69 | +**cypher** — custom call chain traces: |
| 70 | + |
| 71 | +```cypher |
| 72 | +MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"}) |
| 73 | +RETURN [n IN nodes(path) | n.name] AS chain |
| 74 | +``` |
| 75 | + |
| 76 | +**trace** — shortest call chain between two symbols ("how does A reach B?"), one call instead of chaining `context` hops: |
| 77 | + |
| 78 | +``` |
| 79 | +trace({ from: "processCheckout", to: "fetchRates" }) |
| 80 | +→ status: ok, hopCount: 3 |
| 81 | +→ hops: processCheckout → validatePayment → verifyCard → fetchRates |
| 82 | +→ edges: CALLS (1.0), CALLS (0.95), CALLS (1.0) |
| 83 | +``` |
| 84 | + |
| 85 | +When no path exists, `trace` reports the furthest reachable node — exactly where the chain breaks (dynamic dispatch, reflection, or an external boundary). |
| 86 | + |
| 87 | +## Example: "Payment endpoint returns 500 intermittently" |
| 88 | + |
| 89 | +``` |
| 90 | +1. query({search_query: "payment error handling"}) |
| 91 | + → Processes: CheckoutFlow, ErrorHandling |
| 92 | + → Symbols: validatePayment, handlePaymentError |
| 93 | +
|
| 94 | +2. context({name: "validatePayment"}) |
| 95 | + → Outgoing calls: verifyCard, fetchRates (external API!) |
| 96 | +
|
| 97 | +3. READ gitnexus://repo/my-app/process/CheckoutFlow |
| 98 | + → Step 3: validatePayment → calls fetchRates (external) |
| 99 | +
|
| 100 | +4. Root cause: fetchRates calls external API without proper timeout |
| 101 | +``` |
0 commit comments