Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(transcripts): a Claude Code session started by automation is not flagged as missing its user side

time-attack3606ef2d45b0
diff --git a/src/core/transcripts/claude-code-jsonl.ts b/src/core/transcripts/claude-code-jsonl.ts
index 6cfe24dc18..32f1c4391b 100644
--- a/src/core/transcripts/claude-code-jsonl.ts
+++ b/src/core/transcripts/claude-code-jsonl.ts
@@ -612,6 +612,12 @@ export interface ParsedClaudeSession {
* the real drift signal: turn records exist but no longer yield text.
*/
turnShapedLines: number;
+ /**
+ * User records deliberately excluded (root isMeta/isSidechain/isCompactSummary
+ * or a non-human origin): a session with these and no user turn was started
+ * by automation, not a parser that lost the human side.
+ */
+ excludedUserLines: number;
}
/**
@@ -635,6 +641,7 @@ export function parseClaudeSessionFile(
let cwd: string | undefined;
let skippedLines = 0;
let turnShapedLines = 0;
+ let excludedUserLines = 0;
for (const line of raw.split('\n')) {
const t = line.trim();
if (!t) continue;
@@ -655,6 +662,7 @@ export function parseClaudeSessionFile(
) {
turnShapedLines++;
}
+ if (e.type === 'user' && (isSkippedTurnEntry(e) || hasNonHumanOrigin(e))) excludedUserLines++;
if (!turn) continue;
const timestamp = typeof e.timestamp === 'string' ? e.timestamp : '';
turns.push({ role: turn.turn.role, text: turn.turn.text, timestamp });
@@ -667,6 +675,7 @@ export function parseClaudeSessionFile(
bytesRead: size,
skippedLines,
turnShapedLines,
+ excludedUserLines,
};
}
diff --git a/src/core/transcripts/claude-code.ts b/src/core/transcripts/claude-code.ts
index 60ac0df0e3..54b1d4f896 100644
--- a/src/core/transcripts/claude-code.ts
+++ b/src/core/transcripts/claude-code.ts
@@ -228,7 +228,7 @@ export const claudeCodeAdapter: TranscriptAdapter = {
? 'no turn records in file (title/metadata-only, non-human text only, or all-subagent)'
: 'no user or assistant turns in file'
: undefined,
- userTurnsMissing: r.turns.length > 0 && !r.turns.some((t) => t.role === 'user') ? true : undefined,
+ userTurnsMissing: r.turns.length > 0 && r.excludedUserLines === 0 && !r.turns.some((t) => t.role === 'user') ? true : undefined,
};
},
};
diff --git a/test/codex-rollout-0154.serial.test.ts b/test/codex-rollout-0154.serial.test.ts
index a957d4377d..8a5c4be2de 100644
--- a/test/codex-rollout-0154.serial.test.ts
+++ b/test/codex-rollout-0154.serial.test.ts
@@ -174,6 +174,17 @@ describe('E-N4: assistant turns with no user turn are flagged, never silent', ()
expect(diag.userTurnsMissing).toBe(true);
});
+ test('claude-code adapter: a session started by automation (non-human or meta user records) is not flagged', async () => {
+ const p = writeRollout('claude-automation.jsonl', [
+ JSON.stringify({ type: 'user', sessionId: 's-2', origin: { kind: 'task-notification' }, timestamp: '2026-10-01T09:00:00.000Z', message: { role: 'user', content: 'scheduled run' } }),
+ JSON.stringify({ type: 'user', sessionId: 's-2', isMeta: true, timestamp: '2026-10-01T09:00:01.000Z', message: { role: 'user', content: 'expanded command' } }),
+ JSON.stringify({ type: 'assistant', sessionId: 's-2', isSidechain: false, timestamp: '2026-10-01T09:00:02.000Z', message: { role: 'assistant', content: [{ type: 'text', text: 'done' }] } }),
+ ]);
+ const { diag } = await drain(claudeCodeAdapter.parse(p));
+ expect(diag.sessions).toBe(1);
+ expect(diag.userTurnsMissing).toBeUndefined();
+ });
+
test('session-end heartbeats degraded:no_user_turns for an assistant-only rollout and still banks the corpus', async () => {
const codexHome = join(tmp, 'codex');
process.env.CODEX_HOME = codexHome;