Forensics

From open-gsd/gsd-pi · View interactive version

Forensics is an AI agent skill from the GitHub repository open-gsd/gsd-pi. Post-mortem a failed GSD auto-mode run. Traces symptom to root cause via `.gsd/` activity, journal, metrics, and lock artifacts, producing a filing-ready bug report with file:line refs and a fix suggestion. Use when asked to "forensics", "post-mortem", "why did auto-mode fail", "trace the stuck loop

How to use this skill

Skill file

<objective>

Turn scattered GSD runtime artifacts into one coherent cause chain. The deliverable is a GitHub-issue-ready report that names the file and line where the bug lives, cites the evidence, and proposes a fix. Forensics is archaeology, not re-run — no modifying state, no triggering commands, just reading the paper trail.

</objective>

<context>

GSD persists a lot of runtime evidence under .gsd/:

The /gsd forensics command pre-computes a forensic report with anomalies flagged. This skill is the manual investigation that goes deeper, or runs when the automated report isn't enough.

Invocation points:

</context>

<core_principle>

READ-ONLY. Forensics touches no live state. Non-mutating inspection commands (e.g., ps, top -b, cat /proc/*) are allowed for checking process status or reading system files. Strictly prohibited: gsd_* writes, commands that modify state, executing binaries that produce side effects, writing to files (outside the final report), or re-running the failed unit. The evidence must stay pristine for future investigations.

RECOVERY IS A BOUNDARY, NOT A BYPRODUCT. If the failure involves a GSD auto-pause blocker or a failed Task attempt, the recovery routes are authority-controlled: /gsd blocker resolve is cleared only by the human in the native terminal, and a recovery resume (gsd_task_recovery_resume or the operator's /gsd recover <recoveryActionId>) is a gated continuation with its own repair-evidence requirements. Forensics recommends those routes in its Recovery section; it never performs them, and it never recommends direct database, runtime KV/counter, or rendered-file manipulation to unblock a run. Read the gsd-blocker-recovery skill before writing the Recovery section.

SYMPTOM → ROOT CAUSE, WITH CITATIONS. Every claim in the report is backed by an artifact path and either a line number or a JSONL field. "The loop got stuck because of a race" is not useful; ".gsd/journal/2026-04-19.jsonl:142 shows stuck-detected with flowId X, caused by dispatch-guard.ts:87 returning the same unit after unit-end" is.

PRE-PARSED LEADS, NOT CONCLUSIONS. If /gsd forensics has surfaced anomalies, treat them as hypotheses to verify, not answers.

</core_principle>

<process>

Step 1: Locate the evidence

Read what's in .gsd/:

  1. auto.lock — is it stale? Check PID against ps (read-only inspection, allowed). Stale = crash.
  2. Most recent .gsd/activity/*.jsonl — sort by mtime, newest first. That's the last unit that ran.
  3. Today's .gsd/journal/YYYY-MM-DD.jsonl — the iteration-level view.
  4. .gsd/metrics.json — does any type/id appear more than once? (stuck loop signal)
  5. .gsd/runtime/paused-session.json — if present, what was the pause reason?

Step 2: Reconstruct the failure from the activity log

Activity JSONL format:

To trace a failure:

  1. Search for isError: true tool results in the last activity log. That's usually the proximate symptom.
  2. Walk backwards to the assistant message that made the call. Read the text content — that's the agent's reasoning at the moment of failure.
  3. Keep walking back. Find where the agent's model of the state diverged from reality.

Step 3: Cross-reference the journal

For each symptom from the activity log, find the matching journal events:

Use flowId to reconstruct one iteration; use causedBy to follow causal chains across iterations.

Step 4: Name the root cause

A good root cause is:

Bad root cause: "Auto-mode got stuck in a loop." Good root cause: "After slice completion, auto-unit-closeout.ts emits unit-end before auto-post-unit.ts updates the roadmap checkbox. The next iteration-start finds the same unit [ ] and re-dispatches — dispatch-guard.ts:42 has no check against the freshly-ended unitId."

Consult the source map in src/resources/extensions/gsd/prompts/forensics.md to map symptoms to the likely domain files.

Step 5: Propose a fix

For the root cause:

Step 6: Write the report

Format the output as a GitHub-issue-ready report:

## Symptom

<what the user saw — quote the error or describe the observed behavior>

## Evidence Trail

1. `.gsd/auto.lock` — <state: stale / fresh>
2. `.gsd/activity/042-slice-S02.jsonl:128` — <isError: true from `gsd_task_complete`>
3. `.gsd/journal/2026-04-19.jsonl:87` — <stuck-detected flowId 7a3c…>
4. `.gsd/metrics.json` — <unit type/id "slice/S02" appears 3 times>

## Root Cause

<specific named cause — file, function, state transition>

`src/resources/extensions/gsd/auto-unit-closeout.ts:<line>`: <exactly what goes wrong>

## Proposed Fix

<minimal change — file, function, what to change>

## Test

<what test would have caught this; whether one should be added>

## Confidence

<high / medium / low> — <what would change this confidence>

Offer to file this as a GitHub issue via the active GitHub issue-write tool if one is available, using its exact active tool name — explicit confirmation required per the outward-action rule. Also save a copy to .gsd/forensics/<slug>.md for future reference.

</process>

<anti_patterns>

</anti_patterns>

<success_criteria>

</success_criteria>

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.