Skip to content

fix(transcript_cache): fingerprint equal-size in-place rewrites - #573

Closed
AshSgDe29071999 wants to merge 1 commit into
Metabuilder-Labs:mainfrom
AshSgDe29071999:fix-560-transcript-cache-fingerprint
Closed

AshSgDe29071999 wants to merge 1 commit into
Metabuilder-Labs:mainfrom
AshSgDe29071999:fix-560-transcript-cache-fingerprint

Conversation

@AshSgDe29071999

Copy link
Copy Markdown

Summary

  • Adds a cheap head/tail content fingerprint alongside (size, mtime) so equal-length in-place rewrites that preserve mtime invalidate the parse cache.
  • Extends unit coverage for the equal-size / same-mtime rewrite case.

Fixes #560

Test plan

  • pytest tests/unit/test_transcript_cache.py -q

Made with Cursor

Add a cheap head/tail content hash alongside size+mtime so an equal-length
rewrite that preserves mtime no longer serves stale parsed records.

Fixes #560
@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR strengthens transcript-cache invalidation for equal-size, same-mtime rewrites.

  • Adds a head/tail content fingerprint to cache metadata and validation.
  • Adds regression coverage for an in-place rewrite that preserves size and mtime.
  • Updates direct cache-storage tests for the new fingerprint field.

Confidence Score: 4/5

The PR should not merge until fingerprinting preserves the cache reader’s tolerant behavior when a transcript disappears or becomes unreadable mid-scan.

The separate fingerprint open can raise after stat succeeds, allowing a normal concurrent filesystem race to escape cached_read_records despite its documented empty-result behavior.

Files Needing Attention: tokenjam/core/transcript_cache.py

Important Files Changed

Filename Overview
tokenjam/core/transcript_cache.py Adds fingerprint-based validation, but the new unguarded file read breaks tolerant handling of files disappearing during scans.
tests/unit/test_transcript_cache.py Updates the storage helper invocation and adds focused coverage for equal-size, same-mtime rewrites.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
tokenjam/core/transcript_cache.py:109
**Fingerprint read escapes I/O handling**

When a transcript is deleted, replaced, or becomes unreadable after `stat()` succeeds, `_content_fingerprint` performs a separate unguarded open that raises `OSError`, causing the scan to fail instead of returning the documented empty result.

Reviews (1): Last reviewed commit: "fix(transcript_cache): fingerprint equal..." | Re-trigger Greptile

except OSError:
return []
size, mtime = st.st_size, st.st_mtime
fingerprint = _content_fingerprint(path, size)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Fingerprint read escapes I/O handling

When a transcript is deleted, replaced, or becomes unreadable after stat() succeeds, _content_fingerprint performs a separate unguarded open that raises OSError, causing the scan to fail instead of returning the documented empty result.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/core/transcript_cache.py
Line: 109

Comment:
**Fingerprint read escapes I/O handling**

When a transcript is deleted, replaced, or becomes unreadable after `stat()` succeeds, `_content_fingerprint` performs a separate unguarded open that raises `OSError`, causing the scan to fail instead of returning the documented empty result.

How can I resolve this? If you propose a fix, please make it concise.

@anshss

anshss commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and sorry to close it. Going with #572, which takes the same
approach but hashes the full file rather than a head/tail window.

Two things decided it. The 64-byte window here means an equal-size, same-mtime
rewrite in the middle of a large transcript still gets served from cache, so the
original issue isn't fully closed; the added test uses a 60-byte file, which sits
entirely inside the window and so can't catch it. Separately, _content_fingerprint
opens the file without an OSError guard, so a transcript that's unreadable or
deleted mid-scan now raises instead of degrading to [] as the module documents.

The instinct was right and the diff was clean. If you'd like another, there are a
few open issues labeled good first issue, and #563 is close to this one in spirit.

@anshss anshss closed this Jul 25, 2026
anshss added a commit to anshss/tokenjam that referenced this pull request Jul 25, 2026
Agentic contribution tools (Cursor background agents and similar) poll
GitHub's search API on `is:open no:assignee label:"good first issue"` —
they don't read claim comments. When 15 issues got both labels in one
burst, two different tools opened PRs for the same issue within 50
minutes of each other because neither tool's feed reflected the other's
claim (public PRs Metabuilder-Labs#572, Metabuilder-Labs#573 against the same issue Metabuilder-Labs#560).

Removing the labels the instant a closing PR opens is the lever that
actually keeps an issue off those feeds; a comment changes nothing they
read. Labels are restored, and only the exact ones this workflow itself
removed, if that PR is later closed without merging.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

transcript parse cache can serve stale records on an equal-size in-place rewrite

2 participants