Skip to content

Commit a49e535

Browse files
committed
address comments
1 parent 3f19076 commit a49e535

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

apps/sim/app/api/knowledge/utils.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ describe('Knowledge Utils', () => {
259259
{}
260260
)
261261

262-
expect(dbOps.order).toEqual(['insert', 'updateDoc'])
262+
// Embeddings are inserted first, then the document counter update. A
263+
// usage_log billing insert (recordUsage) may trail after updateDoc and is
264+
// irrelevant to this ordering invariant, so assert position rather than
265+
// exact array equality.
266+
expect(dbOps.order[0]).toBe('insert')
267+
expect(dbOps.order.indexOf('updateDoc')).toBeGreaterThan(0)
263268

264269
expect(dbOps.updatePayloads[0]).toMatchObject({
265270
processingStatus: 'completed',

apps/sim/lib/data-drains/sources/workflow-logs.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ async function* pages(input: SourcePageInput): AsyncIterable<WorkflowLogRow[]> {
5050

5151
// Heavy execution data may live in object storage; resolve pointers (bounded
5252
// concurrency) so the drain exports full execution data, not the slim row.
53-
await mapWithConcurrency(rows, MATERIALIZE_CONCURRENCY, async (row) => {
54-
row.executionData = (await materializeExecutionData(
55-
row.executionData as Record<string, unknown> | null,
56-
{ workspaceId: row.workspaceId, workflowId: row.workflowId, executionId: row.executionId }
57-
)) as WorkflowLogRow['executionData']
58-
})
53+
// Use the order-preserving returned array (the util's documented contract)
54+
// and write back, rather than mutating rows inside the mapper.
55+
const materialized = await mapWithConcurrency(rows, MATERIALIZE_CONCURRENCY, (row) =>
56+
materializeExecutionData(row.executionData as Record<string, unknown> | null, {
57+
workspaceId: row.workspaceId,
58+
workflowId: row.workflowId,
59+
executionId: row.executionId,
60+
})
61+
)
62+
for (let i = 0; i < rows.length; i++) {
63+
rows[i].executionData = materialized[i] as WorkflowLogRow['executionData']
64+
}
5965

6066
yield rows
6167
const last = rows[rows.length - 1]

apps/sim/lib/logs/execution/logging-session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ export class LoggingSession {
460460
totalCompletionTokens: 0,
461461
baseExecutionCharge: 0,
462462
models: {},
463+
charges: {},
463464
}
464465
: calculateCostSummary(traceSpans)
465466

0 commit comments

Comments
 (0)