From dfd3ee31a9d111f9f0c4287b39b81bbbcddd3723 Mon Sep 17 00:00:00 2001 From: Omri Maya Date: Mon, 15 Jun 2026 16:54:34 +0300 Subject: [PATCH] fix(codex): derive date-prefix strip from regex, drop magic offset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit f.slice(11) silently assumed len("YYYY-MM-DD-") and was coupled to the `dated` regex two lines up — change the date format and it points at the wrong offset while still "working". Strip with f.replace(dated, '') so the prefix length lives in exactly one place. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../agent-runner/src/providers/exchange-archive.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/container/agent-runner/src/providers/exchange-archive.ts b/container/agent-runner/src/providers/exchange-archive.ts index 8d77eecae..b92278cb3 100644 --- a/container/agent-runner/src/providers/exchange-archive.ts +++ b/container/agent-runner/src/providers/exchange-archive.ts @@ -82,13 +82,14 @@ function threadArchiveFilename( const thread = sanitizeSlug(continuation || 'no-thread').slice(0, 48) || 'no-thread'; const suffix = `${sanitizeSlug(provider)}-${thread}.md`; // Stable across appends: reuse this thread's existing file (whatever date it - // was first created on) so later exchanges keep landing in one file; only - // stamp the creation date when none exists yet. Keeps conversations/ sortable - // by name (thread start date) while staying one-file-per-thread. slice(11) - // strips the `YYYY-MM-DD-` prefix for an exact suffix match (no substring - // false-positives between threads with shared prefixes). + // was first created on); only stamp the creation date when none exists yet. + // Strip the date prefix with the same `dated` regex (not a fixed offset) for + // an exact suffix match — no substring false-positives, no magic length to + // drift if the date format changes. + // ponytail: O(dir) scan per append — fine at hundreds of threads; cache + // thread→filename in memory if conversations/ ever holds thousands. const dated = /^\d{4}-\d{2}-\d{2}-/; - const existing = fs.readdirSync(dir).find((f) => dated.test(f) && f.slice(11) === suffix); + const existing = fs.readdirSync(dir).find((f) => dated.test(f) && f.replace(dated, '') === suffix); if (existing) return existing; return `${timestamp.toISOString().split('T')[0]}-${suffix}`; }