Skip to content

fix(agents): add file_not_found correlation status for missing transcripts - #538

Open
gokhanozdemir wants to merge 3 commits into
codemie-ai:mainfrom
gokhanozdemir:fix/523-transcript-correlation
Open

gokhanozdemir wants to merge 3 commits into
codemie-ai:mainfrom
gokhanozdemir:fix/523-transcript-correlation

Conversation

@gokhanozdemir

@gokhanozdemir gokhanozdemir commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Interactive Claude sessions can fail to persist transcripts at their expected file paths. PTY-driven sessions weren't validated for file existence, so the correlation logic incorrectly marked non-existent files as "matched," producing empty session metrics. This adds a file_not_found correlation status so missing transcripts are handled gracefully instead.

Fixes #523

Changes

  • Add a file_not_found status to the correlation type system
  • Validate file existence before marking correlations as matched in the hook command
  • Update the session synchronizer to skip gracefully when files are missing, instead of failing outright

Impact

No user-facing behavior change for existing successful correlations; missing-transcript cases now report a clear status instead of silently producing empty metrics.

Checklist

  • Self-reviewed
  • Manual testing performed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)

@gokhanozdemir gokhanozdemir changed the title fix(agents): add file_not_found correlation status for missing transcripts fix: add file_not_found correlation status for missing transcripts Sep 5, 2026
@gokhanozdemir gokhanozdemir changed the title fix: add file_not_found correlation status for missing transcripts fix(agents): add file_not_found correlation status for missing transcripts Sep 5, 2026
@gokhanozdemir
gokhanozdemir force-pushed the fix/523-transcript-correlation branch from 1bb4605 to 2991cec Compare September 5, 2026 16:46
@gokhanozdemir gokhanozdemir changed the title fix(agents): add file_not_found correlation status for missing transcripts fix(session): add file_not_found correlation status for missing transcripts Sep 5, 2026
@gokhanozdemir
gokhanozdemir force-pushed the fix/523-transcript-correlation branch from 2991cec to 6a7b7f6 Compare September 5, 2026 16:52
@gokhanozdemir gokhanozdemir changed the title fix(session): add file_not_found correlation status for missing transcripts chore(session): add file_not_found correlation status for missing transcripts Sep 5, 2026
@gokhanozdemir gokhanozdemir changed the title chore(session): add file_not_found correlation status for missing transcripts fix(agents): add file_not_found correlation status for missing transcripts Sep 5, 2026
@gokhanozdemir
gokhanozdemir marked this pull request as ready for review September 5, 2026 17:22
…ripts

Interactive Claude sessions don't persist transcripts at the reported path
for PTY-driven sessions. The correlation logic now checks if the transcript
file actually exists on disk before marking it as 'matched'. If the file doesn't
exist, correlation status is set to 'file_not_found' instead, preventing metrics
processing failures and providing better error handling for interactive sessions
where transcript persistence is expected to be absent.

Fixes codemie-ai#523
@gokhanozdemir
gokhanozdemir force-pushed the fix/523-transcript-correlation branch from 6d94c0f to 1cf15ff Compare September 15, 2026 15:23
@gokhanozdemir

Copy link
Copy Markdown
Contributor Author

Adversarial review

Critical regression: event.transcript_path ? existsSync(...) : false forces correlationStatus to 'file_not_found' whenever transcript_path is empty. But codemie-code, codex, copilot-cli, opencode, and pi all fire SessionStart with transcript_path: '' by design (path not known yet):

  • src/agents/plugins/codemie-code.plugin.ts:233
  • src/agents/plugins/codex/codex.plugin.ts:191
  • src/agents/plugins/copilot-cli/copilot-cli.plugin.ts:161
  • src/agents/plugins/opencode/opencode.plugin.ts:210
  • src/agents/plugins/pi/pi.plugin.ts:376

Nothing anywhere ever rewrites correlation.status after creation (verified repo-wide), so these sessions get stuck at file_not_found permanently, and SessionSyncer.sync() silently (success: true) skips them forever. This breaks metrics/conversation sync for most agents, not just interactive Claude PTY sessions — a much bigger regression than the bug being fixed.

Broken pre-existing test: tests/integration/agent-model.test.ts:329 skip-guards on correlationStatus === 'failed', written specifically to tolerate this exact issue (#523). The new code never produces 'failed' here — it produces 'file_not_found' — so the guard is dead and the test will fail instead of skipping gracefully.

Other issues:

  • Race on re-entrant SessionStart (e.g. compact) can downgrade an already-matched live session to file_not_found with no recovery path.
  • One-shot existsSync check at record-creation time doesn't cover a transcript appearing moments later, or one deleted/rotated after being marked matched.
  • Duplicated existsSync/ternary/warn block across two branches in hook.ts; redundant dynamic import('node:fs') for a builtin already statically imported elsewhere.

Fix applied in a follow-up push: only mark file_not_found when a non-empty transcript_path was reported and is missing; keep prior behavior when no path was reported (the deliberate "not known yet" case); dedupe the two branches; use a static existsSync import; update the test's skip guard to also accept file_not_found.

@gokhanozdemir
gokhanozdemir marked this pull request as draft September 15, 2026 15:35
…ted transcript

An empty transcript_path is a deliberate "not known yet" signal from
codemie-code, codex, copilot-cli, opencode, and pi at SessionStart, not
a failure. The previous check treated it the same as a reported path
that doesn't exist, permanently stranding those sessions at
file_not_found and silently dropping their metrics/conversation sync.

Also dedupes the existsSync/warn logic into one helper and updates the
codemie-ai#523 skip guard in agent-model.test.ts to match the actual status this
fix now produces.

Generated with AI

Co-Authored-By: codemie-ai <[email protected]>
@gokhanozdemir

Copy link
Copy Markdown
Contributor Author

Cherry-picked the Windows CI teardown fix from #537 (110add2f) onto this branch to unblock the flaky migration-runner-ordering.test.ts failure we hit here.

That commit matches an existing established pattern already used in several test files in this codebase (claude.metrics-processor-names.test.ts:104, claude.metrics-processor-clear.test.ts:90, codex-models.test.ts:141, metrics-upload-contract.test.ts:112): wrap rmSync(..., { recursive: true, force: true }) with maxRetries: 5, retryDelay: 100, plus a try/catch that swallows the cleanup error. Reason: on Windows, rmSync's force option only suppresses ENOENT, not the ENOTEMPTY/EBUSY that can occur when a file handle (e.g. from a logger stream) is released a moment after the recursive delete already removed the children.

Not a hack — it's the codebase's already-established idiom for this class of flaky Windows teardown, applied here to the migration runner test that was failing on our Windows CI job.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive Claude sessions: transcript not persisted at reported path → session metrics silently empty (0 records)

1 participant