1---
2name: meta-stack-trace-investigator
3visibility: experimental
4invocation: experimental_internal
5disable-model-invocation: true
6description: "Use this meta-skill instead of answering directly when the user gives a stack trace, traceback, runtime error, or failing log that benefits from multi-skill orchestration across trace parsing, repo/history inspection, patch-target analysis, reproduction guidance, and verification commands."
7kind: meta
8meta_priority: 60
9always: false
10final_text_mode: "step:degraded_summary"
11triggers:
12 - "traceback"
13 - "stack trace"
14 - "runtime error"
15 - "failing log"
16 - "keyerror"
17 - "typeerror"
18 - "investigate stack trace"
19 - "trace investigator"
20 - "诊断 traceback"
21 - "调查 stack trace"
22 - "查 traceback"
23provenance:
24 origin: opensquilla-original
25 license: Apache-2.0
26metadata:
27 opensquilla:
28 risk: low
29 capabilities:
30 - shell
31 - filesystem-write
32composition:
33 steps:
34 - id: trace_collect
35 kind: llm_chat
36 with:
37 system: "You extract stack-trace investigation facts without asking follow-up questions."
38 task: |
39 Extract a compact investigation brief from the original request.
40 Do NOT ask the user to confirm language, expected behavior, or
41 recent changes when the stack trace is enough to infer a useful
42 investigation direction. If a field is absent, write ASSUMED or
43 unknown and continue.
44
45 Original request:
46 ---
47 {{ inputs.user_message | xml_escape | truncate(3000) }}
48 ---
49
50 Return exactly this structure:
51 LANGUAGE: <python|javascript|typescript|go|rust|unknown>
52 EXPECTED_BEHAVIOR: <brief or ASSUMED: not provided>
53 RECENT_CHANGES: <brief or ASSUMED: not provided>
54 TRACE_PRESENT: <yes|no>
55 PRIMARY_EXCEPTION: <exception/error head or unknown>
56 PRIMARY_FILES:
57 - <path:line if present, otherwise unknown>
58 - id: parse_trace
59 kind: llm_chat
60 depends_on: [trace_collect]
61 with:
62 system: "You parse stack traces. Return only the requested JSON object."
63 task: |
64 You are the trace parser for a stack-trace investigation bundle.
65 Extract structured info from the stack trace below; do not speculate
66 about root cause yet.
67
68 Extracted investigation brief (treat as hints, not authoritative):
69 {{ outputs.trace_collect | xml_escape | truncate(1000) }}
70
71 Traceback under investigation:
72 ---
73 {{ inputs.user_message | xml_escape | truncate(3000) }}
74 ---
75
76 Reply with EXACTLY one JSON object on a single line, no preamble:
77 {"exception_class": "<ClassNameOrErrorKind>", "exception_message": "<head of message; <=120 chars>", "primary_file": "<path/file or empty>", "primary_line": <int or 0>, "symbols": ["sym1", "sym2", ...], "language": "<python|javascript|typescript|go|rust|unknown>"}
78
79 The "symbols" list contains the function/method names that appear in
80 the top 3 frames; include at most 6 distinct entries.
81 - id: grep_repo
82 kind: tool_call
83 tool: exec_command
84 tool_allowlist: [exec_command]
85 depends_on: [parse_trace]
86 on_failure: grep_repo_degraded
87 tool_args:
88 command: "rg -n --hidden --max-count 5 -- 'parse_tool_result|run_step|json.loads|KeyError|result' ."
89 workdir: "{{ inputs.workspace_dir }}"
90 timeout: 12
91 - id: grep_repo_degraded
92 kind: llm_chat
93 with:
94 system: "You return a fixed degraded-evidence marker."
95 task: |
96 Return exactly:
97 REPO_GREP: DEGRADED - repository search could not run in this
98 workspace. Continue from traceback semantics and provide exact
99 commands for the target repository.
100 - id: search_issues
101 kind: tool_call
102 tool: exec_command
103 tool_allowlist: [exec_command]
104 depends_on: [parse_trace]
105 on_failure: search_issues_degraded
106 tool_args:
107 command: "gh issue list --search 'KeyError result parse_tool_result' --json number,title,url --limit 10"
108 workdir: "{{ inputs.workspace_dir }}"
109 timeout: 12
110 - id: search_issues_degraded
111 kind: llm_chat
112 with:
113 system: "You return a fixed degraded-evidence marker."
114 task: |
115 Return exactly:
116 ISSUE_SEARCH: DEGRADED - issue search could not run or produced no
117 authenticated results. Continue without issue evidence.
118 - id: git_history
119 kind: tool_call
120 tool: exec_command
121 tool_allowlist: [exec_command]
122 depends_on: [parse_trace]
123 on_failure: git_history_degraded
124 tool_args:
125 command: "git log --since='30 days ago' --oneline -- src/agent/tools.py src/agent/runtime.py"
126 workdir: "{{ inputs.workspace_dir }}"
127 timeout: 12
128 - id: git_history_degraded
129 kind: llm_chat
130 with:
131 system: "You return a fixed degraded-evidence marker."
132 task: |
133 Return exactly:
134 GIT_HISTORY: DEGRADED - git history could not run in this
135 workspace. Continue without commit evidence and provide exact git
136 log/blame commands for the target repository.
137 - id: diff_context
138 kind: skill_exec
139 skill: git-diff
140 depends_on: [parse_trace]
141 on_failure: diff_context_degraded
142 with:
143 mode: worktree
144 cwd: "{{ inputs.workspace_dir | default('.') }}"
145 - id: diff_context_degraded
146 kind: llm_chat
147 with:
148 system: "You return a fixed degraded-evidence marker."
149 task: |
150 Return exactly:
151 DIFF_CONTEXT: DEGRADED - current workspace is not a readable git
152 worktree or git-diff failed. Continue using traceback evidence,
153 repo grep output, and explicit user-provided paths.
154 - id: history_patterns
155 kind: skill_exec
156 skill: history-explorer
157 depends_on: [parse_trace]
158 on_failure: history_patterns_degraded
159 with:
160 query: "{{ outputs.parse_trace | truncate(512) }}"
161 window_days: "30"
162 include: "meta_usage,co_occurrences"
163 - id: history_patterns_degraded
164 kind: llm_chat
165 with:
166 system: "You return a fixed degraded-evidence marker."
167 task: |
168 Return exactly:
169 HISTORY_PATTERNS: DEGRADED - history-explorer failed or no local
170 decision history is available. Continue without prior-pattern
171 evidence.
172 - id: memory_recall
173 kind: tool_call
174 tool: memory_search
175 tool_allowlist: [memory_search]
176 depends_on: [parse_trace]
177 on_failure: memory_recall_degraded
178 tool_args:
179 query: "{{ outputs.parse_trace | truncate(400) }}"
180 max_results: 3
181 - id: memory_recall_degraded
182 kind: llm_chat
183 with:
184 system: "You return a fixed degraded-evidence marker."
185 task: |
186 Return exactly:
187 MEMORY_RECALL: DEGRADED - no prior incident memory is available.
188 Continue without prior-memory evidence.
189 - id: language_probe
190 kind: agent
191 skill: stack-trace-generic-probe
192 depends_on: [parse_trace]
193 route:
194 - when: "'\"language\":\"python\"' in outputs.parse_trace or '\"language\": \"python\"' in outputs.parse_trace or 'LANGUAGE: python' in outputs.trace_collect"
195 to: stack-trace-python-probe
196 - when: "'\"language\":\"javascript\"' in outputs.parse_trace or '\"language\": \"javascript\"' in outputs.parse_trace or '\"language\":\"typescript\"' in outputs.parse_trace or '\"language\": \"typescript\"' in outputs.parse_trace or 'LANGUAGE: javascript' in outputs.trace_collect or 'LANGUAGE: typescript' in outputs.trace_collect"
197 to: stack-trace-js-probe
198 - when: "'\"language\":\"go\"' in outputs.parse_trace or '\"language\": \"go\"' in outputs.parse_trace or 'LANGUAGE: go' in outputs.trace_collect"
199 to: stack-trace-go-probe
200 - when: "'\"language\":\"rust\"' in outputs.parse_trace or '\"language\": \"rust\"' in outputs.parse_trace or 'LANGUAGE: rust' in outputs.trace_collect"
201 to: stack-trace-rust-probe
202 with:
203 task: |
204 Run a language-specific stack-trace probe. Use the parsed trace and
205 evidence gathered so far to propose language-idiomatic checks,
206 minimal reproducer shape, and patch targets. Do not claim repository
207 evidence that is absent.
208
209 Language classification:
210 {{ outputs.trace_collect | truncate(400) }}
211
212 Trace parse:
213 {{ outputs.parse_trace | truncate(1200) }}
214
215 Original user request:
216 {{ inputs.user_message | xml_escape | truncate(2000) }}
217 - id: root_cause
218 kind: llm_chat
219 depends_on: [grep_repo, search_issues, git_history, diff_context, history_patterns, memory_recall, language_probe]
220 with:
221 system: "You synthesize bounded root-cause hypotheses from stack traces, exception semantics, and explicit evidence."
222 task: |
223 Synthesize a root-cause hypothesis from these parallel
224 investigations and the original trace parse.
225
226 Trace parse:
227 {{ outputs.parse_trace | truncate(600) }}
228
229 Repo grep:
230 {{ outputs.grep_repo | truncate(1200) }}
231
232 Related GH issues:
233 {{ outputs.search_issues | truncate(800) }}
234
235 Recent commits on affected files:
236 {{ outputs.git_history | truncate(800) }}
237
238 Current git diff context:
239 {{ outputs.diff_context | truncate(1200) }}
240
241 Prior OpenSquilla skill/router history patterns:
242 {{ outputs.history_patterns | truncate(1200) }}
243
244 Prior similar incidents (may be empty on a fresh install — if
245 this section is empty or returns no matches, IGNORE it and
246 synthesize the root cause from the other available investigations
247 alone; do not invent prior incidents that are not listed):
248 {{ outputs.memory_recall | truncate(800) }}
249
250 Treat prior memory as a non-authoritative search hint only. Do not
251 cite memory paths, similarity scores, or prior-incident claims as
252 evidence for the current traceback; the current trace and target
253 repository evidence are the only grounding sources.
254
255 Language-specific probe:
256 {{ outputs.language_probe | truncate(1200) }}
257
258 If repository search returned NO_HITS or the referenced files are
259 absent, still derive a bounded hypothesis from the stack trace
260 contract itself. Clearly say the repository evidence is degraded;
261 do not pretend that files or symbols were inspected.
262
263 Exception-semantics guard:
264 - For Python expressions like json.loads(raw)['result'] with
265 KeyError: 'result', treat the decoded value as a mapping/dict
266 missing that top-level key. Do not rank list/string/null/non-JSON
267 payloads as primary causes; put them under rejected/different
268 exception shapes because they would normally raise TypeError or
269 JSONDecodeError instead.
270 - When repository evidence is degraded, the strongest evidence is
271 the consumer contract violation: parser expects result, producer
272 supplied another valid JSON object shape.
273
274 Reply with this exact structure (no preamble):
275
276 EXCEPTION_SEMANTICS: <what the exception class implies for this exact expression; name payload shapes that would and would not cause it>
277 ROOT_CAUSE: <one-sentence highest-likelihood hypothesis>
278 EVIDENCE:
279 - <which investigation supported it; cite line>
280 - <which investigation supported it; cite line>
281 RANKED_HYPOTHESES:
282 - likelihood=<high|medium|low>; cause=<cause>; evidence=<evidence>; falsify=<command/check>
283 - include at least six bounded hypotheses when repository
284 evidence is degraded; cover error envelopes, schema drift,
285 nested result wrappers, streaming/control frames, wrong
286 dispatcher/message type, and provider/transport rewraps when
287 they fit the exception semantics
288 SUGGESTIONS:
289 - <file:line> — <action>
290 - <file:line> — <action>
291 - <file:line> — <action>
292 - id: repro_suggestion
293 kind: llm_chat
294 depends_on: [root_cause]
295 with:
296 system: "You propose safe, minimal verification commands for debugging."
297 task: |
298 Propose the smallest safe verification command(s) for this root-cause
299 hypothesis. Prefer existing tests, targeted unit tests, or a minimal
300 reproducer command. Do not propose destructive commands. Do not
301 propose commands that create, overwrite, or edit files, including
302 heredocs, shell redirection, `cat >`, `tee`, `python - <<`,
303 `python -c` that writes files, or temporary files under `/tmp`.
304 If a reproducer needs code, include it as an inline snippet marked
305 "copy into an existing test file" and keep Verification commands
306 limited to read-only locate/history checks or existing test commands.
307
308 Language classification:
309 {{ outputs.trace_collect | truncate(400) }}
310
311 Trace parse:
312 {{ outputs.parse_trace | truncate(600) }}
313
314 Root-cause report:
315 {{ outputs.root_cause | truncate(1200) }}
316
317 Language-specific probe:
318 {{ outputs.language_probe | truncate(1200) }}
319
320 Reply with:
321 CONFIDENCE: <low|medium|high>
322 VERIFY:
323 - <command or manual check>
324 - <minimal reproducer command or snippet for the parsed language>
325 - <history/blame or producer-consumer schema check>
326 FIX_FIRST:
327 - <first file/action>
328 PATCH_SHAPE:
329 - <specific defensive-code shape to try first>
330 - <schema-normalization or frame-filtering shape if relevant>
331
332 For parser/envelope failures, prefer a protocol-error branch plus
333 fixture-driven contract tests over silently returning a default or
334 fabricated result. If a fallback/retry is useful, phrase it as a
335 caller policy after logging and typed error classification, not as
336 the parser's default behavior.
337 - id: degraded_summary
338 kind: llm_chat
339 depends_on: [grep_repo, search_issues, git_history, diff_context, history_patterns, memory_recall, language_probe, repro_suggestion]
340 with:
341 system: "You are a strict final-report renderer for stack-trace investigations. Return only the final report. Never mention internal orchestration, tool failures, path restrictions, memory persistence, or saved artifacts."
342 task: |
343 CRITICAL OUTPUT CONTRACT:
344 - First line must be exactly: ## Trace Facts
345 - Use the same language as the original user request. If the
346 original request is in English, answer in English.
347 - Do not include an opening acknowledgement, apology, emoji, or
348 process commentary.
349 - Do not include the words "meta-skill", "search step", "path
350 restriction", "internal tool", "memory persistence", "saved",
351 "git_history", "DAG", "memory/traceback.md", "prior incident",
352 "similarity score", or "step".
353 - If repository evidence is unavailable, write only:
354 "Repository evidence: DEGRADED in this benchmark/workspace; run
355 the commands below in the target repository."
356 - Verification Commands must contain only commands/checks. Code
357 changes belong only in Patch Direction, not Verification Commands.
358 Never include file-creation or file-edit commands in Verification
359 Commands: no heredocs, no shell redirection, no `cat >`, no `tee`,
360 no `python - <<`, no `python -c` file writes, and no `/tmp`
361 scratch-file creation. Reproducer code belongs in the Reproduction
362 section as an inline snippet, not as a command that writes files.
363 - Keep the final report compact enough to finish: cap root-cause
364 matrix rows at 8, reproducer rows at 5, and patch-direction bullets
365 at 6. Prefer dense commands and bullets over long prose.
366 - Patch Direction must complete before Related Checks. Do not spend
367 the token budget on full implementation code unless the user asked
368 for a patch.
369 - For parser/envelope failures, do not recommend returning a default
370 success/error object from the parser as the first fix. Prefer typed
371 protocol/execution errors, payload-key logging, schema
372 normalization only for supported legacy success keys, and
373 fixture-driven contract tests.
374 - Verification Commands must include at least one exact import-path
375 reproducer when a parsed file/module path is available, plus at
376 least one targeted pytest command for the parser/envelope contract.
377 - Do not ask follow-up questions at the end.
378
379 Produce the final user-facing investigation. If any evidence source
380 returned NO_HITS, NO_MATCHING_ISSUES, NO_RECENT_COMMITS, auth errors,
381 or empty memory, label that source as DEGRADED instead of hiding it.
382 This is the final answer shown to the user: do not mention
383 meta-skill step ids, memory persistence, internal tools, or that
384 anything was saved. Do not say "the meta-skill search step hit a path
385 restriction"; phrase unavailable repo evidence only inside Evidence
386 Status.
387 Treat raw errors from repository/history tools as private diagnostic
388 noise. Do not quote them, translate them, or identify which internal
389 lookup failed; collapse them to the generic degraded evidence line
390 above.
391 Treat memory recall as a private hint source. Never include a
392 "Prior incident" evidence row, memory path, memory score, or memory
393 citation in the final report.
394
395 When repository evidence is degraded, do not stop at a short
396 conclusion. Provide a useful fallback investigation based on the
397 trace contract:
398 - say that the referenced files/symbols were not found in the
399 current workspace when that is true;
400 - include exact repo search commands the user can run in the real
401 target repository;
402 - include a minimal reproducer snippet or command for the parsed
403 language/runtime;
404 - include a defensive patch direction with expected failure mode;
405 - include exact verification commands.
406
407 Quality bar for user-facing output:
408 - start with trace facts, not process commentary
409 - parse the failing frame precisely: file, line, function, expression,
410 exception class, and what the exception proves
411 - explicitly state the data-shape implications:
412 json.loads(raw) succeeded; the decoded payload was subscriptable
413 by string key; the top-level key "result" was absent
414 - explicitly reject payload shapes that would produce JSONDecodeError,
415 TypeError, or IndexError instead of the observed exception
416 - for Python, do not say list/string/null payloads would cause
417 KeyError for this expression; they are rejected/different-exception
418 shapes unless extra wrapping evidence exists
419 - rank a broad hypothesis matrix, including schema drift, error
420 envelope, nested result, streaming/control frame, wrong dispatcher,
421 transport/provider rewrap, and renamed key when applicable
422 - include at least seven ranked hypotheses when repository evidence
423 is degraded: error envelope, schema/version drift, streaming or
424 partial frame, wrong dispatcher/message type, renamed/cased key,
425 exception serialized as tool output, and empty/null/stripped result
426 - include a hypothesis-driven reproducer matrix for at least four
427 payload shapes: success envelope, error envelope, streaming/control
428 frame, and non-dict JSON; specify expected exception or output
429 - repo search targets must include producer, consumer, schema/types,
430 transport wrappers, streaming/chunking, fixtures/logs, tests, git
431 history, and blame
432 - verification commands must be exact shell commands and must include
433 rg checks, git log/blame checks, a minimal language-specific
434 reproducer, and targeted test commands
435 - the minimal language-specific reproducer must be an inline snippet
436 plus an existing-test command, not a file-creation command; do not
437 use `cat >`, heredocs, redirection, `tee`, `/tmp` files, or
438 `python - <<` in Verification Commands
439 - prioritize producer-adapter checks and contract tests over broad
440 generic advice; tie each verification command to the failing module
441 path, symbol, or envelope contract when possible
442 - Patch Direction should distinguish:
443 1. parser boundary: decode, type check, error-envelope branch,
444 supported success-key normalization, typed protocol error
445 2. producer adapters: guarantee one success envelope shape
446 3. caller/runtime: catch typed failures and log tool identity
447 4. tests: fixtures for success, error envelope, missing key,
448 streaming/control frame, and non-dict JSON
449 - include these concrete search families when applicable:
450 `rg -nF "parse_tool_result"`, `rg -n "tool_call|tool_result|dispatch|invoke_tool"`,
451 `rg -n "stream|chunk|delta|partial"`, `rg -n "openai|anthropic|mcp|jsonrpc"`,
452 `rg -nP "return\s*\{\s*['\"](result|data|output|content|error|status|message)['\"]" src/`,
453 `rg -nP "json\.loads\([^)]+\)\[['\"][^'\"]+['\"]\]" src/`,
454 `git log -p --since="60 days" -- <files>`, and `git blame -L`
455 - state that commands are recommended next steps, not executed
456 - do not end by asking whether the user wants more detail
457
458 Root cause:
459 {{ outputs.root_cause | truncate(1200) }}
460
461 Trace parse:
462 {{ outputs.parse_trace | truncate(800) }}
463
464 Language classification:
465 {{ outputs.trace_collect | truncate(400) }}
466
467 Verification plan:
468 {{ outputs.repro_suggestion | truncate(1000) }}
469
470 Language-specific probe:
471 {{ outputs.language_probe | truncate(1000) }}
472
473 Evidence availability:
474 - Repository/history/issue evidence may be unavailable in benchmark
475 workspaces. If the prior sections do not contain concrete
476 file-line excerpts from the target repository, use the exact
477 degraded evidence sentence from the contract and continue with a
478 trace-contract investigation.
479 - Do not quote raw lookup errors, internal lookup names, or protected
480 path details.
481
482 Reply in Markdown with exactly these sections and no preamble:
483 ## Trace Facts
484 ## Diagnosis
485 ## Exception Semantics
486 Explain what the exception class means for the exact failing
487 expression. Reject payload shapes that would produce a different
488 exception type.
489 ## Evidence Status
490 ## Assumptions / Constraints
491 ## Ranked Root Cause Matrix
492 Include at least seven rows. Each row must include likelihood,
493 evidence, falsifying command/check, and expected signal.
494 ## Repo Search Targets
495 Group searches by direct hits, producer/wrappers, runtime/streaming,
496 schema/types, tests/fixtures/logs, and git history. Prefer `rg` and
497 include exact commands. Do not assume `src/tools/` exists; use
498 repo-wide commands first, then path-specific commands for parsed
499 frames.
500 ## Reproduction
501 Include a minimal fixture or snippet for the parsed language/runtime
502 plus a small matrix of payload shapes and expected outcomes.
503 ## Patch Direction
504 Keep this section concise and complete. Prefer bullet-level patch
505 targets and contract-test shape over long code blocks. Explicitly
506 reject silent default-return behavior for missing required result
507 keys unless the target repository's protocol already documents that
508 behavior.
509 ## Patch Target Checklist
510 ## Related Checks
511 Include adjacent contract checks: raw payload logging, error-path
512 tests, schema validation, all return sites funneled through one
513 wrapper, retry/fallback behavior, stream assembly, raw type
514 narrowing, sibling unsafe `json.loads(...)[key]` patterns, and
515 missing observability around tool identity / tool_call_id /
516 producer name / payload keys at the parser boundary.
517 ## Verification Commands
518 Separate locate/context commands, producer-shape search, unit tests,
519 isolated reproducer commands, static sweeps, logs, and history
520 checks. Include commands for the happy path, error-envelope path,
521 streaming/control-frame path, non-dict path, and tool-identity
522 logging check. Use only read-only searches/history/log commands and
523 existing test commands. Do not include commands that create or edit
524 files; if a new fixture is needed, describe the fixture in Patch
525 Direction or Reproduction instead.
526 - id: persist
527 kind: tool_call
528 tool: memory_save
529 tool_allowlist: [memory_save]
530 depends_on: [degraded_summary]
531 tool_args:
532 path: "memory/traceback.md"
533 mode: "append"
534 content: |
535 === stack-trace investigation ===
536 parse: {{ outputs.parse_trace | truncate(400) }}
537 hypothesis: {{ outputs.degraded_summary | truncate(1000) }}
538---
539
540# Stack-Trace Investigator (Meta-Skill)
541
542A **combinator-style** meta-skill that converts a pasted stack trace into a
543structured root-cause report. It now classifies Python, JavaScript,
544TypeScript, Go, Rust, or unknown traces before running the investigation. After
545parsing the trace once, heterogeneous investigations run in parallel:
546
5471. **`grep_repo`** — ripgrep for the symbols in the current repo
5482. **`search_issues`** — `gh issue list` for similar reported problems
5493. **`git_history`** — recent commits touching the affected files
5504. **`diff_context`** — `git-diff` skill for current worktree context
5515. **`history_patterns`** — `history-explorer` skill for prior skill/router
552 usage patterns
5536. **`memory_recall`** — prior incidents stored under the `traceback` topic
5547. **`language_probe`** — routed to the language-specific helper skill
555 (`stack-trace-python-probe`, `stack-trace-js-probe`,
556 `stack-trace-go-probe`, `stack-trace-rust-probe`, or generic fallback)
557
558The `root_cause` and `repro_suggestion` steps fan the signals into a
559hypothesis, concrete fix targets, and verification commands. The final summary
560labels degraded evidence sources explicitly before persisting the incident.
561
562## Trigger surface
563
564Fire by saying `investigate stack trace` or one of the localized triggers
565listed in the frontmatter, with the traceback pasted into the same turn.
566
567## Fallback
568
569If any leaf step fails, the orchestrator surfaces partial outputs in
570`step_outputs`. Operator should manually run `rg <symbols>`,
571`gh issue list --search`, `git log`, and `memory search` and
572synthesize the report by hand.