# Session Log Analysis

This session log repeats the same prompt 13 times. Investigate why that is. It seems to be a "review" marked session?

## What you're looking at

Session `019ee087-16f3-...` is indeed a **review session** — agent `Codex`, model `gpt-5.5`, started by `dipree` on 2026-06-19 15:38:27, with the canonical prompt _"Review the current branch changes and report actionable findings…"_. It reports `checkpoint_count = 13`.

But it only legitimately owns **2** checkpoints (`90b5447afbc7`, `faf8a96b581e` at 20:29 and 20:33, branch `dip/trail-types`). The other **11** belong to completely unrelated sessions:

| Owning session          | Agent | Prompt                                | # checkpoints |
| ----------------------- | ----- | ------------------------------------- | -------------- |
| `019ee088-250c…`      | Pi    | "Create a PR for the Gemini config here." | 2             |
| `019ee116-f0f0…`      | Pi    | "Merge latest main and resolve conflicts." | 9             |
| `019ee087-16f3…` (this one) | Codex | review prompt                          | 2             |

The review session leaked into all 13 because **every one of those 13 checkpoints carries this session id inside its `session_ids` JSON array** — and so does a _second, near-duplicate review session_ `019ee087-16ab-…` (also Codex, identical review prompt, started the same second, 72 ms earlier). Both review sessions are pinned into every checkpoint's `session_ids`.

## Root cause (two layers)

**1. A stale review session leaks into every subsequent checkpoint's `session_ids`.** `session_ids` on a checkpoint is copied verbatim from the commit/transcript metadata's `sessions` array. Nothing filters out sessions that didn't actually contribute to that checkpoint — `dead_session_indices` is computed but the raw `session_ids` list is left whole. The two review sessions opened at 15:38:27 stayed "open" in the local transcript's session list and were stamped onto **every checkpoint created over the next ~5 hours**, across unrelated branches (`add-gemini-entire-config`, `dip/trail-types`, `dip/drop-trail-labels`) and unrelated agents (Pi). That's why both review sessions show `checkpoint_count = 13` while one owns 2 and the other owns 0.

**2. The session-log merge amplifies the leak into 13 repeated prompts.** The session page queries checkpoints with `cp.session_ids LIKE %sessionId%`, so all 13 leaked checkpoints are pulled in. `mergeSessionTranscript()` then loops over each checkpoint, finds this session inside `cp.sessions`, and appends its transcript slice. Each of those 13 slices begins at the same point (`transcript_lines_at_start = 58`, `checkpoint_transcript_start = 58`) and contains a copy of the review prompt message. Messages are deduped by `msg.id` — but because each checkpoint's slice gives that prompt a distinct id, the dedupe misses and the **review prompt gets emitted once per checkpoint → 13 identical prompt blocks** in the log.

## Two distinct bugs worth filing

- **Session-id leakage:** a long-lived/"open" session contaminates the `session_ids` of every later checkpoint. The fix belongs at ingest — only include a session in a checkpoint's `session_ids` if it actually contributed in that checkpoint's transcript window.
- **Duplicate review session:** the review was recorded as two near-identical sessions 72 ms apart, suggesting a double-trigger / double-insert when a review is launched.

**Fix:** exclude `KindAgentReview` sessions in the commit path so a read-only review never gets attributed to commits.
