Skip to content

Commit 1143254

Browse files
committed
improvement(provenance): fold the incomplete-envelope predicate and pin dual-site reporting
Review pass over the previous commit: one helper instead of three copies of the incomplete-envelope check, the staged TSDoc generalized to cover both of its uses, and the block-outputs entry point's two-site reporting of one run envelope documented and pinned rather than left implicit.
1 parent e529adc commit 1143254

3 files changed

Lines changed: 50 additions & 12 deletions

File tree

apps/sim/executor/utils/resolved-secret-trace-registry.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,10 @@ export class ResolvedSecretTraceRegistry {
880880
private readonly scope?: ResolvedSecretTraceScopeV1
881881
private readonly completeProvenanceEnvelopeBytes: number
882882
/**
883-
* A staged registry filters one value and is then discarded. Its caller re-reports whatever
884-
* fault it hits against the real input path, so its own summary lines would restate that with
885-
* strictly less context. Entry-level detail still logs — the caller cannot reconstruct it.
883+
* A staged registry filters values for one operation and is then discarded. Its caller owns the
884+
* reporting and says it with strictly more context — the real input path for a value filter, the
885+
* execution for a display read — so the registry's own summary lines would only restate it.
886+
* Entry-level detail still logs — the caller cannot reconstruct it.
886887
*/
887888
private readonly staged: boolean
888889

apps/sim/lib/logs/execution/trace-store.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,33 @@ describe('stored provenance display reporting', () => {
643643
expect(mockLogger.error).not.toHaveBeenCalled()
644644
})
645645

646+
/** The block entry point runs both display functions; each names its own site for the envelope. */
647+
it('attributes an incomplete run envelope under both sites on a block-outputs read', async () => {
648+
await materializeExecutionDataForDisplayWithBlockOutputs(
649+
{
650+
finalOutput: { result: 'value' },
651+
executionState: {
652+
resolvedSecretTraceProvenance: { version: 1, complete: false, entries: [] },
653+
blockStates: {
654+
'block-1': { output: { value: 1 } },
655+
},
656+
},
657+
},
658+
CONTEXT,
659+
['block-1']
660+
)
661+
662+
expect(registrySummaryLines()).toHaveLength(0)
663+
expect(mockLogger.warn).toHaveBeenCalledWith(
664+
'Stored execution provenance cannot vouch for display content',
665+
expect.objectContaining({ site: 'traceStore.displayProjection', parts: ['traceSpans'] })
666+
)
667+
expect(mockLogger.warn).toHaveBeenCalledWith(
668+
'Stored execution provenance cannot vouch for display content',
669+
expect.objectContaining({ site: 'traceStore.blockOutputs', parts: ['run'] })
670+
)
671+
})
672+
646673
it('reports incomplete block-output envelopes once for the whole block read', async () => {
647674
const result = await materializeExecutionDataForDisplayWithBlockOutputs(
648675
{

apps/sim/lib/logs/execution/trace-store.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export async function materializeExecutionDataForDisplayWithBlockOutputs(
307307
'traceStore.blockOutputRunProvenance'
308308
)
309309
const provenanceFaults = new Map<string, StoredDisplayProvenanceFault>()
310-
if (isResolvedSecretTraceProvenanceV1(runProvenance) && !runProvenance.complete) {
310+
if (isIncompleteStoredEnvelope(runProvenance)) {
311311
provenanceFaults.set('run', 'incomplete')
312312
}
313313
const blockOutputs = new Map<string, unknown>()
@@ -318,11 +318,11 @@ export async function materializeExecutionDataForDisplayWithBlockOutputs(
318318
if (!blockState || blockState.output === undefined) continue
319319

320320
const hasExactProvenance = Object.hasOwn(blockState, RESOLVED_SECRET_PROVENANCE_KEY)
321-
if (hasExactProvenance) {
322-
const blockProvenance = blockState[RESOLVED_SECRET_PROVENANCE_KEY]
323-
if (isResolvedSecretTraceProvenanceV1(blockProvenance) && !blockProvenance.complete) {
324-
provenanceFaults.set(`blockOutput:${blockId}`, 'incomplete')
325-
}
321+
if (
322+
hasExactProvenance &&
323+
isIncompleteStoredEnvelope(blockState[RESOLVED_SECRET_PROVENANCE_KEY])
324+
) {
325+
provenanceFaults.set(`blockOutput:${blockId}`, 'incomplete')
326326
}
327327
const registry = hasExactProvenance
328328
? await importResolvedSecretTraceRegistry(
@@ -377,17 +377,27 @@ async function importResolvedSecretTraceRegistry(
377377

378378
type StoredDisplayProvenanceFault = 'incomplete' | 'malformed'
379379

380+
/** True for a stored envelope that parses but cannot vouch for the value it accompanies. */
381+
function isIncompleteStoredEnvelope(value: unknown): boolean {
382+
return isResolvedSecretTraceProvenanceV1(value) && !value.complete
383+
}
384+
380385
const MAX_REPORTED_PROVENANCE_FAULT_PARTS = 20
381386

382387
/**
383-
* One attributed line per display materialization, in place of one registry summary per envelope
384-
* per view.
388+
* One attributed line per display function per materialization, in place of one registry summary
389+
* per envelope per view.
385390
*
386391
* The registry summaries these replace carried counts and a workspace but no execution id, so a
387392
* reader repeatedly materializing the same stored rows produced an unattributable stream — the
388393
* lines could not say which executions to go look at. Incomplete stays at warn (a stored state
389394
* being re-read); malformed stays at error (a stored envelope that cannot be parsed is a fault
390395
* wherever it is met, matching the level its registry reason carries elsewhere).
396+
*
397+
* A block-outputs read runs the display projection first, so an incomplete run envelope appears
398+
* once under each site — `traceSpans` guarding the span projection, `run` as the block fallback.
399+
* Two sites reading the same envelope are two facts about the view; collapsing them would couple
400+
* the display functions to share reporting state for one line less.
391401
*/
392402
function reportStoredDisplayProvenanceFaults(
393403
site: string,
@@ -489,7 +499,7 @@ export async function projectExecutionDataForDisplay(
489499
const projectionStore = createReadOnlyProjectionStore(context)
490500

491501
const provenanceFaults = new Map<string, StoredDisplayProvenanceFault>()
492-
if (isResolvedSecretTraceProvenanceV1(provenance) && !provenance.complete) {
502+
if (isIncompleteStoredEnvelope(provenance)) {
493503
provenanceFaults.set('traceSpans', 'incomplete')
494504
}
495505

0 commit comments

Comments
 (0)