Skip to content

Regenerate a --no-cache directory when a source .jsonl grows (#254)#256

Merged
cboos merged 1 commit into
mainfrom
dev/nocache-dir-staleness
Jul 2, 2026
Merged

Regenerate a --no-cache directory when a source .jsonl grows (#254)#256
cboos merged 1 commit into
mainfrom
dev/nocache-dir-staleness

Conversation

@cboos

@cboos cboos commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #254.

Problem

The single-file source-mtime freshness check added in #221 was scoped to
input_path.is_file(). A directory run without a cache (e.g.
--no-cache, where cache_manager is None) falls through to the same
no-cache fallback branch, but with no file mtime to compare and no DB tracking
per-source mtimes, should_regenerate rode is_outdated() (embedded tool
version) alone. So a session .jsonl that grew between runs with an unchanged
tool version was wrongly reported "current" → stale combined_transcripts.html.

The cached directory path is unaffected — it tracks source mtimes via
is_html_stale.

Fix

Extend the no-cache fallback's freshness check to directory sources: regenerate
when the newest source .jsonl in the directory is newer than the output —
the directory analogue of the single-file input.mtime > output.mtime,
persistence-free (the output's own mtime is the basis).

  • Non-recursive glob("*.jsonl"), matching how directory mode discovers
    sessions.
  • Shares the cache's filesystem-mtime granularity limit; also, a
    <stem>/subagents/ transcript growing without its top-level parent being
    touched isn't caught (rare — the parent session records the spawning
    tool_use and usually grows too). Noted in the code comment.
  • Feeds only the combined regeneration decision, so the RegenerationReport
    signals stay accurate ("Successfully combined" prints because it truly did).

Test

test_grown_session_regenerates_without_cache — grow a session in a directory,
run --no-cache twice, assert the 2nd run regenerates (new content present),
coarse-FS-safe via os.utime. Verified RED before (served stale) and
GREEN after; also confirmed with a real CLI repro.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved refresh detection when cache is disabled, so updated source files are more reliably reflected in generated output.
    • Directory-based inputs now correctly trigger regeneration when any newer source file is present.
  • Tests
    • Added coverage for stale-output handling with directory inputs to verify refreshed content is regenerated as expected.

The single-file source-mtime freshness check (#221) was scoped to
`input_path.is_file()`, so a directory run WITHOUT a cache (e.g. `--no-cache`,
where `cache_manager` is None) fell through to a version-only skip: with no DB
tracking per-source mtimes and no file mtime to compare, `should_regenerate`
rode `is_outdated()` alone, so a session that grew between runs served stale
`combined_transcripts.html`. (The cached directory path is unaffected — it
tracks source mtimes via `is_html_stale`.)

Extend the no-cache fallback's freshness check to directory sources: regenerate
when the newest source `.jsonl` in the directory is newer than the output — the
directory analogue of the single-file `input.mtime > output.mtime`,
persistence-free (the output's own mtime is the basis). Non-recursive glob,
matching how directory mode discovers sessions; shares the cache's mtime
granularity limit (a `<stem>/subagents/` transcript growing without its
top-level parent being touched isn't caught — rare, noted in the comment).
Flows into the combined regeneration decision only, so the RegenerationReport
signals stay accurate ("Successfully combined" prints because it truly did).

Test: test_grown_session_regenerates_without_cache — grow a session in a dir,
run `--no-cache` twice, assert the 2nd regenerates (coarse-FS-safe via
os.utime). RED before (served stale), GREEN after.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b810f07-baa2-41a7-b61b-af6fe00f621d

📥 Commits

Reviewing files that changed from the base of the PR and between fc80008 and 03033fa.

📒 Files selected for processing (2)
  • claude_code_log/converter.py
  • test/test_output_explicit.py

📝 Walkthrough

Walkthrough

The fallback freshness check in convert_jsonl_to was updated to support directory inputs by comparing output mtime against the newest top-level *.jsonl file's mtime, in addition to the existing single-file comparison. A new test validates regeneration under --no-cache when a directory's session file grows.

Changes

Directory Staleness Fix

Layer / File(s) Summary
Freshness check for directory inputs and regression test
claude_code_log/converter.py, test/test_output_explicit.py
source_is_newer fallback logic now handles directory inputs by comparing output mtime to the newest top-level .jsonl mtime, feeding should_regenerate; a new test asserts --no-cache regenerates combined HTML when a directory's session grows.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Converter as convert_jsonl_to
    participant FS as Filesystem

    User->>CLI: run with --no-cache on directory
    CLI->>Converter: convert_jsonl_to(directory)
    Converter->>FS: get output mtime
    Converter->>FS: get max mtime of top-level *.jsonl files
    Converter->>Converter: compute source_is_newer
    Converter->>Converter: compute should_regenerate
    alt should_regenerate is True
        Converter->>FS: regenerate combined_transcripts.html
    else
        Converter-->>CLI: skip regeneration
    end
Loading

Related Issues: #254

Suggested labels: bug, converter

Suggested reviewers: daaain

🐰 A session grew, the cache stayed blind,
Now directories no longer leave old html behind,
mtimes compared, a freshness true,
Stale pages vanish, replaced anew,
Hop hop, the fix is neat and kind.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly names the no-cache directory regeneration fix and the relevant issue, matching the main change.
Linked Issues check ✅ Passed The code and test directly address #254 by regenerating when a directory's newest .jsonl is newer than the output.
Out of Scope Changes check ✅ Passed The diff stays focused on directory no-cache freshness logic and its test, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/nocache-dir-staleness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cboos cboos merged commit ed91762 into main Jul 2, 2026
17 checks passed
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.

--no-cache on a directory serves stale HTML when a source grows

1 participant