Skip to content

Fix node options and OOM retries #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/supervisor/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export function getDockerHostDomain() {
return isMacOs || isWindows ? "host.docker.internal" : "localhost";
}

export function getRunnerId(runId: string) {
return `runner-${runId.replace("run_", "")}`;
export function getRunnerId(runId: string, attemptNumber?: number) {
const parts = ["runner", runId.replace("run_", "")];

if (attemptNumber && attemptNumber > 1) {
parts.push(`attempt-${attemptNumber}`);
}

return parts.join("-");
}
2 changes: 1 addition & 1 deletion apps/supervisor/src/workloadManager/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class DockerWorkloadManager implements WorkloadManager {
async create(opts: WorkloadManagerCreateOptions) {
this.logger.log("[DockerWorkloadProvider] Creating container", { opts });

const runnerId = getRunnerId(opts.runFriendlyId);
const runnerId = getRunnerId(opts.runFriendlyId, opts.nextAttemptNumber);

const runArgs = [
"run",
Expand Down
2 changes: 1 addition & 1 deletion apps/supervisor/src/workloadManager/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class KubernetesWorkloadManager implements WorkloadManager {
async create(opts: WorkloadManagerCreateOptions) {
this.logger.log("[KubernetesWorkloadManager] Creating container", { opts });

const runnerId = getRunnerId(opts.runFriendlyId);
const runnerId = getRunnerId(opts.runFriendlyId, opts.nextAttemptNumber);

try {
await this.k8s.core.createNamespacedPod({
Expand Down
9 changes: 8 additions & 1 deletion apps/webapp/app/v3/runEngineHandlers.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,19 @@ export function registerRunEngineEventBusHandlers() {

engine.eventBus.on("runRetryScheduled", async ({ time, run, environment, retryAt }) => {
try {
await eventRepository.recordEvent(`Retry #${run.attemptNumber} delay`, {
let retryMessage = `Retry #${run.attemptNumber} delay`;

if (run.nextMachineAfterOOM) {
retryMessage += ` after OOM`;
}

await eventRepository.recordEvent(retryMessage, {
taskSlug: run.taskIdentifier,
environment,
attributes: {
properties: {
retryAt: retryAt.toISOString(),
nextMachine: run.nextMachineAfterOOM,
},
runId: run.friendlyId,
style: {
Expand Down
1 change: 1 addition & 0 deletions internal-packages/run-engine/src/engine/eventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export type EventBusEvents = {
traceContext: Record<string, string | undefined>;
taskIdentifier: string;
baseCostInCents: number;
nextMachineAfterOOM?: string;
};
organization: {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ export class RunAttemptSystem {
traceContext: run.traceContext as Record<string, string | undefined>,
baseCostInCents: run.baseCostInCents,
spanId: run.spanId,
nextMachineAfterOOM: retryResult.machine,
},
organization: {
id: run.runtimeEnvironment.organizationId,
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-v3/src/deploy/buildImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,7 @@ ENV TRIGGER_PROJECT_ID=\${TRIGGER_PROJECT_ID} \
TRIGGER_CONTENT_HASH=\${TRIGGER_CONTENT_HASH} \
TRIGGER_PROJECT_REF=\${TRIGGER_PROJECT_REF} \
NODE_EXTRA_CA_CERTS=\${NODE_EXTRA_CA_CERTS} \
NODE_ENV=production \
NODE_OPTIONS="--max_old_space_size=8192"
NODE_ENV=production

# Copy the files from the install stage
COPY --from=build --chown=node:node /app ./
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/v3/build/flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe("dedupFlags", () => {
expect(dedupFlags("--log=info --log=warn --log=error")).toBe("--log=error");
});

it("should treat underscores as hyphens", () => {
expect(dedupFlags("--debug_level=info")).toBe("--debug-level=info");
expect(dedupFlags("--debug_level=info --debug-level=warn")).toBe("--debug-level=warn");
});

it("should handle mix of flags with and without values", () => {
expect(dedupFlags("--debug=false -v --debug=true")).toBe("-v --debug=true");
expect(dedupFlags("-v --quiet -v")).toBe("--quiet -v");
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/v3/build/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export function dedupFlags(flags: string): string {
.map((flag): [string, string | boolean] => {
const equalIndex = flag.indexOf("=");
if (equalIndex !== -1) {
const key = flag.slice(0, equalIndex);
const key = flag.slice(0, equalIndex).replace(/_/g, "-");
const value = flag.slice(equalIndex + 1);
return [key, value];
} else {
return [flag, true];
return [flag.replace(/_/g, "-"), true];
}
});

Expand Down