Skip to content

Commit 81b35cb

Browse files
committed
fix(perf): match Codex input classes to the rollouts the loader reads
The input-class matchers looked at absolute paths: any `.zst` file counted as a compressed rollout, and any path containing `/archived_sessions/`, including a parent of the fixture, counted as an archived session. Match paths relative to the Codex home against what the loader reads: `*.jsonl` and `*.jsonl.zst` (reader.rs) under `sessions/` and `archived_sessions/` (paths.rs). Tests cover non-rollout `.zst` files, rollouts outside those directories, non-rollout files in `archived_sessions/`, and a fixture under a directory named `archived_sessions`. Reported by Cubic on #2061.
1 parent f4362a2 commit 81b35cb

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎apps/ccusage/scripts/compare-pr-performance_test.clj‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,18 @@
228228
(with-fixture ["sessions/2026/06/01/rollout-a.jsonl.zst"]
229229
#(is (.contains (:warning (codex-compatibility reads? [v30 main] %)) "`v20.0.30` cannot read zstd-compressed rollouts")))
230230
(with-fixture ["archived_sessions/rollout-a.jsonl.zst"]
231-
#(is (= {:layout "current"} (codex-compatibility reads? [main] %)))))))
231+
#(is (= {:layout "current"} (codex-compatibility reads? [main] %)))))
232+
(testing "only files the Codex loader reads as rollouts count"
233+
(with-fixture ["sessions/2026/06/01/cache.bin.zst" "sessions/notes.json.zst" "other/rollout-a.jsonl.zst"
234+
"archived_sessions/README.md" "sessions/2026/06/01/rollout-a.jsonl"]
235+
#(is (nil? (codex-compatibility reads? [v5 main] %))))
236+
(let [parent (babashka.fs/create-temp-dir {:prefix "ccusage-codex-fixture."})
237+
dir (path parent "archived_sessions" "codex")]
238+
(try
239+
(babashka.fs/create-dirs (path dir "sessions"))
240+
(spit (path dir "sessions" "rollout-a.jsonl") "")
241+
(is (nil? (codex-compatibility reads? [v5 main] dir)))
242+
(finally (babashka.fs/delete-tree parent)))))))
232243

233244
(let [{:keys [fail error]} (apply run-tests ['compare-pr-performance-test])]
234245
(when (pos? (+ fail error))

‎apps/ccusage/scripts/compare_pr_performance/history.clj‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,19 @@
128128
#1794) do not apply to unbounded reports, so nothing else belongs here."
129129
[{:name "archived sessions (`archived_sessions/`)" :pr "#1230"
130130
:commit "a9b12c43ac608d308bb4a2c5f5673dc6b9e530c1"
131-
:matches? #(str/includes? % "/archived_sessions/")}
131+
:matches? #(re-matches #"archived_sessions/.+\.jsonl(\.zst)?" %)}
132132
{:name "zstd-compressed rollouts (`.jsonl.zst`)" :pr "#1890"
133133
:commit "44a3aa84e84cbc1afa40dab3f2849e03e9a9b054"
134-
:matches? #(str/ends-with? % ".zst")}])
134+
:matches? #(re-matches #"(archived_sessions|sessions)/.+\.jsonl\.zst" %)}])
135+
136+
(defn codex-rollout-paths
137+
"Fixture files relative to the Codex home, with `/` separators, which is
138+
how the input classes match the directories and rollout names the Codex
139+
loader reads."
140+
[codex-dir]
141+
(->> (file-seq (fs/file codex-dir))
142+
(filter fs/regular-file?)
143+
(map #(str/join "/" (map str (fs/relativize codex-dir %))))))
135144

136145
(defn reads-input-class?
137146
"A binary path cannot be checked, so only a commit that contains the
@@ -160,7 +169,7 @@
160169
:note (str "Note: " (describe skipped) ". The Codex fixture therefore uses the legacy layout: every rollout "
161170
"uncompressed under `sessions/`, which every ref reads in full.")}
162171
:else
163-
(let [files (map str (filter fs/regular-file? (file-seq (fs/file fixture-codex-dir))))
172+
(let [files (codex-rollout-paths fixture-codex-dir)
164173
present (filter (fn [input-class] (some (:matches? input-class) files)) skipped)]
165174
(when (seq present)
166175
{:warning (str "⚠️ **Warning:** the custom Codex fixture contains input some refs skip: " (describe present)

0 commit comments

Comments
 (0)