trusty-mpm 1.0.2

trusty-mpm: unified multi-agent orchestration platform (core, daemon, CLI, TUI, Telegram)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# Complete Debugging Workflow

> **Part of**: [Systematic Debugging]../SKILL.md
> **Category**: debugging
> **Reading Level**: Intermediate

## Purpose

Complete step-by-step workflow for all four phases of systematic debugging, including detailed instructions, decision trees, and verification criteria.

## Phase 1: Root Cause Investigation

**Goal**: Understand WHAT and WHY before attempting fixes.

### Step 1: Read Error Messages Carefully

**Don't skip past errors or warnings:**
- Read stack traces completely
- Note line numbers, file paths, error codes
- Error messages often contain the exact solution
- Write down exact error text

### Step 2: Reproduce Consistently

**Can you trigger it reliably?**

```
Can you reproduce the issue?
├─ Yes → Proceed to Step 3
├─ Intermittent → Gather more data
│  ├─ Check for race conditions
│  ├─ Look for environmental factors
│  ├─ Add logging around suspected area
│  └─ Document patterns (time of day, load, etc.)
└─ No → Issue may be environmental
   ├─ Check configuration differences
   ├─ Verify dependencies
   └─ Compare runtime environments
```

**Document:**
- Exact steps to reproduce
- Required preconditions
- Expected vs actual behavior
- Success rate (every time? 50%? 10%?)

### Step 3: Check Recent Changes

**What changed that could cause this?**

```bash
# Git history
git log --oneline --since="1 week ago"
git diff HEAD~5 -- path/to/relevant/file

# Recent commits
git show <commit-hash>

# Blame for specific line
git blame path/to/file.ts | grep -A5 -B5 "problem line"
```

**Look for:**
- Code changes in affected area
- New dependencies added
- Configuration changes
- Environmental differences (dev vs prod)
- Database schema changes
- API version changes

### Step 4: Gather Evidence in Multi-Component Systems

**WHEN system has multiple components (CI → build → signing, API → service → database):**

**BEFORE proposing fixes, add diagnostic instrumentation:**

```
For EACH component boundary:
  - Log what data enters component
  - Log what data exits component
  - Verify environment/config propagation
  - Check state at each layer

Run once to gather evidence showing WHERE it breaks
THEN analyze evidence to identify failing component
THEN investigate that specific component
```

**Example: Multi-layer System**

```bash
# Layer 1: Workflow
echo "=== Secrets available in workflow: ==="
echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
echo "API_KEY: ${API_KEY:+SET}${API_KEY:-UNSET}"

# Layer 2: Build script
echo "=== Environment vars in build script: ==="
env | grep IDENTITY || echo "IDENTITY not in environment"
env | grep API_KEY || echo "API_KEY not in environment"

# Layer 3: Service layer
echo "=== Service initialization: ==="
echo "Config loaded: $CONFIG_PATH"
echo "Database connection: $DB_HOST:$DB_PORT"

# Layer 4: Actual operation
echo "=== Operation execution: ==="
set -x  # Enable command tracing
./actual-operation --verbose
set +x
```

**This reveals**: Which layer fails (secrets → workflow ✓, workflow → build ✗)

### Step 5: Trace Data Flow

**WHEN error is deep in call stack:**

**Backward tracing technique:**
1. Where does bad value originate?
2. What called this function with bad value?
3. Keep tracing up until you find the source
4. Fix at source, not at symptom

**Example:**

```
Error: Cannot read property 'id' of undefined
  at processUser (user.service.ts:45)
  at handleRequest (request.handler.ts:23)
  at middleware (auth.middleware.ts:12)

Investigation:
45: const userId = user.id;  // user is undefined - WHERE did it come from?
23: processUser(req.user);   // req.user is undefined - WHERE set?
12: req.user = await getUser(token);  // getUser returned undefined - WHY?

Root cause: getUser returns undefined when token expired
Fix: Handle undefined in getUser, not at usage site
```

## Phase 2: Pattern Analysis

**Goal**: Find working examples and identify differences.

### Step 1: Find Working Examples

**Locate similar working code in same codebase:**

```bash
# Find similar patterns
grep -r "similar_function" src/
grep -r "similar_pattern" src/

# Find similar test cases
find tests/ -name "*similar*test*"
```

**Questions:**
- What works that's similar to what's broken?
- How is working code different?
- What dependencies does working code use?

### Step 2: Compare Against References

**If implementing pattern, read reference implementation COMPLETELY:**

**DON'T:**
- Skim the documentation
- Copy-paste without understanding
- "Adapt" the pattern without reading fully

**DO:**
- Read every line of reference
- Understand WHY each part exists
- Note all dependencies and setup
- Check for hidden requirements

### Step 3: Identify Differences

**List every difference, however small:**

```
Working Code          | Broken Code
---------------------|--------------------
Uses async/await     | Uses callbacks
Has error handling   | No error handling
Validates input      | Assumes valid input
Imports from '@lib'  | Imports from '../lib'
```

**Don't assume "that can't matter"** - small differences often cause bugs.

### Step 4: Understand Dependencies

**What other components does this need?**
- Required packages and versions
- Configuration settings
- Environment variables
- Database schema
- External services
- Initialization order

## Phase 3: Hypothesis and Testing

**Goal**: Form and test specific hypotheses scientifically.

### Step 1: Form Single Hypothesis

**Write it down explicitly:**

❌ Bad: "Something is wrong with the database"
✅ Good: "Database connection times out because connection pool is exhausted"

❌ Bad: "The calculation is incorrect"
✅ Good: "Division by zero when denominator is empty list"

**Good hypothesis characteristics:**
- **Specific**: Names exact variable/function/line
- **Testable**: Can be verified with single change
- **Falsifiable**: Could be proven wrong
- **Evidence-Based**: Supported by logs/observations

### Step 2: Test Minimally

**Make the SMALLEST possible change to test hypothesis:**

```typescript
// Hypothesis: Function fails when input array is empty

// Minimal test
if (array.length === 0) {
  console.log('HYPOTHESIS TEST: Empty array detected');
}

// DON'T bundle multiple changes
if (array.length === 0) {
  throw new Error('Empty array');  // Multiple changes
}
```

**One variable at a time:**
- Change only what tests hypothesis
- Keep changes minimal
- Comment your reasoning
- Revert if hypothesis wrong

### Step 3: Verify Before Continuing

**Execute reproduction case and observe outcome:**

```bash
# Run specific test
npm test path/to/failing.test.ts

# Or run reproduction script
node reproduce-bug.js
```

**Outcomes:**
- **Hypothesis Confirmed** → Proceed to Phase 4
- **Hypothesis Rejected** → Return to Phase 3 Step 1 with new data
- **Inconclusive** → Refine test or gather more data

### Step 4: When You Don't Know

**Be honest about knowledge gaps:**
- Say "I don't understand X"
- Don't pretend to know
- Ask for help
- Research more before forming hypothesis

**Better to say "I need to investigate further" than propose wrong fix.**

## Phase 4: Implementation

**Goal**: Fix the root cause, not the symptom.

### Step 1: Create Failing Test Case

**Simplest possible reproduction:**

```typescript
// Good: Minimal failing test
test('handles empty array', () => {
  const result = processArray([]);
  expect(result).toEqual([]);
});

// Bad: Too complex
test('complex scenario', () => {
  const db = setupDatabase();
  const user = createUser(db);
  const items = fetchItems(user);
  const result = processArray(items);
  // What exactly are we testing?
});
```

**Requirements:**
- Automated test if framework available
- One-off test script if no framework
- MUST have before fixing
- Should be fast to run

### Step 2: Implement Single Fix

**Address the root cause identified:**

```typescript
// Good: Fixes root cause
function processArray(items: Item[]): Result[] {
  if (items.length === 0) {
    return [];  // Handle edge case
  }
  return items.map(transform);
}

// Bad: Fixes symptom
function processArray(items: Item[]): Result[] {
  try {
    return items.map(transform);
  } catch (e) {
    return [];  // Hides real problem
  }
}
```

**Rules:**
- ONE change at a time
- No "while I'm here" improvements
- No bundled refactoring
- Focus only on the bug

### Step 3: Verify Fix

**Run full verification:**

```bash
# Test passes now?
npm test path/to/test.test.ts

# No other tests broken?
npm test

# Issue actually resolved?
node reproduce-bug.js  # Should work now
```

**Checklist:**
- [ ] Failing test now passes
- [ ] All other tests still pass
- [ ] Original bug no longer occurs
- [ ] No new warnings or errors
- [ ] Performance not degraded

### Step 4: If Fix Doesn't Work

**STOP and reassess:**

**Track attempts:**
- Fix #1 failed → Return to Phase 1, re-analyze
- Fix #2 failed → Return to Phase 1, gather more evidence
- Fix #3 failed → **STOP: Architecture problem**

**DON'T attempt Fix #4 without architectural discussion.**

### Step 5: If 3+ Fixes Failed - Question Architecture

**Pattern indicating architectural problem:**
- Each fix reveals new shared state/coupling in different place
- Fixes require "massive refactoring" to implement
- Each fix creates new symptoms elsewhere
- You're "fighting the framework"

**STOP and question fundamentals:**
- Is this pattern fundamentally sound?
- Are we "sticking with it through sheer inertia"?
- Should we refactor architecture vs continue fixing symptoms?

**Discuss with human partner before attempting more fixes.**

**This is NOT a failed hypothesis - this is wrong architecture.**

## Verification Checklist

Before marking debugging complete:

- [ ] Root cause identified (not just symptoms)
- [ ] Hypothesis formed and tested
- [ ] Fix addresses root cause
- [ ] Test case created
- [ ] Test passes
- [ ] No regressions introduced
- [ ] Solution documented
- [ ] Learned from the issue

## Summary

- Phase 1 (Root Cause): Read, reproduce, gather evidence
- Phase 2 (Pattern): Find working examples, compare
- Phase 3 (Hypothesis): Form theory, test minimally
- Phase 4 (Implementation): Create test, fix, verify
- If 3+ fixes fail: Question architecture

## Related References

- [Examples]examples.md: Real-world debugging scenarios
- [Troubleshooting]troubleshooting.md: Common debugging challenges
- [Anti-patterns]anti-patterns.md: Common mistakes to avoid