一键导入
debugging-complex-multi-layer-systems
A reasoning pattern for diagnosing and fixing bugs that span multiple abstraction layers in complex systems.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
A reasoning pattern for diagnosing and fixing bugs that span multiple abstraction layers in complex systems.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Rewrite any text as a solemn, slightly absurd 19th-century Civil War field dispatch (Ken Burns documentary voice), then optionally turn it into a multimodal video — period narration via ElevenLabs, the letter in fancy script on aged parchment, a mournful music bed, and a slow Ken Burns pan/zoom of the letter being read. Use when the user types /civilwar, asks to "civil-war-ify" or "Ken Burns" some text, or asks for a documentary-style letter video.
This skill codifies the standards and workflows for this machine's openclaw agent gateway configuration. Use this skill when provisioning new agents or managing existing ones. Trigger phrases are "add a new agent", "update [agent's name] identity"
Unified 33GOD master skill and router. Use for any 33GOD request: architecture context, project creation, task execution, coding workflow, service development, workflow generation, and platform-level orchestration. This skill routes to focused references/workflows/scripts for incremental discovery.
Advanced context management with auto-compaction and dynamic context optimization for DeepSeek's 64k context window. Features intelligent compaction (merging, summarizing, extracting), query-aware relevance scoring, and hierarchical memory system with context archive. Logs optimization events to chat.
Use this when creating new projects, generating documentation, cleaning/organizing a repo, suggesting architecture, deploying containers and services, naming files/folders, or when the user references 'ecosystem', 'patterns', or 'containers'. This skill outlines naming conventions, stack preferences, project organization (iMi worktrees), Docker patterns, and PRD structures from past conversations.
Orchestrate multi-step project workflows using mise task definitions with dependency management and argument handling. Use whenever the user wants to create, edit, or debug mise tasks, wire up task dependencies with depends/depends_post, or run workflows via 'mise run'. Also use when setting up task runners or automating build pipelines through mise. Do NOT use for mise environment variable configuration (use mise-configuration instead) or for general shell scripting unrelated to mise.
| name | debugging-complex-multi-layer-systems |
| description | A reasoning pattern for diagnosing and fixing bugs that span multiple abstraction layers in complex systems. |
Use this reasoning pattern when fixing one bug reveals another bug in the same operation, or when debugging complex multi-layer systems.
Invoke this pattern when:
Identify all abstraction layers involved in the failing operation:
Example: iMi PR Worktree Creation
Layer 1: CLI Command Handler (main.rs::handle_review_command)
↓ calls
Layer 2: Worktree Manager (worktree.rs::create_pr_worktree_with_gh)
↓ calls
Layer 3: Git Manager (git.rs::checkout_pr)
↓ calls
Layer 4: External Tools (gh CLI, git commands)
↓ affects
Layer 5: Filesystem State (directories, .git metadata)
Key Question: Which layer owns each symptom?
Map each observable symptom to its originating layer:
| Symptom | Layer | Type |
|---|---|---|
| Worktree created in wrong directory | 2 | Architectural |
| Trunk switched to PR branch | 3 | Implementation |
| "Branch already used" error | 3 | Implementation |
Pattern: Architectural issues (wrong entity, wrong location) originate in higher layers. Implementation issues (side effects, race conditions) originate in lower layers.
Rule: Fix top-down (highest layer first)
Rationale:
Example Sequence:
Anti-pattern: Fixing Layer 3 first
After each layer fix, test only that layer's contract:
// Layer 2 test: Repository resolution
#[test]
fn test_resolve_repo_from_github_format() {
let manager = create_test_manager();
let resolved = manager.resolve_repo_name(Some("YIC-Triumph/trinote2.0")).await?;
assert_eq!(resolved, "trinote2.0");
let db_repo = manager.db.get_repository(&resolved).await?.unwrap();
assert!(db_repo.remote_url.contains("YIC-Triumph/trinote2.0"));
}
// Layer 3 test: PR fetch without checkout
#[test]
fn test_fetch_pr_without_trunk_corruption() {
let repo = setup_test_repo();
let trunk_branch = get_current_branch(&repo);
git_manager.checkout_pr(&repo_path, 458, &worktree_path)?;
let trunk_branch_after = get_current_branch(&repo);
assert_eq!(trunk_branch, trunk_branch_after); // Trunk unchanged
assert!(worktree_path.exists()); // Worktree created
}
Only after all layer fixes, run end-to-end test:
#[tokio::test]
async fn test_pr_worktree_cross_repo_integration() {
// Setup: User in repo A
env::set_current_dir("/home/delorenj/code/iMi/trunk-main")?;
// Action: Create PR worktree in repo B
let result = manager.create_review_worktree(458, Some("YIC-Triumph/trinote2.0")).await?;
// Verify Layer 2: Correct repo
assert!(result.starts_with("/home/delorenj/code/trinote2.0/pr-458"));
// Verify Layer 3: No trunk corruption
let repo_b_trunk = Repository::open("/home/delorenj/code/trinote2.0/trunk-main")?;
assert_eq!(get_current_branch(&repo_b_trunk), "main");
let repo_a_trunk = Repository::open("/home/delorenj/code/iMi/trunk-main")?;
assert_eq!(get_current_branch(&repo_a_trunk), "main");
}
[Symptom: Operation fails with error X]
↓
[Run operation, capture full error trace]
↓
[Identify deepest layer in stack trace]
↓
[Is error in expected layer for this symptom?]
├─ Yes → Single-layer bug, fix directly
└─ No → Layered bug, start mapping
↓
[Map all layers involved]
↓
[Identify symptoms at each layer]
↓
[Start fixing from highest layer]
↓
[Test layer contract]
├─ Pass → Move to next layer
└─ Fail → Iterate on current layer
↓
[All layers fixed?]
├─ No → Continue fixing next layer
└─ Yes → Integration test
Symptoms: Wrong entity retrieved, missing relationships, stale cache Fix Strategy: Query validation, cache invalidation, data integrity checks
Symptoms: Wrong calculation, incorrect state transition, missing validation Fix Strategy: Unit tests for edge cases, state machine verification
Symptoms: Wrong parameters passed, incorrect serialization, broken contracts Fix Strategy: Contract tests, schema validation, integration tests
Symptoms: Unexpected side effects, race conditions, resource conflicts Fix Strategy: Isolation (don't rely on side effects), idempotency, retries
Layer 1: CLI (main.rs) ✓ Correct - passes repo argument
Layer 2: Manager (worktree.rs) ✗ Bug - uses current_dir() instead of resolving repo
Layer 3: Git (git.rs) ✗ Hidden bug - gh pr checkout has side effect
Layer 4: External (gh CLI) ✓ Correct - works as designed
Fixed Layer 2 first: Resolve repo from database before operations
imi pr 458 YIC-Triumph/trinote2.0 from iMi directoryThis revealed Layer 3 bug: Side effect in checkout_pr
gh pr checkout was switching trunk to PR branchFixed Layer 3: Replace checkout with fetch
gh pr checkout (side effect)gh pr view + git fetch (no side effect)Mistake: Start with lowest layer because "it's simpler" Problem: Higher layer bug may make lower layer fix irrelevant
Mistake: Change multiple layers simultaneously Problem: Can't isolate which fix resolved which symptom
Mistake: Fix each new error as it appears without mapping layers Problem: Never address root architectural issues
Mistake: Only run end-to-end tests, no layer isolation Problem: Can't determine which layer failed when integration breaks
When encountering layered bugs, document:
## Bug Report: [Operation] fails with [Symptom]
### Layer Mapping
- Layer N: [Component] - Status: [✓/✗] - Issue: [description]
- Layer N-1: [Component] - Status: [✓/✗] - Issue: [description]
...
### Fix Order
1. Fixed [Layer X]: [What changed]
- Test result: [Pass/Fail/Revealed Layer Y bug]
2. Fixed [Layer Y]: [What changed]
- Test result: [Pass/Fail]
### Root Causes
- [Layer X]: [Architectural/Implementation] - [Reason]
- [Layer Y]: [Architectural/Implementation] - [Reason]
### Tests Added
- [Layer X contract test]: `test_name_x()`
- [Layer Y contract test]: `test_name_y()`
- [Integration test]: `test_name_integration()`
git-state-recovery: For Layer 5 (filesystem state) issuesecosystem-patterns: For architectural layer decisionsdebugging: For investigation techniques at each layer