agentleFS
yeaight7yeaight7/agent-powerups/skills/agent-session-forensics/SKILL.md

agent-session-forensics

Skill6 starsChanged 4 months agoApache-2.0View on GitHub

Use when diagnosing agent session history, interrupted tool loops, missing tool results, timing bottlenecks, or subagent trace correlation.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer read-only inspection first.

    line 17
  2. Distinctive:

    Ask before modifying, truncating, or deleting any session or history file.

    line 19
  3. Distinctive:

    Do not edit session JSON without backing up the original first.

    line 55
  4. Distinctive:

    Treat history files as sensitive: prompts, tool arguments, credentials, and file contents may appear.

    line 56
  5. Distinctive:

    Do not infer user intent from stale history when current user instructions conflict.

    line 57
  6. Distinctive:

    Do not repair by deleting broad ranges — find the last valid tool-call/result correlation boundary.

    line 58
  7. Distinctive:

    Every tool-call ID is accounted for (matched or flagged as unmatched).

    line 62
  8. Distinctive:

    No session file is mutated without explicit user approval.

    line 64

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Agent Session Forensics

When To Use

  • Agent session ended mid-tool-call or cannot resume.
  • Tool call appears in assistant turn but no corresponding result turn follows.
  • Need to correlate tool calls, tool results, and timing metadata.
  • Diagnosing slow LLM calls, duplicate user turns, or malformed results.
  • Debugging experimental MCP data-layer sessions.

Requirements / Checks

  • Locate session directory and history files before editing anything.
  • Prefer read-only inspection first.
  • Have jq or equivalent JSON tooling available.
  • Ask before modifying, truncating, or deleting any session or history file.

Workflow

  1. Inventory session files — find metadata, current history, rotated previous history, and related subagent histories.
  2. Count and list last turns:
    jq 'length' history.json                                      # total messages
    jq '.[-10:] | .[] | {role, stop_reason}' history.json        # last 10 turns
    jq '.[] | select(.role=="assistant") | .tool_calls[].id' history.json  # tool call IDs
    jq '.[] | select(.role=="user") | .tool_results[]?.tool_call_id' history.json  # results
  3. Correlate tool call IDs — every tool_call in an assistant turn must have a matching tool_result in the immediately following user turn. Find the first gap.
  4. Check timing for slow calls:
    jq '.[] | select(.timing) | {role, duration_ms: .timing.duration_ms}' history.json
  5. Identify failure pattern — see table below.
  6. Repair (if approved) — write a backup first (cp history.json history.json.bak), then make the smallest possible fix at the last valid correlation boundary.

Common Failure Patterns

SymptomLikely causeRepair
Tool call with no result turnSession interrupted mid-toolTruncate after last matched pair
Two consecutive user turnsDuplicate message insertionRemove the duplicate
tool_result with no prior tool_callCorrupted or manually edited historyRemove orphan result
Empty content on assistant turnModel returned no text + no toolsUsually safe to truncate
Session loops without progressMissing result causes re-promptInject minimal synthetic result

Safety Constraints

  • Do not edit session JSON without backing up the original first.
  • Treat history files as sensitive: prompts, tool arguments, credentials, and file contents may appear.
  • Do not infer user intent from stale history when current user instructions conflict.
  • Do not repair by deleting broad ranges — find the last valid tool-call/result correlation boundary.

Validation / Done Criteria

  • Report the names of every session file inspected.
  • Every tool-call ID is accounted for (matched or flagged as unmatched).
  • Any proposed repair names the backup path and truncation boundary.
  • No session file is mutated without explicit user approval.

References

  • references/history-diagnostics.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.