Skip to content

Commit b11250d

Browse files
committed
fix(build-notes): carry the notes' layout into the build and size-check a baseline before creating notes
1 parent 379c44c commit b11250d

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎apps/sim/lib/build-notes/application/build-notes.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export interface EvaluateBuildNotesResult {
146146
}
147147

148148
interface BatchReading {
149-
batch: Pick<ApplyWorkflowOperationsInput, 'operations' | 'blockEnabledChanges'> | null
149+
batch: Pick<ApplyWorkflowOperationsInput, 'operations' | 'blockEnabledChanges' | 'layout'> | null
150150
problems: string[]
151151
}
152152

@@ -169,6 +169,8 @@ function parseBatch(reading: ReturnType<typeof readBuildNotes>): BatchReading {
169169
blockId: change.block_id,
170170
enabled: change.enabled,
171171
})),
172+
// Placement only, so it is not part of what evaluation approves.
173+
layout: parsed.data.layout,
172174
},
173175
problems: [],
174176
}

‎apps/sim/lib/build-notes/files.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ class StaleBaselineError extends OrchestrationError {
2929
/** A baseline is a whole graph; anything larger is not one this feature keeps. */
3030
const MAX_BASELINE_BYTES = 16 * 1024 * 1024
3131

32+
/** The baseline file's text, refused when the graph is larger than a baseline can be. */
33+
function baselineContent(baseline: BaselineSnapshot): string {
34+
const content = serializeBaseline(baseline)
35+
if (Buffer.byteLength(content, 'utf-8') > MAX_BASELINE_BYTES) {
36+
throw new OrchestrationError(
37+
'payload_too_large',
38+
`This workflow is too large for build notes to keep a baseline of (over ${MAX_BASELINE_BYTES / 1024 / 1024}MB)`
39+
)
40+
}
41+
return content
42+
}
43+
3244
/** Creates the notes file with its owner row, then the baseline file of the current graph. */
3345
export async function createBuildNotesFiles(params: {
3446
workspaceId: string
@@ -38,6 +50,8 @@ export async function createBuildNotesFiles(params: {
3850
baseline: BaselineSnapshot
3951
}): Promise<BuildNotesRow> {
4052
const { workspaceId, workflowId, userId } = params
53+
// Refused before the notes exist, so a workflow too large to baseline never gets notes it cannot use.
54+
baselineContent(params.baseline)
4155
let notes: BuildNotesRow
4256
try {
4357
;({ owner: notes } = await createOwnedWorkspaceFile({
@@ -79,13 +93,7 @@ export async function writeBaseline(
7993
baseline: BaselineSnapshot,
8094
author: { userId: string; source: WorkspaceFileVersionSource }
8195
): Promise<BuildNotesRow> {
82-
const content = serializeBaseline(baseline)
83-
if (Buffer.byteLength(content, 'utf-8') > MAX_BASELINE_BYTES) {
84-
throw new OrchestrationError(
85-
'payload_too_large',
86-
`This workflow is too large for build notes to keep a baseline of (over ${MAX_BASELINE_BYTES / 1024 / 1024}MB)`
87-
)
88-
}
96+
const content = baselineContent(baseline)
8997
if (!notes.baselineFileId) {
9098
try {
9199
const { fileId } = await createOwnedWorkspaceFile({

0 commit comments

Comments
 (0)