Skip to content

SWF(bug): keep in-window sessions whose transcript has an old mtime in stats - #46

Merged
kodji7202-code merged 12 commits into
mainfrom
devin/1795209837-stats-old-mtime
Nov 26, 2026
Merged

kodji7202-code merged 12 commits into
mainfrom
devin/1795209837-stats-old-mtime

Conversation

@kodji7202-code

@kodji7202-code kodji7202-code commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

runledger stats no longer drops a session that started inside the window just because its transcript file has an older mtime (copied, restored or synced with a preserved/wrong mtime).

Root cause

collect() in runledger/stats.py skipped every file with st_mtime < since before it looked at the cache or the transcript, on the assumption that an old file can't hold a newer session. That assumption breaks whenever the mtime isn't the real last write, so the session vanished from the report (No sessions found ..., exit 1).

Fix

The mtime check is now only a hint for which files to check cheaply, not a reason to drop them:

summary = cache.get(path, st)                      # valid full summary always wins
if summary is None and st.st_mtime < since:        # old file, not cached
    started = cache.get_start(path, st) or _session_start(path)   # header record(s) only, <=64 KiB
    cache.put_start(path, st, started)              # remembered, so warm runs don't reopen it
    if started is known and not since <= started <= until:
        continue                                    # genuinely old: still never fully parsed
# otherwise: parse as before
  • _session_start accepts only standard Claude, Codex (session_meta and legacy untyped) and Droid headers; anything uncertain (unknown layout, unparsable or out-of-range timestamp) returns None and falls back to the full parser, so it can never hide a session.
  • Start-only cache records are tagged "kind": "start", store a UTC instant (so a time-zone change can't misplace them), are validated by the transcript's mtime_ns + size, can't be returned as summaries, and share the normal _trim / MAX_CACHE_ENTRIES path. Existing caches load unchanged (no version bump).

Evidence

Real CLI, isolated home, one Claude transcript stamped 2026-05-10T12:00:00Z with mtime set to 2020-01-01 via os.utime:

runledger stats --all --since 2026-05-01 --until 2026-05-31

main this PR
exit: 1
No sessions found between 2026-05-01 and 2026-05-31.
exit: 0
RunLedger stats - any project (since 2026-05-01 until 2026-05-31, 1 session, 1 agent)
claude-code 1 ...

New regression test, run against main's collect() first:

$ python -m pytest -q tests/test_stats.py -k old_mtime_does_not_hide
FAILED ...test_old_mtime_does_not_hide_in_window_start[False-claude_session]   assert 0 == 1
... (codex, droid, cached and uncached: 6 failed)
6 failed, 81 deselected in 0.46s

With the fix:

$ python -m pytest -q tests/test_stats.py
122 passed in 2.28s

Tests also assert the probed start equals summarize(path).started for Claude, Codex (modern and legacy) and Droid, that time-zone changes and year-1 / overflowing timestamps never misplace a session or abort the run, that genuinely old sessions are skipped without summarize, that start records are invalidated by mtime or size changes, promoted to full summaries when the window widens, and trimmed with the rest.

Full suite on the branch merged with current main: 4330 passed, 42 skipped.

Benchmark (cold cache preserved)

3,000 transcripts of ~1 MB, 80% old start + old mtime, 20% in window. Real runledger stats subprocesses (startup + discovery included), 15 repeats per side, alternating main/PR order, idle machine. Cold = .runledger/cache deleted before the run (OS page cache not flushed); warm = immediately after cold. Main loaded from an unchanged worktree via PYTHONPATH.

Cache main (median) this PR (median) diff
Cold 2.699 s 2.829 s +130 ms (+4.8%)
Warm 0.302 s 0.315 s +13 ms (+4.2%)

Old out-of-window sessions are still never fully parsed (summarize() runs 600 times per cold run on both sides). cProfile puts the added cold cost in 2,400 one-line header probes (~107 ms instrumented: mostly open/readline/json.loads). That is the price of not trusting mtimes; warm runs reuse the cached start and don't reopen those files.

Try it

pip install -e . && runledger stats --all --since 7d with a transcript whose mtime you backdate: python -c "import os;os.utime('<transcript.jsonl>',(1577880000,1577880000))"

Not tested

Old-mtime non-JSONL transcripts (Aider history) have no cheap header, so a cold run now parses them once and caches the summary; not benchmarked separately. OS page cache was not flushed for "cold" runs.

CI stabilization

The approval test fixture now reads the POST body before sending a 401 response. On Windows, unread request input can reset the TCP connection before the client reads that response, which made test_http_approver_wrong_key_falls_back_to_a_local_ask intermittently lose the status code. This is a test-fixture-only change.

Link to Devin session: https://app.devin.ai/sessions/985aa7d6d922481dad503dcb404e15d3
Open in Devin Desktop: https://app.devin.ai/desktop/session/985aa7d6d922481dad503dcb404e15d3?variant=devin
Requested by: @kodji7202-code


Software Factory opened this PR for Officialkairomgmt
Implemented in session Keep in-window transcripts with old file mtimes
Review with Devin · Open in Devin Desktop


officialkairomgmt and others added 2 commits November 20, 2026 21:32
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T21:44:44.600078Z c7f9f7d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7f9f7d9c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread runledger/stats.py Outdated
if codex and (kind != "session_meta" or not isinstance(record.get("payload"), dict)):
return None
stamp = record.get("timestamp")
return _local(_ts(stamp)) if isinstance(stamp, str) else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle timestamp overflow in the old-file probe

When an old-mtime JSONL starts with a boundary timestamp such as 0001-01-01T00:00:00+01:00, _ts can raise OverflowError while converting it to UTC. This probe runs before collect()'s summarize() exception handler, so one such transcript aborts the entire stats command; handle the overflow at the parsing or collection boundary so it cannot escape.

Useful? React with 👍 / 👎.

officialkairomgmt and others added 4 commits November 20, 2026 21:45
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment •

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

officialkairomgmt and others added 3 commits November 20, 2026 22:39
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Capy couldn't review this pull request because Cojo's workspace is out of credits, add credits or enable auto-reload to resume automatic reviews.

The code reviews included with your plan this billing period are used up, so reviews are paid from your credits until the plan resets. A Low or Medium effort review counts as 1 included review, and a High effort review counts as 2.

Open in Capy

officialkairomgmt and others added 3 commits November 26, 2026 13:04
…s-old-mtime

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…s-old-mtime

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
@kodji7202-code
kodji7202-code merged commit 206dd6b into main Nov 26, 2026
25 checks passed
@kodji7202-code
kodji7202-code deleted the devin/1795209837-stats-old-mtime branch November 26, 2026 14:16
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.

1 participant