From 43cd3c129a1ca6f6c61bf7f1101952434511c161 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Tue, 17 Nov 2026 10:41:46 +1030 Subject: [PATCH 01/11] fix(cache): tell long-id steps apart by an identity digest under --strict-cache An entry keeps the test id, target id, and agent name cut to 300 characters. Two steps whose names agree in their first 299 characters stored the same provenance, so the strict rekey check took a step that was never recorded for one whose key changed and failed it with REPLAY_STALE. When a name is longer than an entry keeps, the entry now also stores identityDigest, the SHA-256 of the whole redacted names, and stepKey compares it. A confirmed replay writes the digest into a kept entry that predates it. Co-Authored-By: Claude Opus 5.5 --- .changeset/strict-cache-long-test-id.md | 6 +++ docs/cache.mdx | 1 + packages/core/src/cache/context.ts | 12 +++--- packages/core/src/cache/recorder.ts | 12 ++++-- packages/core/src/cache/rekeyed.ts | 11 ++++-- packages/core/src/cache/trace-read.ts | 3 ++ packages/core/src/cache/trace.ts | 6 +++ packages/e2e/tests/unit/step-cache.test.ts | 38 ++++++++++++++++++- .../e2e/tests/unit/trace-cache-config.test.ts | 19 ++++++++++ 9 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 .changeset/strict-cache-long-test-id.md diff --git a/.changeset/strict-cache-long-test-id.md b/.changeset/strict-cache-long-test-id.md new file mode 100644 index 0000000000..3ead905e10 --- /dev/null +++ b/.changeset/strict-cache-long-test-id.md @@ -0,0 +1,6 @@ +--- +'e2e': patch +'@e2e-dev/core': patch +--- + +`--strict-cache` no longer fails with `REPLAY_STALE` a never-recorded step whose test id, target, or agent name is over 300 characters and starts like a recorded one. diff --git a/docs/cache.mdx b/docs/cache.mdx index 8dd1315f18..a82168eff4 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -393,6 +393,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | +| | A step whose test id, target name, or agent name is over 300 characters, when its recording under another key was made by an earlier `e2e` version | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/packages/core/src/cache/context.ts b/packages/core/src/cache/context.ts index 27fbd4c922..0c56fbd1df 100644 --- a/packages/core/src/cache/context.ts +++ b/packages/core/src/cache/context.ts @@ -141,14 +141,16 @@ function flowOf(trace: ActionTrace): string { /** * Writes the step's full provenance into a kept entry recorded before the - * occurrence fields were, leaving every other entry untouched. Its replay - * proved which step it belongs to, and `cache.strict` matches only entries - * that say so exactly (`rekeyed.ts`). + * occurrence fields or the identity digest were, leaving every other entry + * untouched. Its replay proved which step it belongs to, and `cache.strict` + * matches only entries that say so exactly (`rekeyed.ts`). */ async function completeProvenance(store: CacheStore, keyHash: string, recordedFor: TraceProvenance): Promise { const existing = await store.read(keyHash); - if (existing.status !== 'hit' || existing.entry.payload.recordedFor?.callIndex !== undefined) return; - await store.write(keyHash, { ...existing.entry.payload, recordedFor }); + if (existing.status !== 'hit') return; + const stored = existing.entry.payload.recordedFor; + const complete = stored?.callIndex !== undefined && stored.identityDigest === recordedFor.identityDigest; + if (!complete) await store.write(keyHash, { ...existing.entry.payload, recordedFor }); } /** How an attempt ended, as the settlement of its staged entries reads it. */ diff --git a/packages/core/src/cache/recorder.ts b/packages/core/src/cache/recorder.ts index 9246ce5f6f..0cdaf58067 100644 --- a/packages/core/src/cache/recorder.ts +++ b/packages/core/src/cache/recorder.ts @@ -39,6 +39,7 @@ import { type TraceTargetDescriptor, } from './trace.ts'; import { readRecordedModel } from './trace-fields.ts'; +import { sha256Hex } from '../internal/ids.ts'; import { bound } from '../internal/text.ts'; /** The summary a run-time value gap records; the prose a project-tool gap would carry for a tool of that name. */ @@ -342,12 +343,17 @@ function sameTarget(a: TraceTargetDescriptor | undefined, b: TraceTargetDescript * the store holds. */ export function recordedProvenance(provenance: TraceProvenance, redact: (text: string) => string): TraceProvenance { + const testId = redact(provenance.testId); + const targetId = redact(provenance.targetId); + const agent = provenance.agent === undefined ? undefined : redact(provenance.agent); + const cut = [testId, targetId, agent ?? ''].some((text) => text.length > MAX_TRACE_DESCRIPTOR_CHARS); return { - testId: bound(redact(provenance.testId), MAX_TRACE_DESCRIPTOR_CHARS), - targetId: bound(redact(provenance.targetId), MAX_TRACE_DESCRIPTOR_CHARS), + testId: bound(testId, MAX_TRACE_DESCRIPTOR_CHARS), + targetId: bound(targetId, MAX_TRACE_DESCRIPTOR_CHARS), instructionDigest: provenance.instructionDigest, ...(provenance.paramsDigest === undefined ? {} : { paramsDigest: provenance.paramsDigest }), ...(provenance.callIndex === undefined ? {} : { callIndex: provenance.callIndex }), - ...(provenance.agent === undefined ? {} : { agent: bound(redact(provenance.agent), MAX_TRACE_DESCRIPTOR_CHARS) }), + ...(agent === undefined ? {} : { agent: bound(agent, MAX_TRACE_DESCRIPTOR_CHARS) }), + ...(cut ? { identityDigest: sha256Hex(JSON.stringify([testId, targetId, agent ?? null])) } : {}), }; } diff --git a/packages/core/src/cache/rekeyed.ts b/packages/core/src/cache/rekeyed.ts index 3b966e7d31..f53975b07f 100644 --- a/packages/core/src/cache/rekeyed.ts +++ b/packages/core/src/cache/rekeyed.ts @@ -85,9 +85,14 @@ export function storedRecordingsFor(cache: ResolvedCacheConfig): StoredRecording return new StoredRecordings(new FileCacheStore({ directory: cache.dir, maxBytes: MAX_CACHE_WIRE_BYTES, writable: false })); } -/** The whole step as one map key, or undefined when the provenance does not record all of it. */ +/** + * The whole step as one map key, or undefined when the provenance does not + * record all of it. A cut test id, target id, or agent name keys by its + * `identityDigest` too, so an entry recorded before the digest was never + * matches a step whose name was cut. + */ function stepKey(step: TraceProvenance): string | undefined { - const { testId, targetId, instructionDigest, paramsDigest, callIndex, agent } = step; + const { testId, targetId, instructionDigest, paramsDigest, callIndex, agent, identityDigest } = step; if (paramsDigest === undefined || callIndex === undefined || agent === undefined) return undefined; - return JSON.stringify([testId, targetId, instructionDigest, paramsDigest, callIndex, agent]); + return JSON.stringify([testId, targetId, instructionDigest, paramsDigest, callIndex, agent, identityDigest ?? null]); } diff --git a/packages/core/src/cache/trace-read.ts b/packages/core/src/cache/trace-read.ts index df68f58a55..8a22c66dbd 100644 --- a/packages/core/src/cache/trace-read.ts +++ b/packages/core/src/cache/trace-read.ts @@ -426,6 +426,8 @@ function readProvenance(document: unknown): TraceProvenance | undefined { } const agent = raw['agent'] === undefined ? undefined : readBoundedText(raw['agent'], MAX_TRACE_DESCRIPTOR_CHARS); if (raw['agent'] !== undefined && agent === undefined) return undefined; + const identityDigest = raw['identityDigest']; + if (identityDigest !== undefined && (typeof identityDigest !== 'string' || !SHA256_HEX.test(identityDigest))) return undefined; return { testId, targetId, @@ -433,6 +435,7 @@ function readProvenance(document: unknown): TraceProvenance | undefined { ...(paramsDigest === undefined ? {} : { paramsDigest }), ...(callIndex === undefined ? {} : { callIndex }), ...(agent === undefined ? {} : { agent }), + ...(identityDigest === undefined ? {} : { identityDigest }), }; } diff --git a/packages/core/src/cache/trace.ts b/packages/core/src/cache/trace.ts index 4a142a52a0..7bfbfee288 100644 --- a/packages/core/src/cache/trace.ts +++ b/packages/core/src/cache/trace.ts @@ -105,6 +105,12 @@ export interface TraceProvenance { readonly callIndex?: number; /** Name of the configured agent the step ran with. */ readonly agent?: string; + /** + * SHA-256 of the whole redacted test id, target id, and agent name, only + * when one of them is longer than an entry keeps: two steps that differ + * past the cut store the same text but never the same digest. + */ + readonly identityDigest?: string; } /** diff --git a/packages/e2e/tests/unit/step-cache.test.ts b/packages/e2e/tests/unit/step-cache.test.ts index 581845b6a4..943713b7d3 100644 --- a/packages/e2e/tests/unit/step-cache.test.ts +++ b/packages/e2e/tests/unit/step-cache.test.ts @@ -6,9 +6,10 @@ import { join } from 'node:path'; import { afterEach, describe, expect, it, vi } from 'vitest'; import { settleStagedTraces, type AgentCacheContext, type ClaimedKey } from '@e2e-dev/core/lib/cache/context'; import { instructionDigest, paramsDigest } from '@e2e-dev/core/lib/cache/identity'; +import { recordedProvenance } from '@e2e-dev/core/lib/cache/recorder'; import { StoredRecordings } from '@e2e-dev/core/lib/cache/rekeyed'; import { FileCacheStore, MAX_CACHE_WIRE_BYTES } from '@e2e-dev/core/lib/cache/store'; -import { buildTraceEntry, type ActionTrace, type DerivedReason, type TraceEntry } from '@e2e-dev/core/lib/cache/trace'; +import { buildTraceEntry, MAX_TRACE_DESCRIPTOR_CHARS, type ActionTrace, type DerivedReason, type TraceEntry } from '@e2e-dev/core/lib/cache/trace'; import { failedStepOutcome, recordedVerdictOf, StepTraceSession, type StepCacheHost, type StepCacheOptions } from '@e2e-dev/core/lib/agent/step-cache'; import { AgentError } from '@e2e-dev/core/lib/agent/error'; import type { ExecutorActions } from '@e2e-dev/core/lib/agent/executor'; @@ -1394,6 +1395,41 @@ describe('cache.strict and a step whose key changed under its recording', () => } }); + describe.each(['testId', 'targetId', 'agent'] as const)('a %s longer than an entry keeps', (field) => { + const long = 'checkout for a signed in customer with a saved card '.repeat(6); + const stepWith = (value: string) => ({ ...exampleStep, [field]: value }); + const sessionFor = (context: AgentCacheContext, step: typeof exampleStep) => + makeSession({ ...context, claimKey: () => ({ keyHash: OWN_KEY, context: exampleContext, step }) }, makeHost(['/'])); + + it('runs live when only another step that starts the same way was recorded', async () => { + const context = await rekeyedContext(recordedPayload(recordedProvenance(stepWith(`${long} first`), (text) => text))); + const session = sessionFor(context, stepWith(`${long} second`)); + await expect(session.begin()).resolves.toBeUndefined(); + expect(session.cacheInfo).toMatchObject({ mode: 'missed', reason: 'no-entry' }); + }); + + it('fails with REPLAY_STALE when its own recording sits under another key', async () => { + const step = stepWith(`${long} first`); + const stored = recordedProvenance(step, (text) => text); + expect(stored[field]).toHaveLength(MAX_TRACE_DESCRIPTOR_CHARS); + const session = sessionFor(await rekeyedContext(recordedPayload(stored)), step); + await expect(session.begin()).rejects.toMatchObject({ code: 'REPLAY_STALE' }); + }); + + it('runs live against an entry that cut it before entries kept an identity digest', async () => { + const step = stepWith(`${long} first`); + const { identityDigest: _digest, ...legacy } = recordedProvenance(step, (text) => text); + await expect(sessionFor(await rekeyedContext(recordedPayload(legacy)), step).begin()).resolves.toBeUndefined(); + }); + + it(`fails with REPLAY_STALE at exactly ${MAX_TRACE_DESCRIPTOR_CHARS} characters, which an entry keeps whole`, async () => { + const step = stepWith('x'.repeat(MAX_TRACE_DESCRIPTOR_CHARS)); + const stored = recordedProvenance(step, (text) => text); + expect(stored).toEqual(step); + await expect(sessionFor(await rekeyedContext(recordedPayload(stored)), step).begin()).rejects.toMatchObject({ code: 'REPLAY_STALE' }); + }); + }); + it('runs live when the only recording is truncated or records no step', async () => { const tapUpgrade = { name: 'tap', summary: 'tap button "Upgrade"', target: { role: 'button', name: 'Upgrade' } } as const; const truncated = recordedPayload(exampleStep, { actions: Array.from({ length: 50 }, () => tapUpgrade), truncated: true }); diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index d9bffff67a..04f1fc2139 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -6,6 +6,7 @@ import { chmod, mkdtemp, readFile, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { describe, expect, it } from 'vitest'; import { createAgentCacheContext, settleStagedTraces } from '@e2e-dev/core/lib/cache/context'; +import { recordedProvenance } from '@e2e-dev/core/lib/cache/recorder'; import { FileCacheStore } from '@e2e-dev/core/lib/cache/store'; import { buildTraceEntry } from '@e2e-dev/core/lib/cache/trace'; import { readTraceEntry } from '@e2e-dev/core/lib/cache/trace-read'; @@ -358,6 +359,24 @@ describe('settleStagedTraces', () => { expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload).toEqual({ ...recorded, recordedFor: STEP }); }); + it('writes the identity digest into a confirmed kept entry that cut a long test id before entries kept one', async () => { + const store = memoryStore(); + const long = { ...STEP, testId: `${STEP.testId}${'x'.repeat(400)}` }; + const recordedFor = recordedProvenance(long, (text) => text); + const { identityDigest, ...legacy } = recordedFor; + expect(identityDigest).toMatch(/^[a-f0-9]{64}$/u); + store.entries.set(KEY_A, JSON.stringify(buildTraceEntry({ ...trace('replayed flow'), recordedFor: legacy }))); + const context = contextWith(store); + context.staged.push({ kind: 'keep', keyHash: KEY_A, stepIndex: 1, recordedFor }); + await settleStagedTraces(context, { lastVerifiedStepIndex: 2, implicatesUnconfirmed: true }); + expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload.recordedFor).toEqual(recordedFor); + }); + + it('refuses an entry whose identity digest is not a SHA-256 hex digest', () => { + const entry = buildTraceEntry({ ...trace('recorded flow'), recordedFor: { ...STEP, identityDigest: 'not-a-digest' } }); + expect(readTraceEntry(JSON.parse(JSON.stringify(entry)))).toBeUndefined(); + }); + it('writes what was confirmed and leaves every unconfirmed entry as stored when the failure implicates nothing', async () => { const KEY_C = 'c'.repeat(64); const store = memoryStore(); From ba838f9af1700c0ad09d5c36637b7d9e725a5729 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Tue, 17 Nov 2026 11:06:54 +1030 Subject: [PATCH 02/11] fix(cache): key by the identity digest a name that ends like a cut bound() cuts a name to 299 characters and an ellipsis (298 after a surrogate pair). A whole target or agent name of that shape stored no digest, so it matched an entry recorded before the digest for another step whose name was cut, and strict failed it with REPLAY_STALE. boundIsAmbiguous() names both cases, and recordedProvenance writes the digest for either. Also pins that the digest is taken over the redacted names. Co-Authored-By: Claude Opus 5.5 --- docs/cache.mdx | 2 +- packages/core/src/cache/recorder.ts | 6 +++--- packages/core/src/cache/rekeyed.ts | 5 ++--- packages/core/src/cache/trace.ts | 4 ++-- packages/core/src/internal/text.ts | 5 +++++ packages/e2e/tests/unit/step-cache.test.ts | 18 +++++++++++++++++- packages/e2e/tests/unit/text.test.ts | 13 ++++++++++++- .../e2e/tests/unit/trace-cache-config.test.ts | 12 ++++++++++++ 8 files changed, 54 insertions(+), 11 deletions(-) diff --git a/docs/cache.mdx b/docs/cache.mdx index a82168eff4..e7d982106d 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -393,7 +393,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | -| | A step whose test id, target name, or agent name is over 300 characters, when its recording under another key was made by an earlier `e2e` version | +| | A step whose test file and titles, target name, or agent name come to over 300 characters, when its recording under another key was made by an earlier `e2e` version | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/packages/core/src/cache/recorder.ts b/packages/core/src/cache/recorder.ts index 0cdaf58067..878f29c924 100644 --- a/packages/core/src/cache/recorder.ts +++ b/packages/core/src/cache/recorder.ts @@ -40,7 +40,7 @@ import { } from './trace.ts'; import { readRecordedModel } from './trace-fields.ts'; import { sha256Hex } from '../internal/ids.ts'; -import { bound } from '../internal/text.ts'; +import { bound, boundIsAmbiguous } from '../internal/text.ts'; /** The summary a run-time value gap records; the prose a project-tool gap would carry for a tool of that name. */ const DERIVED_GAP_SUMMARY = 'tool type (run-time value)'; @@ -346,7 +346,7 @@ export function recordedProvenance(provenance: TraceProvenance, redact: (text: s const testId = redact(provenance.testId); const targetId = redact(provenance.targetId); const agent = provenance.agent === undefined ? undefined : redact(provenance.agent); - const cut = [testId, targetId, agent ?? ''].some((text) => text.length > MAX_TRACE_DESCRIPTOR_CHARS); + const ambiguous = [testId, targetId, agent ?? ''].some((text) => boundIsAmbiguous(text, MAX_TRACE_DESCRIPTOR_CHARS)); return { testId: bound(testId, MAX_TRACE_DESCRIPTOR_CHARS), targetId: bound(targetId, MAX_TRACE_DESCRIPTOR_CHARS), @@ -354,6 +354,6 @@ export function recordedProvenance(provenance: TraceProvenance, redact: (text: s ...(provenance.paramsDigest === undefined ? {} : { paramsDigest: provenance.paramsDigest }), ...(provenance.callIndex === undefined ? {} : { callIndex: provenance.callIndex }), ...(agent === undefined ? {} : { agent: bound(agent, MAX_TRACE_DESCRIPTOR_CHARS) }), - ...(cut ? { identityDigest: sha256Hex(JSON.stringify([testId, targetId, agent ?? null])) } : {}), + ...(ambiguous ? { identityDigest: sha256Hex(JSON.stringify([testId, targetId, agent ?? null])) } : {}), }; } diff --git a/packages/core/src/cache/rekeyed.ts b/packages/core/src/cache/rekeyed.ts index f53975b07f..909f69666e 100644 --- a/packages/core/src/cache/rekeyed.ts +++ b/packages/core/src/cache/rekeyed.ts @@ -87,9 +87,8 @@ export function storedRecordingsFor(cache: ResolvedCacheConfig): StoredRecording /** * The whole step as one map key, or undefined when the provenance does not - * record all of it. A cut test id, target id, or agent name keys by its - * `identityDigest` too, so an entry recorded before the digest was never - * matches a step whose name was cut. + * record all of it. A step with a cut test id, target id, or agent name keys + * by its `identityDigest` too, so it never matches an entry that has none. */ function stepKey(step: TraceProvenance): string | undefined { const { testId, targetId, instructionDigest, paramsDigest, callIndex, agent, identityDigest } = step; diff --git a/packages/core/src/cache/trace.ts b/packages/core/src/cache/trace.ts index 7bfbfee288..0a8fb47ffe 100644 --- a/packages/core/src/cache/trace.ts +++ b/packages/core/src/cache/trace.ts @@ -107,8 +107,8 @@ export interface TraceProvenance { readonly agent?: string; /** * SHA-256 of the whole redacted test id, target id, and agent name, only - * when one of them is longer than an entry keeps: two steps that differ - * past the cut store the same text but never the same digest. + * when one of them is longer than an entry keeps or ends like a cut: two + * steps whose stored text is the same never share the digest. */ readonly identityDigest?: string; } diff --git a/packages/core/src/internal/text.ts b/packages/core/src/internal/text.ts index fb8df7bdea..125e77cd41 100644 --- a/packages/core/src/internal/text.ts +++ b/packages/core/src/internal/text.ts @@ -17,6 +17,11 @@ export function bound(text: string, maxChars: number): string { return `${text.slice(0, end)}…`; } +/** Whether `bound(text, maxChars)` could equal what `bound` makes of a different text: it cuts `text`, or `text` already ends like a cut. */ +export function boundIsAmbiguous(text: string, maxChars: number): boolean { + return text.length > maxChars || (text.length >= maxChars - 1 && text.endsWith('…')); +} + /** * Normalizes text by trimming leading/trailing whitespace and replacing every * nonempty run of Unicode whitespace with one ASCII space. diff --git a/packages/e2e/tests/unit/step-cache.test.ts b/packages/e2e/tests/unit/step-cache.test.ts index 943713b7d3..6134e4da24 100644 --- a/packages/e2e/tests/unit/step-cache.test.ts +++ b/packages/e2e/tests/unit/step-cache.test.ts @@ -1395,7 +1395,7 @@ describe('cache.strict and a step whose key changed under its recording', () => } }); - describe.each(['testId', 'targetId', 'agent'] as const)('a %s longer than an entry keeps', (field) => { + describe.each(['testId', 'targetId', 'agent'] as const)('when the %s is longer than an entry keeps', (field) => { const long = 'checkout for a signed in customer with a saved card '.repeat(6); const stepWith = (value: string) => ({ ...exampleStep, [field]: value }); const sessionFor = (context: AgentCacheContext, step: typeof exampleStep) => @@ -1422,6 +1422,22 @@ describe('cache.strict and a step whose key changed under its recording', () => await expect(sessionFor(await rekeyedContext(recordedPayload(legacy)), step).begin()).resolves.toBeUndefined(); }); + it('runs live when its whole name reads like the cut an entry with no identity digest stored for another step', async () => { + const { identityDigest: _digest, ...legacy } = recordedProvenance(stepWith(`${long} first`), (text) => text); + const step = stepWith(legacy[field]!); + await expect(sessionFor(await rekeyedContext(recordedPayload(legacy)), step).begin()).resolves.toBeUndefined(); + }); + + it('fails with REPLAY_STALE when its whole name ends like a cut and its own recording sits under another key', async () => { + for (const length of [MAX_TRACE_DESCRIPTOR_CHARS - 1, MAX_TRACE_DESCRIPTOR_CHARS]) { + const step = stepWith(`${'x'.repeat(length - 1)}…`); + const stored = recordedProvenance(step, (text) => text); + expect(stored.identityDigest, String(length)).toMatch(/^[a-f0-9]{64}$/u); + const session = sessionFor(await rekeyedContext(recordedPayload(stored)), step); + await expect(session.begin(), String(length)).rejects.toMatchObject({ code: 'REPLAY_STALE' }); + } + }); + it(`fails with REPLAY_STALE at exactly ${MAX_TRACE_DESCRIPTOR_CHARS} characters, which an entry keeps whole`, async () => { const step = stepWith('x'.repeat(MAX_TRACE_DESCRIPTOR_CHARS)); const stored = recordedProvenance(step, (text) => text); diff --git a/packages/e2e/tests/unit/text.test.ts b/packages/e2e/tests/unit/text.test.ts index bd35f890cb..706f442775 100644 --- a/packages/e2e/tests/unit/text.test.ts +++ b/packages/e2e/tests/unit/text.test.ts @@ -1,6 +1,6 @@ import { runInNewContext } from 'node:vm'; import { describe, expect, it } from 'vitest'; -import { bound, compareText, matchesText, normalizeRegexpFlags, normalizeText, toTextPattern } from '@e2e-dev/core/lib/internal/text'; +import { bound, boundIsAmbiguous, compareText, matchesText, normalizeRegexpFlags, normalizeText, toTextPattern } from '@e2e-dev/core/lib/internal/text'; describe('normalizeText', () => { it('trims and collapses unicode whitespace runs to one ASCII space', () => { @@ -86,3 +86,14 @@ describe('bound', () => { expect(bound(`ab😀def`, 5)).toBe('ab😀…'); }); }); + +describe('boundIsAmbiguous', () => { + it('holds for text bound cuts and for text that ends like one of its cuts, and for nothing else', () => { + expect(boundIsAmbiguous('abcdef', 5)).toBe(true); + expect(boundIsAmbiguous('abcd…', 5)).toBe(true); + expect(boundIsAmbiguous('abc…', 5)).toBe(true); + expect(boundIsAmbiguous('abcde', 5)).toBe(false); + expect(boundIsAmbiguous('ab…', 5)).toBe(false); + expect(boundIsAmbiguous('loading…', 300)).toBe(false); + }); +}); diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index 04f1fc2139..827a9dfcf9 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -10,6 +10,7 @@ import { recordedProvenance } from '@e2e-dev/core/lib/cache/recorder'; import { FileCacheStore } from '@e2e-dev/core/lib/cache/store'; import { buildTraceEntry } from '@e2e-dev/core/lib/cache/trace'; import { readTraceEntry } from '@e2e-dev/core/lib/cache/trace-read'; +import { SecretLedger } from '@e2e-dev/core/lib/internal/redact'; import { resolveConfig } from '../../src/config/resolve-run.ts'; import type { ActionTrace, CacheStore } from '@e2e-dev/core/lib/types'; import type { E2EConfig } from '../../src/run-types.ts'; @@ -372,6 +373,17 @@ describe('settleStagedTraces', () => { expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload.recordedFor).toEqual(recordedFor); }); + it('takes the identity digest over the redacted names, so it never depends on a secret value', () => { + const long = `${STEP.testId}${'x'.repeat(400)}`; + const digestWith = (value: string) => { + const secrets = new SecretLedger(); + secrets.register('password', value); + return recordedProvenance({ ...STEP, testId: `${long} as ${value}` }, secrets.redact).identityDigest; + }; + expect(digestWith('hunter2')).toMatch(/^[a-f0-9]{64}$/u); + expect(digestWith('hunter2')).toBe(digestWith('swordfish')); + }); + it('refuses an entry whose identity digest is not a SHA-256 hex digest', () => { const entry = buildTraceEntry({ ...trace('recorded flow'), recordedFor: { ...STEP, identityDigest: 'not-a-digest' } }); expect(readTraceEntry(JSON.parse(JSON.stringify(entry)))).toBeUndefined(); From d6bb251a3d907dbec70cfaaa2a620155da8a6b7d Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Tue, 17 Nov 2026 11:33:21 +1030 Subject: [PATCH 03/11] docs(cache): measure the long-id row by the test id, and say where a name ends in an ellipsis The test id percent-encodes the titles, so the limit is reached well before 300 characters of title text. The row names the test id again. The digest JSDoc names the createAgent cache key as the source of a name that ends like a cut, and the provenance tests leave the settlement block. Co-Authored-By: Claude Opus 5.5 --- docs/cache.mdx | 2 +- packages/core/src/cache/rekeyed.ts | 5 +-- packages/core/src/cache/trace.ts | 5 +-- packages/core/src/internal/text.ts | 5 ++- .../e2e/tests/unit/trace-cache-config.test.ts | 34 ++++++++++--------- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/cache.mdx b/docs/cache.mdx index e7d982106d..a82168eff4 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -393,7 +393,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | -| | A step whose test file and titles, target name, or agent name come to over 300 characters, when its recording under another key was made by an earlier `e2e` version | +| | A step whose test id, target name, or agent name is over 300 characters, when its recording under another key was made by an earlier `e2e` version | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/packages/core/src/cache/rekeyed.ts b/packages/core/src/cache/rekeyed.ts index 909f69666e..5fdd25002d 100644 --- a/packages/core/src/cache/rekeyed.ts +++ b/packages/core/src/cache/rekeyed.ts @@ -87,8 +87,9 @@ export function storedRecordingsFor(cache: ResolvedCacheConfig): StoredRecording /** * The whole step as one map key, or undefined when the provenance does not - * record all of it. A step with a cut test id, target id, or agent name keys - * by its `identityDigest` too, so it never matches an entry that has none. + * record all of it. A step whose test id, target id, or agent name an entry + * could store cut keys by its `identityDigest` too, so it never matches an + * entry that has none. */ function stepKey(step: TraceProvenance): string | undefined { const { testId, targetId, instructionDigest, paramsDigest, callIndex, agent, identityDigest } = step; diff --git a/packages/core/src/cache/trace.ts b/packages/core/src/cache/trace.ts index 0a8fb47ffe..f744c17440 100644 --- a/packages/core/src/cache/trace.ts +++ b/packages/core/src/cache/trace.ts @@ -107,8 +107,9 @@ export interface TraceProvenance { readonly agent?: string; /** * SHA-256 of the whole redacted test id, target id, and agent name, only - * when one of them is longer than an entry keeps or ends like a cut: two - * steps whose stored text is the same never share the digest. + * when one of them is longer than an entry keeps or ends like a cut (a + * `createAgent` cache key can): two steps whose stored text is the same + * never share the digest. */ readonly identityDigest?: string; } diff --git a/packages/core/src/internal/text.ts b/packages/core/src/internal/text.ts index 125e77cd41..9c385ab307 100644 --- a/packages/core/src/internal/text.ts +++ b/packages/core/src/internal/text.ts @@ -17,7 +17,10 @@ export function bound(text: string, maxChars: number): string { return `${text.slice(0, end)}…`; } -/** Whether `bound(text, maxChars)` could equal what `bound` makes of a different text: it cuts `text`, or `text` already ends like a cut. */ +/** + * Whether `bound(text, maxChars)` could equal what `bound` makes of a + * different text: it cuts `text`, or `text` already ends like a cut. + */ export function boundIsAmbiguous(text: string, maxChars: number): boolean { return text.length > maxChars || (text.length >= maxChars - 1 && text.endsWith('…')); } diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index 827a9dfcf9..1d8aa98a1b 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -373,22 +373,6 @@ describe('settleStagedTraces', () => { expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload.recordedFor).toEqual(recordedFor); }); - it('takes the identity digest over the redacted names, so it never depends on a secret value', () => { - const long = `${STEP.testId}${'x'.repeat(400)}`; - const digestWith = (value: string) => { - const secrets = new SecretLedger(); - secrets.register('password', value); - return recordedProvenance({ ...STEP, testId: `${long} as ${value}` }, secrets.redact).identityDigest; - }; - expect(digestWith('hunter2')).toMatch(/^[a-f0-9]{64}$/u); - expect(digestWith('hunter2')).toBe(digestWith('swordfish')); - }); - - it('refuses an entry whose identity digest is not a SHA-256 hex digest', () => { - const entry = buildTraceEntry({ ...trace('recorded flow'), recordedFor: { ...STEP, identityDigest: 'not-a-digest' } }); - expect(readTraceEntry(JSON.parse(JSON.stringify(entry)))).toBeUndefined(); - }); - it('writes what was confirmed and leaves every unconfirmed entry as stored when the failure implicates nothing', async () => { const KEY_C = 'c'.repeat(64); const store = memoryStore(); @@ -430,3 +414,21 @@ describe('settleStagedTraces', () => { expect(other).not.toBe(first); }); }); + +describe('recorded provenance', () => { + it('takes the identity digest over the redacted names, so it never depends on a secret value', () => { + const long = `${STEP.testId}${'x'.repeat(400)}`; + const digestWith = (value: string) => { + const secrets = new SecretLedger(); + secrets.register('password', value); + return recordedProvenance({ ...STEP, testId: `${long} as ${value}` }, secrets.redact).identityDigest; + }; + expect(digestWith('hunter2')).toMatch(/^[a-f0-9]{64}$/u); + expect(digestWith('hunter2')).toBe(digestWith('swordfish')); + }); + + it('refuses an entry whose identity digest is not a SHA-256 hex digest', () => { + const entry = buildTraceEntry({ ...trace('recorded flow'), recordedFor: { ...STEP, identityDigest: 'not-a-digest' } }); + expect(readTraceEntry(JSON.parse(JSON.stringify(entry)))).toBeUndefined(); + }); +}); From aca807eee964dd9c44140de428f024ec5a5b8806 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Tue, 17 Nov 2026 15:16:26 +1030 Subject: [PATCH 04/11] test(cache): refuse an identity digest that is an array or a number RegExp#test stringifies its argument, so ['<64 hex>'] passes the hex pattern; the typeof check is what refuses it, and now a test pins it. Also rewords the stepKey JSDoc. Co-Authored-By: Claude Opus 5.5 --- packages/core/src/cache/rekeyed.ts | 5 ++--- packages/e2e/tests/unit/trace-cache-config.test.ts | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/cache/rekeyed.ts b/packages/core/src/cache/rekeyed.ts index 5fdd25002d..b8337f4d3c 100644 --- a/packages/core/src/cache/rekeyed.ts +++ b/packages/core/src/cache/rekeyed.ts @@ -87,9 +87,8 @@ export function storedRecordingsFor(cache: ResolvedCacheConfig): StoredRecording /** * The whole step as one map key, or undefined when the provenance does not - * record all of it. A step whose test id, target id, or agent name an entry - * could store cut keys by its `identityDigest` too, so it never matches an - * entry that has none. + * record all of it. When an entry could store a name cut, the key includes + * `identityDigest`, so such a step never matches an entry without one. */ function stepKey(step: TraceProvenance): string | undefined { const { testId, targetId, instructionDigest, paramsDigest, callIndex, agent, identityDigest } = step; diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index 1d8aa98a1b..ec8fd89e20 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -427,8 +427,9 @@ describe('recorded provenance', () => { expect(digestWith('hunter2')).toBe(digestWith('swordfish')); }); - it('refuses an entry whose identity digest is not a SHA-256 hex digest', () => { - const entry = buildTraceEntry({ ...trace('recorded flow'), recordedFor: { ...STEP, identityDigest: 'not-a-digest' } }); - expect(readTraceEntry(JSON.parse(JSON.stringify(entry)))).toBeUndefined(); + it.each([['not-a-digest'], [['a'.repeat(64)]], [42]])('refuses an entry whose identity digest is %j', (identityDigest) => { + const entry = JSON.parse(JSON.stringify(buildTraceEntry({ ...trace('recorded flow'), recordedFor: STEP }))); + entry.payload.recordedFor.identityDigest = identityDigest; + expect(readTraceEntry(entry)).toBeUndefined(); }); }); From e77e3e01082281f1541a7ce7485b6902edf3dfcf Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 13:13:31 +1030 Subject: [PATCH 05/11] fix(cache): pin the no-rewrite side of the identity digest backfill - Add a settleStagedTraces test: a confirmed kept entry that already keeps the step's identity digest gets no store write. - The StagedTrace JSDoc names the identity digest beside the occurrence fields. - The docs row no longer says "test id", which this page uses for the app's element test ids, and names the 299 or 300 characters ending in an ellipsis case. Co-Authored-By: Claude Opus 5.5 --- docs/cache.mdx | 2 +- packages/core/src/cache/context.ts | 5 +++-- .../e2e/tests/unit/trace-cache-config.test.ts | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/cache.mdx b/docs/cache.mdx index a82168eff4..f57e74c2fd 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -393,7 +393,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | -| | A step whose test id, target name, or agent name is over 300 characters, when its recording under another key was made by an earlier `e2e` version | +| | A step in a test with a very long title, or with a target or agent name over 300 characters (or of 299 or 300 characters ending in `…`), when its recording under another key was made by an earlier `e2e` version | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/packages/core/src/cache/context.ts b/packages/core/src/cache/context.ts index 0c56fbd1df..98727ed222 100644 --- a/packages/core/src/cache/context.ts +++ b/packages/core/src/cache/context.ts @@ -38,8 +38,9 @@ import type { JsonValue } from '../types.ts'; * (every `unique()` slot filled with this run's value) can never be written; * confirmed, the file keeps its bytes and `createdAt`, and a committed cache * directory stays clean, unless its provenance predates the step's - * occurrence fields (`recordedFor`, as stored), which the replay proved and - * are then written in. Unconfirmed, both kinds are evicted alike. + * occurrence fields or identity digest (`recordedFor`, as stored), which the + * replay proved and are then written in. Unconfirmed, both kinds are evicted + * alike. */ export type StagedTrace = { readonly keyHash: string; diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index ec8fd89e20..50becbb813 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -373,6 +373,27 @@ describe('settleStagedTraces', () => { expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload.recordedFor).toEqual(recordedFor); }); + it('leaves a confirmed kept entry that already keeps the step\'s identity digest exactly as stored', async () => { + const store = memoryStore(); + const recordedFor = recordedProvenance({ ...STEP, testId: `${STEP.testId}${'x'.repeat(400)}` }, (text) => text); + expect(recordedFor.identityDigest).toMatch(/^[a-f0-9]{64}$/u); + const stored = JSON.stringify(buildTraceEntry({ ...trace('replayed flow'), recordedFor })); + store.entries.set(KEY_A, stored); + const written: string[] = []; + const context = contextWith({ + ...store, + write: async (keyHash, payload) => { + written.push(keyHash); + return store.write(keyHash, payload); + }, + }); + context.staged.push({ kind: 'keep', keyHash: KEY_A, stepIndex: 1, recordedFor }); + const writes = await settleStagedTraces(context, { lastVerifiedStepIndex: 2, implicatesUnconfirmed: true }); + expect(written).toEqual([]); + expect(store.entries.get(KEY_A)).toBe(stored); + expect(writes.get(1)).toBe('kept'); + }); + it('writes what was confirmed and leaves every unconfirmed entry as stored when the failure implicates nothing', async () => { const KEY_C = 'c'.repeat(64); const store = memoryStore(); From 06b92ba5c0591e4caf707cb5a3fcab4be1bb4058 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 13:29:00 +1030 Subject: [PATCH 06/11] fix(cache): pin that ambiguity is measured on the redacted names - Test that a name a secret makes longer than an entry keeps gets an identity digest. - The docs row drops the ellipsis case: target and agent names are ASCII only, and runner test ids are percent-encoded, so neither can end in one. It says the test's file path and percent-encoded titles, and that a confirmed read-write replay ends the exception. - The identityDigest JSDoc names the secret-value case. - One isOptionalDigest check serves paramsDigest and identityDigest. Co-Authored-By: Claude Opus 5.5 --- docs/cache.mdx | 2 +- packages/core/src/cache/trace-read.ts | 9 +++++++-- packages/core/src/cache/trace.ts | 2 +- packages/e2e/tests/unit/trace-cache-config.test.ts | 12 ++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/cache.mdx b/docs/cache.mdx index f57e74c2fd..67bee70702 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -393,7 +393,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | -| | A step in a test with a very long title, or with a target or agent name over 300 characters (or of 299 or 300 characters ending in `…`), when its recording under another key was made by an earlier `e2e` version | +| | A step in a test whose file path and percent-encoded titles come to over 300 characters, or whose target or agent name is over 300 characters, when its recording under another key was made by an earlier `e2e` version and no read-write run has [confirmed](#when-a-recording-is-written) a replay of it since | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/packages/core/src/cache/trace-read.ts b/packages/core/src/cache/trace-read.ts index 8a22c66dbd..057a392187 100644 --- a/packages/core/src/cache/trace-read.ts +++ b/packages/core/src/cache/trace-read.ts @@ -408,6 +408,11 @@ function readPosition(document: unknown): TracePosition | undefined { return { index: index as number, of: of as number }; } +/** Whether a provenance field that may be absent is absent or a SHA-256 hex digest. */ +function isOptionalDigest(value: unknown): value is string | undefined { + return value === undefined || (typeof value === 'string' && SHA256_HEX.test(value)); +} + function readProvenance(document: unknown): TraceProvenance | undefined { if (typeof document !== 'object' || document === null || Array.isArray(document)) { return undefined; @@ -419,7 +424,7 @@ function readProvenance(document: unknown): TraceProvenance | undefined { if (testId === undefined || targetId === undefined) return undefined; if (typeof instructionDigest !== 'string' || !SHA256_HEX.test(instructionDigest)) return undefined; const paramsDigest = raw['paramsDigest']; - if (paramsDigest !== undefined && (typeof paramsDigest !== 'string' || !SHA256_HEX.test(paramsDigest))) return undefined; + if (!isOptionalDigest(paramsDigest)) return undefined; const callIndex = raw['callIndex']; if (callIndex !== undefined && (typeof callIndex !== 'number' || !Number.isSafeInteger(callIndex) || callIndex < 0)) { return undefined; @@ -427,7 +432,7 @@ function readProvenance(document: unknown): TraceProvenance | undefined { const agent = raw['agent'] === undefined ? undefined : readBoundedText(raw['agent'], MAX_TRACE_DESCRIPTOR_CHARS); if (raw['agent'] !== undefined && agent === undefined) return undefined; const identityDigest = raw['identityDigest']; - if (identityDigest !== undefined && (typeof identityDigest !== 'string' || !SHA256_HEX.test(identityDigest))) return undefined; + if (!isOptionalDigest(identityDigest)) return undefined; return { testId, targetId, diff --git a/packages/core/src/cache/trace.ts b/packages/core/src/cache/trace.ts index f744c17440..55b257074a 100644 --- a/packages/core/src/cache/trace.ts +++ b/packages/core/src/cache/trace.ts @@ -109,7 +109,7 @@ export interface TraceProvenance { * SHA-256 of the whole redacted test id, target id, and agent name, only * when one of them is longer than an entry keeps or ends like a cut (a * `createAgent` cache key can): two steps whose stored text is the same - * never share the digest. + * share the digest only when their names differ in a secret value alone. */ readonly identityDigest?: string; } diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index 50becbb813..bb859f55ed 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -448,6 +448,18 @@ describe('recorded provenance', () => { expect(digestWith('hunter2')).toBe(digestWith('swordfish')); }); + it('measures the redacted names, so a name a secret makes longer than an entry keeps gets a digest', () => { + const secrets = new SecretLedger(); + secrets.register('password', 'hunter2'); + const variant = (title: string) => recordedProvenance({ ...STEP, testId: `${'x'.repeat(280)} hunter2 ${title}` }, secrets.redact); + const [first, second] = [variant('first'), variant('second')]; + expect(`${'x'.repeat(280)} hunter2 second`.length).toBeLessThanOrEqual(300); + expect(first.testId).toBe(second.testId); + expect(first.identityDigest).toMatch(/^[a-f0-9]{64}$/u); + expect(second.identityDigest).toMatch(/^[a-f0-9]{64}$/u); + expect(first.identityDigest).not.toBe(second.identityDigest); + }); + it.each([['not-a-digest'], [['a'.repeat(64)]], [42]])('refuses an entry whose identity digest is %j', (identityDigest) => { const entry = JSON.parse(JSON.stringify(buildTraceEntry({ ...trace('recorded flow'), recordedFor: STEP }))); entry.payload.recordedFor.identityDigest = identityDigest; From 0f8c4599460cbef92541ce34ecd11c421ec7b789 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 13:48:40 +1030 Subject: [PATCH 07/11] test(cache): pin that the backfill replaces or drops a stale identity digest - A confirmed kept entry whose names redact differently now gets the step's new digest, and one whose names no longer need a digest drops it. - Shorten the docs row to the maintainer's wording. Co-Authored-By: Claude Opus 5.5 --- docs/cache.mdx | 2 +- .../e2e/tests/unit/trace-cache-config.test.ts | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/cache.mdx b/docs/cache.mdx index 67bee70702..9fa2cca216 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -393,7 +393,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | -| | A step in a test whose file path and percent-encoded titles come to over 300 characters, or whose target or agent name is over 300 characters, when its recording under another key was made by an earlier `e2e` version and no read-write run has [confirmed](#when-a-recording-is-written) a replay of it since | +| | A step in a test with a very long title, or with a target or agent name over 300 characters, when an earlier `e2e` version recorded it under another key and no read-write run has replayed it since | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index bb859f55ed..ed749fb83a 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -394,6 +394,34 @@ describe('settleStagedTraces', () => { expect(writes.get(1)).toBe('kept'); }); + it('replaces the identity digest of a confirmed kept entry whose names redact differently now', async () => { + const store = memoryStore(); + const step = { ...STEP, testId: `${STEP.testId}${'x'.repeat(400)} as hunter2` }; + store.entries.set(KEY_A, JSON.stringify(buildTraceEntry({ ...trace('replayed flow'), recordedFor: recordedProvenance(step, (text) => text) }))); + const secrets = new SecretLedger(); + secrets.register('password', 'hunter2'); + const recordedFor = recordedProvenance(step, secrets.redact); + const context = contextWith(store); + context.staged.push({ kind: 'keep', keyHash: KEY_A, stepIndex: 1, recordedFor }); + await settleStagedTraces(context, { lastVerifiedStepIndex: 2, implicatesUnconfirmed: true }); + expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload.recordedFor).toEqual(recordedFor); + }); + + it('drops the identity digest of a confirmed kept entry whose names no longer need one', async () => { + const store = memoryStore(); + const step = { ...STEP, testId: `${'x'.repeat(290)}hunter2` }; + const secrets = new SecretLedger(); + secrets.register('password', 'hunter2'); + const recorded = recordedProvenance(step, secrets.redact); + expect(recorded.identityDigest).toMatch(/^[a-f0-9]{64}$/u); + store.entries.set(KEY_A, JSON.stringify(buildTraceEntry({ ...trace('replayed flow'), recordedFor: recorded }))); + const recordedFor = recordedProvenance(step, (text) => text); + const context = contextWith(store); + context.staged.push({ kind: 'keep', keyHash: KEY_A, stepIndex: 1, recordedFor }); + await settleStagedTraces(context, { lastVerifiedStepIndex: 2, implicatesUnconfirmed: true }); + expect(readTraceEntry(JSON.parse(store.entries.get(KEY_A)!))?.payload.recordedFor?.identityDigest).toBeUndefined(); + }); + it('writes what was confirmed and leaves every unconfirmed entry as stored when the failure implicates nothing', async () => { const KEY_C = 'c'.repeat(64); const store = memoryStore(); From 6d3734131906ed6a9d0df4f9ba8bf469a472f7b7 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 14:04:58 +1030 Subject: [PATCH 08/11] docs(cache): say the backfill rewrites differing provenance, and translate the row - The StagedTrace, completeProvenance, and settleStagedTraces JSDoc say an entry is rewritten when its stored provenance differs from the step's, which now includes replacing or dropping a digest. - Test that an invalid paramsDigest is refused too, in a describe for reading entries. - Add the long-name row to the ja and zh cache tables. Co-Authored-By: Claude Opus 5.5 --- docs/ja/cache.mdx | 1 + docs/zh/cache.mdx | 1 + packages/core/src/cache/context.ts | 15 ++++++++------- packages/e2e/tests/unit/step-cache.test.ts | 2 +- .../e2e/tests/unit/trace-cache-config.test.ts | 13 +++++++++++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/ja/cache.mdx b/docs/ja/cache.mdx index b774051d1d..13450681c7 100644 --- a/docs/ja/cache.mdx +++ b/docs/ja/cache.mdx @@ -254,6 +254,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`、`wrong-context`、`target-not-found`、`target-ambiguous`、`viewport-changed`、`action-failed`、`action-uncertain`、`end-mismatch`: アプリまたはエントリーが変わった | 一度も記録されていないステップ(新規または編集済みの指示やパラメーター) | | `no-entry`: キャッシュディレクトリに同じステップの記録が別のキーで存在する場合 | `gap` または `truncated` の記録 | | | ストアの読み取りが失敗したステップ | +| | タイトルが非常に長いテスト、またはターゲット名かエージェント名が 300 文字を超えるステップで、以前の `e2e` バージョンが別のキーで記録し、その後 `read-write` の実行で再生されていないもの | 別のキーの記録は、キーを変える `e2e` のアップグレード、プロジェクト ID、アプリの識別情報、エージェントのコンテキストの変更などで生じます。メッセージにはそのファイルと、現行バージョンで作られた記録なら変更点も示されます。何も再生しなくなったファイルは削除してください。この検査は、独自の `cache.store` には適用されません。 diff --git a/docs/zh/cache.mdx b/docs/zh/cache.mdx index 2942acd6ec..ff888ecfc8 100644 --- a/docs/zh/cache.mdx +++ b/docs/zh/cache.mdx @@ -254,6 +254,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`、`wrong-context`、`target-not-found`、`target-ambiguous`、`viewport-changed`、`action-failed`、`action-uncertain`、`end-mismatch`:应用或条目发生了变化 | 从未录制过的步骤(新建或编辑过的指令或参数) | | `no-entry`,且缓存目录中存在使用其他键的同一步骤录制记录 | `gap` 或 `truncated` 录制记录 | | | 从存储读取失败的步骤 | +| | 标题很长的测试中的步骤,或目标名称、智能体名称超过 300 个字符的步骤,且其录制记录由较早的 `e2e` 版本以其他键生成,之后也没有 `read-write` 运行回放过它 | 其他键下的录制记录可能来自改变键的 `e2e` 升级,也可能来自项目 ID、应用标识或智能体上下文的变化。消息会指出该文件;如果记录由当前版本生成,还会说明变化内容。如果已无回放使用该文件,请删除它。此检查不涵盖自定义 `cache.store`。 diff --git a/packages/core/src/cache/context.ts b/packages/core/src/cache/context.ts index 98727ed222..cc88f622c9 100644 --- a/packages/core/src/cache/context.ts +++ b/packages/core/src/cache/context.ts @@ -37,8 +37,8 @@ import type { JsonValue } from '../types.ts'; * stands. A kept entry carries no payload, so the replay's expansion of it * (every `unique()` slot filled with this run's value) can never be written; * confirmed, the file keeps its bytes and `createdAt`, and a committed cache - * directory stays clean, unless its provenance predates the step's - * occurrence fields or identity digest (`recordedFor`, as stored), which the + * directory stays clean, unless its stored provenance (`recordedFor`) differs + * from the step's in the occurrence fields or the identity digest, which the * replay proved and are then written in. Unconfirmed, both kinds are evicted * alike. */ @@ -141,10 +141,10 @@ function flowOf(trace: ActionTrace): string { } /** - * Writes the step's full provenance into a kept entry recorded before the - * occurrence fields or the identity digest were, leaving every other entry - * untouched. Its replay proved which step it belongs to, and `cache.strict` - * matches only entries that say so exactly (`rekeyed.ts`). + * Writes the step's full provenance into a kept entry whose stored provenance + * lacks the occurrence fields or holds another identity digest, leaving every + * other entry untouched. Its replay proved which step it belongs to, and + * `cache.strict` matches only entries that say so exactly (`rekeyed.ts`). */ async function completeProvenance(store: CacheStore, keyHash: string, recordedFor: TraceProvenance): Promise { const existing = await store.read(keyHash); @@ -203,7 +203,8 @@ export interface SurvivedFailure { * no settlement: interruption implicates nothing, so it writes nothing and * evicts nothing. An entry a step replayed whole is staged too, * so the same rule evicts it when nothing confirmed it; when something did, - * it is left exactly as it was found, but for provenance it lacked. + * it is left exactly as it was found, but for provenance that differs from + * the step's (`completeProvenance`). */ export async function settleStagedTraces(context: AgentCacheContext, settlement: AttemptSettlement | undefined): Promise> { const outcomes = new Map(); diff --git a/packages/e2e/tests/unit/step-cache.test.ts b/packages/e2e/tests/unit/step-cache.test.ts index 6134e4da24..17681832f9 100644 --- a/packages/e2e/tests/unit/step-cache.test.ts +++ b/packages/e2e/tests/unit/step-cache.test.ts @@ -1422,7 +1422,7 @@ describe('cache.strict and a step whose key changed under its recording', () => await expect(sessionFor(await rekeyedContext(recordedPayload(legacy)), step).begin()).resolves.toBeUndefined(); }); - it('runs live when its whole name reads like the cut an entry with no identity digest stored for another step', async () => { + it('runs live when its whole name equals the cut name of another step, stored without an identity digest', async () => { const { identityDigest: _digest, ...legacy } = recordedProvenance(stepWith(`${long} first`), (text) => text); const step = stepWith(legacy[field]!); await expect(sessionFor(await rekeyedContext(recordedPayload(legacy)), step).begin()).resolves.toBeUndefined(); diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index ed749fb83a..40d6913983 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -488,9 +488,18 @@ describe('recorded provenance', () => { expect(first.identityDigest).not.toBe(second.identityDigest); }); - it.each([['not-a-digest'], [['a'.repeat(64)]], [42]])('refuses an entry whose identity digest is %j', (identityDigest) => { +}); + +describe('reading recorded provenance', () => { + it.each([ + ['paramsDigest', 'not-a-digest'], + ['paramsDigest', 42], + ['identityDigest', 'not-a-digest'], + ['identityDigest', ['a'.repeat(64)]], + ['identityDigest', 42], + ])('refuses an entry whose %s is %j', (field, digest) => { const entry = JSON.parse(JSON.stringify(buildTraceEntry({ ...trace('recorded flow'), recordedFor: STEP }))); - entry.payload.recordedFor.identityDigest = identityDigest; + entry.payload.recordedFor[field] = digest; expect(readTraceEntry(entry)).toBeUndefined(); }); }); From e6a69cfa6cfbbf9d7b17fe2814c0457a72588d25 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 14:21:02 +1030 Subject: [PATCH 09/11] test(cache): pin that target and agent names are stored and digested redacted - Test both fields with a registered secret: the stored name holds no secret value, and the digest is the same for two values. - The StagedTrace and settleStagedTraces JSDoc point at completeProvenance instead of restating when it rewrites an entry. Co-Authored-By: Claude Opus 5.5 --- packages/core/src/cache/context.ts | 10 ++++------ packages/e2e/tests/unit/trace-cache-config.test.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/core/src/cache/context.ts b/packages/core/src/cache/context.ts index cc88f622c9..a8153d3ba8 100644 --- a/packages/core/src/cache/context.ts +++ b/packages/core/src/cache/context.ts @@ -37,10 +37,8 @@ import type { JsonValue } from '../types.ts'; * stands. A kept entry carries no payload, so the replay's expansion of it * (every `unique()` slot filled with this run's value) can never be written; * confirmed, the file keeps its bytes and `createdAt`, and a committed cache - * directory stays clean, unless its stored provenance (`recordedFor`) differs - * from the step's in the occurrence fields or the identity digest, which the - * replay proved and are then written in. Unconfirmed, both kinds are evicted - * alike. + * directory stays clean, but for the provenance the replay proved, which + * `completeProvenance` writes in. Unconfirmed, both kinds are evicted alike. */ export type StagedTrace = { readonly keyHash: string; @@ -203,8 +201,8 @@ export interface SurvivedFailure { * no settlement: interruption implicates nothing, so it writes nothing and * evicts nothing. An entry a step replayed whole is staged too, * so the same rule evicts it when nothing confirmed it; when something did, - * it is left exactly as it was found, but for provenance that differs from - * the step's (`completeProvenance`). + * it is left exactly as it was found, but for what `completeProvenance` + * writes in. */ export async function settleStagedTraces(context: AgentCacheContext, settlement: AttemptSettlement | undefined): Promise> { const outcomes = new Map(); diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index 40d6913983..58c2848c82 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -476,6 +476,17 @@ describe('recorded provenance', () => { expect(digestWith('hunter2')).toBe(digestWith('swordfish')); }); + it.each(['targetId', 'agent'] as const)('stores the %s redacted and takes the digest over it redacted', (field) => { + const recorded = (value: string) => { + const secrets = new SecretLedger(); + secrets.register('password', value); + return recordedProvenance({ ...STEP, testId: `${STEP.testId}${'x'.repeat(400)}`, [field]: `staging-${value}` }, secrets.redact); + }; + expect(recorded('hunter2')[field]).not.toContain('hunter2'); + expect(recorded('hunter2').identityDigest).toMatch(/^[a-f0-9]{64}$/u); + expect(recorded('hunter2').identityDigest).toBe(recorded('swordfish').identityDigest); + }); + it('measures the redacted names, so a name a secret makes longer than an entry keeps gets a digest', () => { const secrets = new SecretLedger(); secrets.register('password', 'hunter2'); From 849ebf9b379694d8687806024ce9af02bffeb110 Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 14:31:48 +1030 Subject: [PATCH 10/11] docs(cache): name each identity digest case completeProvenance rewrites Co-Authored-By: Claude Opus 5.5 --- packages/core/src/cache/context.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/cache/context.ts b/packages/core/src/cache/context.ts index a8153d3ba8..31d3ea9386 100644 --- a/packages/core/src/cache/context.ts +++ b/packages/core/src/cache/context.ts @@ -140,9 +140,11 @@ function flowOf(trace: ActionTrace): string { /** * Writes the step's full provenance into a kept entry whose stored provenance - * lacks the occurrence fields or holds another identity digest, leaving every - * other entry untouched. Its replay proved which step it belongs to, and - * `cache.strict` matches only entries that say so exactly (`rekeyed.ts`). + * lacks the occurrence fields, or whose identity digest is not the step's: + * missing while the step has one, different, or present while the step has + * none. Every other entry is left untouched. Its replay proved which step it + * belongs to, and `cache.strict` matches only entries that say so exactly + * (`rekeyed.ts`). */ async function completeProvenance(store: CacheStore, keyHash: string, recordedFor: TraceProvenance): Promise { const existing = await store.read(keyHash); From 275d93aacc4b9ddb4d0ac0b345f3af44c5ea515d Mon Sep 17 00:00:00 2001 From: Samanyu Das Date: Wed, 18 Nov 2026 14:46:19 +1030 Subject: [PATCH 11/11] docs(cache): measure the long-name row by the testId in report.json - A title is percent-encoded into the test id, so a 34-character Japanese title already passes 300 characters. Name the `testId` field users can see instead of "a very long title". - Only a read-write run of this version writes the digest in, so say so. - Drop a test assertion on a constant, and a stray blank line. Co-Authored-By: Claude Opus 5.5 --- docs/cache.mdx | 2 +- docs/ja/cache.mdx | 2 +- docs/zh/cache.mdx | 2 +- packages/e2e/tests/unit/trace-cache-config.test.ts | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/cache.mdx b/docs/cache.mdx index ca3c880443..4a64450cb0 100644 --- a/docs/cache.mdx +++ b/docs/cache.mdx @@ -394,7 +394,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`, `wrong-context`, `target-not-found`, `target-ambiguous`, `viewport-changed`, `action-failed`, `action-uncertain`, `end-mismatch`: the app or the entry changed | A step never recorded (a new or edited instruction or params) | | `no-entry`, when the cache directory holds a recording of the same step under another key | A `gap` or a `truncated` recording | | | A step whose store read fails | -| | A step in a test with a very long title, or with a target or agent name over 300 characters, when an earlier `e2e` version recorded it under another key and no read-write run has replayed it since | +| | A step whose test's `testId` in `report.json`, target name, or agent name is over 300 characters, when an earlier `e2e` version recorded it under another key and no `read-write` run of this version has replayed it since | A recording under another key comes from an `e2e` upgrade that changed the keys, or a change to the project id, the app's identity, or the agent's diff --git a/docs/ja/cache.mdx b/docs/ja/cache.mdx index 13450681c7..fded905be1 100644 --- a/docs/ja/cache.mdx +++ b/docs/ja/cache.mdx @@ -254,7 +254,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`、`wrong-context`、`target-not-found`、`target-ambiguous`、`viewport-changed`、`action-failed`、`action-uncertain`、`end-mismatch`: アプリまたはエントリーが変わった | 一度も記録されていないステップ(新規または編集済みの指示やパラメーター) | | `no-entry`: キャッシュディレクトリに同じステップの記録が別のキーで存在する場合 | `gap` または `truncated` の記録 | | | ストアの読み取りが失敗したステップ | -| | タイトルが非常に長いテスト、またはターゲット名かエージェント名が 300 文字を超えるステップで、以前の `e2e` バージョンが別のキーで記録し、その後 `read-write` の実行で再生されていないもの | +| | テストの `report.json` の `testId`、ターゲット名、エージェント名のいずれかが 300 文字を超えるステップで、以前の `e2e` バージョンが別のキーで記録し、その後このバージョンの `read-write` の実行で再生されていないもの | 別のキーの記録は、キーを変える `e2e` のアップグレード、プロジェクト ID、アプリの識別情報、エージェントのコンテキストの変更などで生じます。メッセージにはそのファイルと、現行バージョンで作られた記録なら変更点も示されます。何も再生しなくなったファイルは削除してください。この検査は、独自の `cache.store` には適用されません。 diff --git a/docs/zh/cache.mdx b/docs/zh/cache.mdx index ff888ecfc8..ba017fd000 100644 --- a/docs/zh/cache.mdx +++ b/docs/zh/cache.mdx @@ -254,7 +254,7 @@ CI=1 bunx e2e run --strict-cache | `invalid-entry`、`wrong-context`、`target-not-found`、`target-ambiguous`、`viewport-changed`、`action-failed`、`action-uncertain`、`end-mismatch`:应用或条目发生了变化 | 从未录制过的步骤(新建或编辑过的指令或参数) | | `no-entry`,且缓存目录中存在使用其他键的同一步骤录制记录 | `gap` 或 `truncated` 录制记录 | | | 从存储读取失败的步骤 | -| | 标题很长的测试中的步骤,或目标名称、智能体名称超过 300 个字符的步骤,且其录制记录由较早的 `e2e` 版本以其他键生成,之后也没有 `read-write` 运行回放过它 | +| | 测试在 `report.json` 中的 `testId`、目标名称或智能体名称超过 300 个字符的步骤,且其录制记录由较早的 `e2e` 版本以其他键生成,之后也没有此版本的 `read-write` 运行回放过它 | 其他键下的录制记录可能来自改变键的 `e2e` 升级,也可能来自项目 ID、应用标识或智能体上下文的变化。消息会指出该文件;如果记录由当前版本生成,还会说明变化内容。如果已无回放使用该文件,请删除它。此检查不涵盖自定义 `cache.store`。 diff --git a/packages/e2e/tests/unit/trace-cache-config.test.ts b/packages/e2e/tests/unit/trace-cache-config.test.ts index 58c2848c82..84236461f7 100644 --- a/packages/e2e/tests/unit/trace-cache-config.test.ts +++ b/packages/e2e/tests/unit/trace-cache-config.test.ts @@ -490,15 +490,14 @@ describe('recorded provenance', () => { it('measures the redacted names, so a name a secret makes longer than an entry keeps gets a digest', () => { const secrets = new SecretLedger(); secrets.register('password', 'hunter2'); + // Under 300 characters as written, over 300 once `hunter2` is redacted. const variant = (title: string) => recordedProvenance({ ...STEP, testId: `${'x'.repeat(280)} hunter2 ${title}` }, secrets.redact); const [first, second] = [variant('first'), variant('second')]; - expect(`${'x'.repeat(280)} hunter2 second`.length).toBeLessThanOrEqual(300); expect(first.testId).toBe(second.testId); expect(first.identityDigest).toMatch(/^[a-f0-9]{64}$/u); expect(second.identityDigest).toMatch(/^[a-f0-9]{64}$/u); expect(first.identityDigest).not.toBe(second.identityDigest); }); - }); describe('reading recorded provenance', () => {