Skip to content

[bug] Session parsing counts injected context and summaries as user messages #1989

Open

Description

@HengYangDS

Problem

The session parser treats anything with a user role as something the human typed. In practice the native transcripts carry injected context, compaction summaries and internal markers in the same role, so "user messages", question counts and the derived scoring include text the person never wrote.

Read-only measurement on one machine (teamai-cli 0.30.0; scripts not included):

  • Claude Code (~/.claude/projects/*/*.jsonl): besides entries with isMeta and isCompactSummary, there are records starting with <system-reminder>, <task-notification>, an interruption marker or a slash-command marker that carry no isMeta flag — 340 + 15 of them in a 93 MB transcript.
  • Codex (~/.codex/sessions/**/*.jsonl): in the 5 most recent files there is no event_msg of type user_message at all; typed input appears as event_msg → item_completed with item.type == "UserMessage" (24 items). The same files contain 203 records with a user role, most of them injected context.
  • Hermes (~/.hermes/state.db, messages table): ordinary user messages have display_kind empty (200 rows); non-empty values are operational (model_switch, 3 rows); summaries carry role='user' with _compressed_summary=1 (14 rows).

Consequence: counting and scoring in Team Improvement are inflated by system and injected text, and any downstream consumer (e.g. a tool that wants the person's own words) cannot tell which records are actually typed input.

Proposed Solution

Parse by the source of the message rather than by role alone, and expose the result:

  • Claude Code: type=user text that is not a tool result, not isMeta, not isCompactSummary, and does not begin with <system-reminder>, <task-notification>, an interruption marker or a command marker.
  • Codex: event_msg → item_completed with item.type == "UserMessage" (keep a version check; older recordings use user_message).
  • Hermes: role='user', display_kind empty, _compressed_summary=0.

If a transcript does not match the expected shape, report it and fail loudly rather than silently skipping the file; a count of unparsed lines in each report would make drift visible.

Alternatives Considered

  • Filtering by known injection prefixes only: brittle, misses new kinds.
  • Leaving it as is and documenting the caveat: metrics keep including system text.

Additional Context

Version 0.30.0, macOS. Transcript shapes are internal formats and change between releases; a per-version criteria table with a safe default would keep this maintainable.

Activity

  1. mosifu commented on Nov 20, 2026

    @mosifu
    Contributor

    I'd like to take this. One scoping question before I write code, because the two answers change the shape of the patch.

    Where the inflation can come from. The hook path already drops injected prompts: dashboard-collector.ts:1153 runs every prompt_submit through stripInjectedPrompt (types.ts:2513, prefixes <task-notification>, <system-reminder>, the interrupt marker), and a purely injected prompt returns null, so it never reaches the event or the prompt count. Your measurement therefore has to come from a consumer that reads the native store directly rather than from events — the session census/score path — and I have not pinned that consumer down yet.

    So:/n/n1. Do you want the predicate in the adapters (packages/tool-*/src/sessions.ts, next to the existing isMeta handling) and the metric switched to it, or a marker on the converted message (metadata.synthetic) with each consumer filtering? The marker keeps the archive and session migrate faithful and moves the decision to the consumer; the predicate changes what a read returns.
    2. One PR for the three parsers, or three PRs (Claude Code first, then Codex, then Hermes)? They share no code, and the Codex one also needs the item_completed/UserMessage version check you mention.

    If you would rather I just pick, I will start with Claude Code alone, as a marker plus the one consumer that counts, and follow up with the other two.

  2. added
    bug
    on Nov 20, 2026
  3. Luckyou-d commented on Nov 20, 2026

    @Luckyou-d
    Contributor

    Taking the isCompactSummary half of this: Claude writes the compaction summary into the transcript in the user role, and isHumanPromptEntry only filtered isMeta/isSidechain, so each compaction counted as a member turn and inflated the prompt count. Sent a PR that reads the flag and skips those entries (false/absent unchanged), with a test that fails on main.

    Deliberately not in that PR, so they get their own decisions/fixtures: the Codex (event_msg -> item_completed, item.type == "UserMessage") and Hermes (display_kind / _compressed_summary) parsers, and the slash-command markers - session-scoring.test.ts currently pins <command-name>/review-notes</command-name> as the member's first prompt, so excluding it would change intended behaviour and is worth a maintainer call.

    Please assign @Luckyou-d if available.

  4. HengYangDS commented on Nov 20, 2026

    @HengYangDS
    ContributorAuthor

    Thanks for taking this. Separate PRs, Claude Code first, sounds right, and so does the marker: let each adapter mark what it knows is not typed by the person, and let the counting skip marked messages. Since someone else picked up the compaction-summary half, could you two agree on who does which so the marker is set in one place?

  5. XY-code1 commented on Nov 23, 2026

    @XY-code1
    Collaborator

    @mosifu Are you already working on the Codex part of this issue? I'd like to take just that adapter if it's free. I'll leave Claude Code (#2003) and Hermes out of scope, and start with sanitized fixtures for both older and newer Codex transcript formats. The goal is to distinguish human input from injected context for counting without dropping the original transcript content.

  6. HengYangDS commented on Nov 25, 2026

    @HengYangDS
    ContributorAuthor

    Thanks for splitting this across the three adapters. #2003 covers Claude compaction summaries. #2034 uses turn IDs where available to keep a matching injected Codex row from consuming the human-input marker. #2039 adds a fallback for older Hermes databases that lack the classification columns.

    Before closing this, could we compare the prompt count and derived scoring on the same transcript for each adapter, with one typed prompt and one injected or operational row? For Codex, #2034 still lists dashboard counters and real CLI verification as open. For Hermes, please verify that the source transcript remains readable and that the exclusion applies to what counts as typed input. A slash command the person actually typed should still count, while the material it loads should stay out of that count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions