Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code c8df9e447f chore: improve monitoring for Fix: Add isBuildUpToDate check before logic functi
Added warning-level logging in `CodeStepBuildService.buildCodeStepsFromSourceForSteps()` when a code step build is silently skipped because the logic function's `applicationUniversalIdentifier` cannot be resolved.

Previously, when `applicationUniversalIdentifier` was undefined (e.g., the application record was missing from the cache or the logic function had no `applicationId`), the build was silently skipped with `continue` — no log, no error, no trace. This meant unbuilt logic functions could slip through the pre-flight build check without any observability, leading to the downstream S3 "File not found" error at execution time.

The warning log includes the `logicFunctionId` and `applicationId` to aid in diagnosing why the build was skipped.
2026-04-22 08:40:30 +00:00
Sonarly Claude Code fd259d6b9d Fix: Add isBuildUpToDate check before logic function execution in workflow path
https://sonarly.com/issue/29664?type=bug

When a workflow executes a CODE step, the `CodeWorkflowAction` calls `LogicFunctionExecutorService.execute()` which proceeds directly to `LambdaDriver.execute()` and attempts to read the compiled JavaScript from S3 via `getBuiltCode()`. Neither the workflow action nor the executor service checks the `isBuildUpToDate` flag on the logic function before attempting execution. If the logic function's source code has never been compiled (or was modified since last compile), no built artifact exists in S3, and the S3 driver throws `FileStorageException('File not found', FILE_NOT_FOUND)`.

The GraphQL execution path (`LogicFunctionFromSourceService.executeOneFromSource()`) correctly checks `flatLogicFunction.isBuildUpToDate` and triggers `buildOneFromSource()` before executing. The workflow path bypasses this entirely.

Fix: Added a `LOGIC_FUNCTION_NOT_BUILT` exception code and an `isBuildUpToDate` check in `LogicFunctionExecutorService.execute()`.

When a logic function's source code is created or updated, `isBuildUpToDate` is set to `false` and no built artifact exists in S3. The GraphQL execution path (`executeOneFromSource`) checks this flag and triggers a build first. However, the workflow path (`CodeWorkflowAction → LogicFunctionExecutorService.execute() → LambdaDriver.execute()`) did not check this flag, leading to a cryptic S3 "File not found" error when `getBuiltCode()` tried to read the non-existent built file.

The fix adds validation in `LogicFunctionExecutorService.execute()` — immediately after fetching the flat logic function entity, it checks `isBuildUpToDate`. If false, it throws a `LogicFunctionExecutionException` with the new `LOGIC_FUNCTION_NOT_BUILT` code and a clear message explaining the function needs to be built first.

This protects all callers of the executor (workflow actions, route triggers, future integrations) from hitting the cryptic S3 error. The existing route trigger error mapper handles unmapped codes by falling through to `LOGIC_FUNCTION_EXECUTION_ERROR` (500), which is correct behavior.

Note: The pre-flight build in `RunWorkflowJob.startWorkflowExecution` (`buildCodeStepsFromSourceForSteps`) is supposed to build unbuilt code steps before execution, but has a silent failure path — it skips the build without logging when `applicationUniversalIdentifier` cannot be resolved. This new check is defense-in-depth for when that pre-flight build fails silently.
2026-04-22 08:40:30 +00:00
2 changed files with 15 additions and 1 deletions
@@ -51,6 +51,7 @@ export class LogicFunctionExecutionException extends Error {
export enum LogicFunctionExecutionExceptionCode {
LOGIC_FUNCTION_NOT_FOUND = 'LOGIC_FUNCTION_NOT_FOUND',
LOGIC_FUNCTION_NOT_BUILT = 'LOGIC_FUNCTION_NOT_BUILT',
RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED',
}
@@ -88,6 +89,13 @@ export class LogicFunctionExecutorService {
logicFunctionId,
});
if (!flatLogicFunction.isBuildUpToDate) {
throw new LogicFunctionExecutionException(
`Logic function ${logicFunctionId} has not been built. Build it before execution.`,
LogicFunctionExecutionExceptionCode.LOGIC_FUNCTION_NOT_BUILT,
);
}
const envVariables = await this.getExecutionEnvVariables({
workspaceId,
flatApplication,
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { isDefined } from 'twenty-shared/utils';
@@ -12,6 +12,8 @@ import {
@Injectable()
export class CodeStepBuildService {
private readonly logger = new Logger(CodeStepBuildService.name);
constructor(
private readonly workspaceManyOrAllFlatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService,
private readonly logicFunctionFromSourceService: LogicFunctionFromSourceService,
@@ -103,6 +105,10 @@ export class CodeStepBuildService {
: undefined;
if (!isDefined(applicationUniversalIdentifier)) {
this.logger.warn(
`Skipping build for logic function ${logicFunctionId}: ` +
`application not found for applicationId=${flatLogicFunction.applicationId}`,
);
continue;
}