Skip to content

Commit a99defa

Browse files
committed
pr feedback
1 parent c61c9f8 commit a99defa

18 files changed

+190
-152
lines changed

dist/index.js

Lines changed: 64 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model/cloud-runner/providers/aws/aws-task-runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class AWSTaskRunner {
209209
const sleepMs = baseBackoffMs + jitterMs;
210210
CloudRunnerLogger.log(`AWS throttled GetRecords, backing off ${sleepMs}ms (1000 + jitter ${jitterMs})`);
211211
await new Promise((r) => setTimeout(r, sleepMs));
212+
212213
return { iterator, shouldReadLogs, output, shouldCleanup };
213214
}
214215
throw error;

src/model/cloud-runner/providers/aws/services/task-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export class TaskService {
204204
const objects = await (
205205
SharedWorkspaceLocking as unknown as { listObjects(prefix: string): Promise<string[]> }
206206
).listObjects('');
207+
207208
return objects.map((x: string) => ({ Key: x }));
208209
}
209210
const s3 = AwsClientFactory.getS3();
@@ -213,6 +214,6 @@ export class TaskService {
213214

214215
const results = await s3.send(new ListObjectsV2Command(listRequest));
215216

216-
return (results.Contents || []).map((obj) => ({ Key: obj.Key || '' }));
217+
return (results.Contents || []).map((object) => ({ Key: object.Key || '' }));
217218
}
218219
}

src/model/cloud-runner/providers/k8s/kubernetes-job-spec-factory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class KubernetesJobSpecFactory {
2222
containerName: string,
2323
ip: string = '',
2424
) {
25-
const endpointEnvNames = new Set([
25+
const endpointEnvironmentNames = new Set([
2626
'AWS_S3_ENDPOINT',
2727
'AWS_ENDPOINT',
2828
'AWS_CLOUD_FORMATION_ENDPOINT',
@@ -36,7 +36,7 @@ class KubernetesJobSpecFactory {
3636
let value = x.value;
3737
if (
3838
typeof value === 'string' &&
39-
endpointEnvNames.has(x.name) &&
39+
endpointEnvironmentNames.has(x.name) &&
4040
(value.startsWith('http://localhost') || value.startsWith('http://127.0.0.1'))
4141
) {
4242
// Replace localhost with host.k3d.internal so pods can access host services
@@ -45,6 +45,7 @@ class KubernetesJobSpecFactory {
4545
.replace('http://localhost', 'http://host.k3d.internal')
4646
.replace('http://127.0.0.1', 'http://host.k3d.internal');
4747
}
48+
4849
return { name: x.name, value } as CloudRunnerEnvironmentVariable;
4950
});
5051

src/model/cloud-runner/providers/k8s/kubernetes-pods.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class KubernetesPods {
1919
}));
2020

2121
const errorDetails: string[] = [];
22-
errorDetails.push(`Pod: ${podName}`);
23-
errorDetails.push(`Phase: ${phase}`);
22+
errorDetails.push(`Pod: ${podName}`, `Phase: ${phase}`);
2423

2524
if (conditions.length > 0) {
2625
errorDetails.push(
@@ -36,10 +35,10 @@ class KubernetesPods {
3635
let containerSucceeded = false;
3736

3837
if (containerStatuses.length > 0) {
39-
containerStatuses.forEach((cs, idx) => {
38+
for (const [index, cs] of containerStatuses.entries()) {
4039
if (cs.state?.waiting) {
4140
errorDetails.push(
42-
`Container ${idx} (${cs.name}) waiting: ${cs.state.waiting.reason} - ${cs.state.waiting.message || ''}`,
41+
`Container ${index} (${cs.name}) waiting: ${cs.state.waiting.reason} - ${cs.state.waiting.message || ''}`,
4342
);
4443
}
4544
if (cs.state?.terminated) {
@@ -49,12 +48,12 @@ class KubernetesPods {
4948
containerSucceeded = true;
5049
}
5150
errorDetails.push(
52-
`Container ${idx} (${cs.name}) terminated: ${cs.state.terminated.reason} - ${
51+
`Container ${index} (${cs.name}) terminated: ${cs.state.terminated.reason} - ${
5352
cs.state.terminated.message || ''
5453
} (exit code: ${exitCode})`,
5554
);
5655
}
57-
});
56+
}
5857
}
5958

6059
if (events.length > 0) {
@@ -80,6 +79,7 @@ class KubernetesPods {
8079
);
8180
}
8281
CloudRunnerLogger.log(`Pod details: ${errorDetails.join('\n')}`);
82+
8383
// Don't throw error - container succeeded, PreStopHook failure is non-critical
8484
return false; // Pod is not running, but we don't treat it as a failure
8585
}
@@ -90,8 +90,9 @@ class KubernetesPods {
9090
CloudRunnerLogger.log(
9191
`Pod ${podName} was killed with PreStopHook failure. Waiting for container status to determine if container succeeded...`,
9292
);
93+
9394
// Wait a bit for container status to become available (up to 30 seconds)
94-
for (let i = 0; i < 6; i++) {
95+
for (let index = 0; index < 6; index++) {
9596
await new Promise((resolve) => setTimeout(resolve, 5000));
9697
try {
9798
const updatedPod = (await kubeClient.listNamespacedPod(namespace)).body.items.find(
@@ -105,6 +106,7 @@ class KubernetesPods {
105106
CloudRunnerLogger.logWarning(
106107
`Pod ${podName} container succeeded (exit code 0) after waiting. PreStopHook failure is non-fatal.`,
107108
);
109+
108110
return false; // Pod is not running, but container succeeded
109111
} else {
110112
CloudRunnerLogger.log(
@@ -121,12 +123,14 @@ class KubernetesPods {
121123
CloudRunnerLogger.log(`Error while waiting for container status: ${waitError}`);
122124
}
123125
}
126+
124127
// If we still don't have container status after waiting, but only PreStopHook failed,
125128
// be lenient - the container might have succeeded but status wasn't updated
126129
if (containerExitCode === undefined && hasPreStopHookFailure && !hasExceededGracePeriod) {
127130
CloudRunnerLogger.logWarning(
128131
`Pod ${podName} container status not available after waiting, but only PreStopHook failed (no ExceededGracePeriod). Assuming container may have succeeded.`,
129132
);
133+
130134
return false; // Be lenient - PreStopHook failure alone is not fatal
131135
}
132136
CloudRunnerLogger.log(
@@ -139,6 +143,7 @@ class KubernetesPods {
139143
CloudRunnerLogger.logWarning(
140144
`Pod ${podName} has PreStopHook failure but no container failure detected. Treating as non-fatal.`,
141145
);
146+
142147
return false; // PreStopHook failure alone is not fatal if container status is unclear
143148
}
144149

@@ -149,8 +154,10 @@ class KubernetesPods {
149154
CloudRunnerLogger.logWarning(
150155
`Pod ${podName} was killed (exit code 137 - likely OOM or resource limit) with PreStopHook/grace period issues. This may be a resource constraint issue rather than a build failure.`,
151156
);
157+
152158
// Still log the details but don't fail the test - the build might have succeeded before being killed
153159
CloudRunnerLogger.log(`Pod details: ${errorDetails.join('\n')}`);
160+
154161
return false; // Don't treat system kills as test failures if only PreStopHook issues
155162
}
156163

src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,30 @@ class KubernetesTaskRunner {
6262
true,
6363
callback,
6464
);
65+
6566
// If we successfully got logs, check for end of transmission
6667
if (FollowLogStreamService.DidReceiveEndOfTransmission) {
6768
CloudRunnerLogger.log('end of log stream');
6869
break;
6970
}
71+
7072
// If we got logs but no end marker, continue trying (might be more logs)
7173
if (retriesAfterFinish < KubernetesTaskRunner.maxRetry) {
7274
retriesAfterFinish++;
7375
continue;
7476
}
77+
7578
// If we've exhausted retries, break
7679
break;
7780
} catch (fallbackError: any) {
7881
CloudRunnerLogger.log(`Fallback log fetch also failed: ${fallbackError}`);
82+
7983
// If both fail, continue retrying if we haven't exhausted retries
8084
if (retriesAfterFinish < KubernetesTaskRunner.maxRetry) {
8185
retriesAfterFinish++;
8286
continue;
8387
}
88+
8489
// Only break if we've exhausted all retries
8590
CloudRunnerLogger.logWarning(
8691
`Could not fetch any container logs after ${KubernetesTaskRunner.maxRetry} retries`,
@@ -101,6 +106,7 @@ class KubernetesTaskRunner {
101106
if (!error?.message?.includes('previous terminated container')) {
102107
throw error;
103108
}
109+
104110
// For previous container errors, we've already tried fallback, so just break
105111
CloudRunnerLogger.logWarning(
106112
`Could not fetch previous container logs after retries, but continuing with available logs`,

src/model/cloud-runner/providers/local/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ class LocalCloudRunner implements ProviderInterface {
7474
.split('\n')
7575
.filter((x) => x.trim().length > 0)
7676
.join(' ; ');
77+
7778
// Use shell-quote to properly escape the command string, preventing command injection
7879
const bashWrapped = `bash -lc ${quote([inline])}`;
80+
7981
return await CloudRunnerSystem.Run(bashWrapped);
8082
}
8183

src/model/cloud-runner/remote-client/caching.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ export class Caching {
8484
try {
8585
const diskCheckOutput = await CloudRunnerSystem.Run(`df . 2>/dev/null || df /data 2>/dev/null || true`);
8686
CloudRunnerLogger.log(`Disk space before tar: ${diskCheckOutput}`);
87+
8788
// Parse disk usage percentage (e.g., "72G 72G 196M 100%")
8889
const usageMatch = diskCheckOutput.match(/(\d+)%/);
8990
if (usageMatch) {
90-
diskUsagePercent = parseInt(usageMatch[1], 10);
91+
diskUsagePercent = Number.parseInt(usageMatch[1], 10);
9192
}
92-
} catch (error) {
93+
} catch {
9394
// Ignore disk check errors
9495
}
9596

@@ -103,6 +104,7 @@ export class Caching {
103104
await CloudRunnerSystem.Run(
104105
`find ${cacheParent} -name "*.tar*" -type f -mmin +360 -delete 2>/dev/null || true`,
105106
);
107+
106108
// Also try to remove old cache directories
107109
await CloudRunnerSystem.Run(`find ${cacheParent} -type d -empty -delete 2>/dev/null || true`);
108110
CloudRunnerLogger.log(`Cleanup completed. Checking disk space again...`);
@@ -117,7 +119,7 @@ export class Caching {
117119
// Clean up any existing incomplete tar files
118120
try {
119121
await CloudRunnerSystem.Run(`rm -f ${cacheArtifactName}.tar${compressionSuffix} 2>/dev/null || true`);
120-
} catch (error) {
122+
} catch {
121123
// Ignore cleanup errors
122124
}
123125

@@ -130,6 +132,7 @@ export class Caching {
130132
const errorMessage = error?.message || error?.toString() || '';
131133
if (errorMessage.includes('No space left') || errorMessage.includes('Wrote only')) {
132134
CloudRunnerLogger.log(`Disk space error detected. Attempting aggressive cleanup...`);
135+
133136
// Try to clean up old cache files more aggressively
134137
try {
135138
const cacheParent = path.dirname(cacheFolder);
@@ -138,8 +141,10 @@ export class Caching {
138141
await CloudRunnerSystem.Run(
139142
`find ${cacheParent} -name "*.tar*" -type f -mmin +60 -delete 2>/dev/null || true`,
140143
);
144+
141145
// Remove empty cache directories
142146
await CloudRunnerSystem.Run(`find ${cacheParent} -type d -empty -delete 2>/dev/null || true`);
147+
143148
// Also try to clean up the entire cache folder if it's getting too large
144149
const cacheRoot = path.resolve(cacheParent, '..');
145150
if (await fileExists(cacheRoot)) {
@@ -149,12 +154,14 @@ export class Caching {
149154
);
150155
}
151156
CloudRunnerLogger.log(`Aggressive cleanup completed. Retrying tar operation...`);
157+
152158
// Retry the tar operation once after cleanup
153159
let retrySucceeded = false;
154160
try {
155161
await CloudRunnerSystem.Run(
156162
`tar -cf ${cacheArtifactName}.tar${compressionSuffix} "${path.basename(sourceFolder)}"`,
157163
);
164+
158165
// If retry succeeds, mark it - we'll continue normally without throwing
159166
retrySucceeded = true;
160167
} catch (retryError: any) {
@@ -164,10 +171,12 @@ export class Caching {
164171
}`,
165172
);
166173
}
174+
167175
// If retry succeeded, don't throw the original error - let execution continue after catch block
168176
if (!retrySucceeded) {
169177
throw error;
170178
}
179+
171180
// If we get here, retry succeeded - execution will continue after the catch block
172181
} else {
173182
throw new Error(
@@ -189,6 +198,7 @@ export class Caching {
189198
await CloudRunnerSystem.Run(`du ${cacheArtifactName}.tar${compressionSuffix}`);
190199
assert(await fileExists(`${cacheArtifactName}.tar${compressionSuffix}`), 'cache archive exists');
191200
assert(await fileExists(path.basename(sourceFolder)), 'source folder exists');
201+
192202
// Ensure the cache folder directory exists before moving the file
193203
// (it might have been deleted by cleanup if it was empty)
194204
if (!(await fileExists(cacheFolder))) {

0 commit comments

Comments
 (0)