Skip to content

Commit 7e0d868

Browse files
authored
fix: surface an unbilled run, and clamp the google-docs page cap (#7025)
Two places where a failure is reported as something smaller than it is. **A run that is never billed logs as a notification problem.** The usage safety net re-records billing when an earlier step threw before the single record call, and its own failure went into a bare `catch {}`. With a degraded database the user lookup throws first, the re-record hits the same database and is swallowed, and the only line emitted reads "Usage threshold notification check failed (non-fatal)" — which is true of the outer failure and badly wrong about the inner one. It now logs at error with the execution and workflow ids, and says the run may be unbilled. The outer warn still covers the email path it was written for. **google-docs can ask Drive for a negative page.** `remaining` was `maxDocs - previouslyFetched` unclamped, where its google-slides twin carries `Math.max(0, …)` under the comment "Last-page precision". Both then run `if (documents.length > remaining) documents = documents.slice(0, remaining)`, and a negative `remaining` makes that guard true for any non-empty page while `slice` counts from the end — keeping the leading documents and dropping the trailing ones, where the cap says to keep none. Reachable when `maxDocs` is lowered while a sync cursor persists. google-drive guards the same case with an early return; google-docs had neither.
1 parent 0cbff0e commit 7e0d868

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

apps/sim/connectors/google-docs/google-docs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ export const googleDocsConnector: ConnectorConfig = {
304304

305305
const maxDocs = sourceConfig.maxDocs ? Number(sourceConfig.maxDocs) : 0
306306
const previouslyFetched = (syncContext?.totalDocsFetched as number) ?? 0
307-
const remaining = maxDocs > 0 ? maxDocs - previouslyFetched : 0
307+
/** Last-page precision: never ask Drive for more files than the cap still allows. */
308+
const remaining = maxDocs > 0 ? Math.max(0, maxDocs - previouslyFetched) : 0
308309
const pageSize = remaining > 0 ? Math.min(PAGE_SIZE, remaining) : PAGE_SIZE
309310

310311
/**

apps/sim/lib/logs/execution/logger.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,16 @@ export class ExecutionLogger implements IExecutionLoggerService {
13991399
actorUserId,
14001400
exactBillingContext
14011401
)
1402-
} catch {}
1402+
} catch (recordError) {
1403+
/* The safety net is the last thing between a completed run and an unbilled
1404+
one. Swallowing it left the only emitted line saying a notification check
1405+
had failed and was non-fatal. */
1406+
execLog.error('Failed to record execution usage — this run may be unbilled', {
1407+
error: recordError,
1408+
executionId,
1409+
workflowId: updatedLog.workflowId,
1410+
})
1411+
}
14031412
execLog.warn('Usage threshold notification check failed (non-fatal)', { error: e })
14041413
}
14051414

0 commit comments

Comments
 (0)