Skip to content

Commit 27afbce

Browse files
committed
chore(logs): convert inline marker comments to TSDoc
1 parent f4d8086 commit 27afbce

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@ export class LoggingSession {
193193
}
194194
}
195195

196+
/**
197+
* Persist the last-started-block marker. Redis is the primary path when the
198+
* flag is on; falls back to the durable jsonb_set UPDATE when Redis is
199+
* unavailable or the write fails, so a marker is never dropped.
200+
*/
196201
private async persistLastStartedBlock(marker: ExecutionLastStartedBlock): Promise<void> {
197-
// Redis is the primary path when enabled; fall back to the durable SQL write
198-
// when Redis is unavailable or the write fails, so a marker is never dropped.
199202
if (this.useRedisMarkers && (await setLastStartedBlock(this.executionId, marker))) {
200203
return
201204
}
@@ -216,9 +219,12 @@ export class LoggingSession {
216219
}
217220
}
218221

222+
/**
223+
* Persist the last-completed-block marker. Redis is the primary path when the
224+
* flag is on; falls back to the durable jsonb_set UPDATE when Redis is
225+
* unavailable or the write fails, so a marker is never dropped.
226+
*/
219227
private async persistLastCompletedBlock(marker: ExecutionLastCompletedBlock): Promise<void> {
220-
// Redis is the primary path when enabled; fall back to the durable SQL write
221-
// when Redis is unavailable or the write fails, so a marker is never dropped.
222228
if (this.useRedisMarkers && (await setLastCompletedBlock(this.executionId, marker))) {
223229
return
224230
}
@@ -1022,6 +1028,13 @@ export class LoggingSession {
10221028
)
10231029
}
10241030

1031+
/**
1032+
* Force-fail terminal boundary that bypasses completeWorkflowExecution. Folds
1033+
* any live Redis progress markers into execution_data before clearing the key,
1034+
* so a run whose markers only ever lived in Redis still keeps its
1035+
* last-started/last-completed breadcrumb. Both the fold and clear are no-ops
1036+
* when the standard completion path already persisted and cleared them.
1037+
*/
10251038
static async markExecutionAsFailed(
10261039
executionId: string,
10271040
errorMessage: string | undefined,
@@ -1031,11 +1044,6 @@ export class LoggingSession {
10311044
try {
10321045
const message = errorMessage || 'Run failed'
10331046

1034-
// This terminal boundary bypasses completeWorkflowExecution, so fold any
1035-
// live Redis markers into the row here too — otherwise a run whose markers
1036-
// only ever lived in Redis would be saved with error data but no
1037-
// last-started/last-completed breadcrumb. Empty when the standard
1038-
// completion path already folded and cleared them.
10391047
const markers = await getProgressMarkers(executionId)
10401048

10411049
let executionData = sql`jsonb_set(
@@ -1068,8 +1076,6 @@ export class LoggingSession {
10681076
)
10691077
)
10701078

1071-
// Markers are now durable on the row; drop the Redis key to match the
1072-
// standard clear-at-every-boundary invariant.
10731079
void clearProgressMarkers(executionId)
10741080

10751081
logger.info(`[${requestId || 'unknown'}] Marked execution ${executionId} as failed`)

apps/sim/lib/logs/execution/progress-markers.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ describe('progress-markers', () => {
6161
await setLastStartedBlock(EXECUTION_ID, startedMarker)
6262

6363
expect(mockRedis.eval).toHaveBeenCalledTimes(1)
64-
const args = mockRedis.eval.mock.calls[0]
65-
// [script, numKeys, key, field, tsField, timestamp, json, ttl]
66-
expect(args[1]).toBe(1)
67-
expect(args[2]).toBe(KEY)
68-
expect(args[3]).toBe('started')
69-
expect(args[4]).toBe('startedAt')
70-
expect(args[5]).toBe(startedMarker.startedAt)
71-
expect(JSON.parse(args[6] as string)).toEqual(startedMarker)
72-
expect(args[7]).toBe(EXPECTED_TTL_MS)
64+
const [, numKeys, key, field, timestampField, timestamp, json, ttl] =
65+
mockRedis.eval.mock.calls[0]
66+
expect(numKeys).toBe(1)
67+
expect(key).toBe(KEY)
68+
expect(field).toBe('started')
69+
expect(timestampField).toBe('startedAt')
70+
expect(timestamp).toBe(startedMarker.startedAt)
71+
expect(JSON.parse(json as string)).toEqual(startedMarker)
72+
expect(ttl).toBe(EXPECTED_TTL_MS)
7373
})
7474

7575
it('returns true when the Redis write succeeds', async () => {

apps/sim/lib/logs/fetch-log-detail.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ interface FetchLogDetailArgs {
7878
* Shared loader for the workflow-log detail shape returned by the by-id and
7979
* by-execution routes. Returns `null` when no matching row exists in either
8080
* the workflow-execution or job-execution tables for this user + workspace.
81+
*
82+
* For in-flight (running/pending) executions, live progress markers are merged
83+
* from Redis, since they are only folded into the row at a terminal/pause
84+
* boundary.
8185
*/
8286
export async function fetchLogDetail({
8387
userId,
@@ -166,7 +170,6 @@ export async function fetchLogDetail({
166170
{ workspaceId, workflowId: log.workflowId, executionId: log.executionId }
167171
)
168172

169-
// In-flight markers live in Redis until folded into the row at a terminal/pause boundary.
170173
const liveMarkers =
171174
log.status === 'running' || log.status === 'pending'
172175
? await getProgressMarkers(log.executionId)

0 commit comments

Comments
 (0)