@atolis-hq/wake 0.3.63 → 0.3.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/bootstrap/composition-root.js +14 -2
- package/dist/src/bootstrap/surface-cli-applications.js +1 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/index.js +1 -0
- package/dist/src/execution/infrastructure/runner-memory-profile.js +34 -0
- package/dist/src/integrations/github/infrastructure/bounded-fetch.js +75 -0
- package/dist/src/integrations/github/infrastructure/client.js +2 -0
- package/dist/src/surfaces/cli/infrastructure/docker-cli.js +3 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createPullRequestService } from '../activities/index.js';
|
|
2
2
|
import { ControlStreamKind, DispatchPolicy, createAdvanceOnce, createControlPlaneService, createRunnerControlService, ineligibleRunners, } from '../control-plane/index.js';
|
|
3
|
-
import { ExecutionCancellationReason, ExternalExecutionState, GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, } from '../execution/index.js';
|
|
3
|
+
import { ExecutionCancellationReason, ExternalExecutionState, GitWorkspaceProvider, RecoveryService, TranscriptStore, createExecutionService, createRunnerMemoryProfileDecorator, } from '../execution/index.js';
|
|
4
4
|
import { createGitHubAgentContextReader, gitHubProviderDefinition, resolveGitHubResourceUrl, } from '../integrations/github/index.js';
|
|
5
5
|
import { SystemClock, UlidIdGenerator, } from '../kernel/index.js';
|
|
6
6
|
import { compileWorkflow, createOrchestrationService } from '../orchestration/index.js';
|
|
@@ -59,10 +59,22 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
59
59
|
const transcriptStore = config.transcripts.enabled
|
|
60
60
|
? (options.transcriptStore ?? new TranscriptStore(paths.transcriptsRoot))
|
|
61
61
|
: undefined;
|
|
62
|
+
const profileDecorator = process.env.WAKE_MEMORY_PROFILE === 'runner'
|
|
63
|
+
? createRunnerMemoryProfileDecorator({
|
|
64
|
+
write: (line) => process.stderr.write(line),
|
|
65
|
+
now: () => clock.now().toISOString(),
|
|
66
|
+
memoryUsage: () => process.memoryUsage(),
|
|
67
|
+
})
|
|
68
|
+
: undefined;
|
|
69
|
+
const decorateRunner = profileDecorator === undefined
|
|
70
|
+
? options.decorateRunner
|
|
71
|
+
: options.decorateRunner === undefined
|
|
72
|
+
? profileDecorator
|
|
73
|
+
: (runner, name) => profileDecorator(options.decorateRunner(runner, name), name);
|
|
62
74
|
const execution = createExecutionService(journal, activities, config.execution, {
|
|
63
75
|
clock,
|
|
64
76
|
ids,
|
|
65
|
-
runners: createRunnerRegistry(config.execution, fakeScenarios,
|
|
77
|
+
runners: createRunnerRegistry(config.execution, fakeScenarios, decorateRunner),
|
|
66
78
|
reportRunnerQuota: createRunnerQuotaReporter(journal, clock, ids),
|
|
67
79
|
...(transcriptStore !== undefined
|
|
68
80
|
? {
|
|
@@ -179,6 +179,7 @@ function sandboxDockerOptions(root, overrides) {
|
|
|
179
179
|
containerHomeMountPath: root.config.host.sandbox.containerHomeMountPath,
|
|
180
180
|
extraMounts: root.config.host.sandbox.extraMounts,
|
|
181
181
|
startEnabled: root.config.host.sandbox.start.enabled,
|
|
182
|
+
...(process.env.WAKE_MEMORY_PROFILE === 'runner' ? { memoryProfile: 'runner' } : {}),
|
|
182
183
|
inspect: createDockerInspection(root.paths.wakeRoot),
|
|
183
184
|
resolveBuildVersion: () => resolveSandboxBuildVersion(root),
|
|
184
185
|
};
|
|
@@ -26,6 +26,7 @@ export * from './infrastructure/runners/cursor.js';
|
|
|
26
26
|
export * from './infrastructure/runners/fake.js';
|
|
27
27
|
export * from './infrastructure/runners/fake-scenarios.js';
|
|
28
28
|
export * from './infrastructure/runners/registry.js';
|
|
29
|
+
export * from './infrastructure/runner-memory-profile.js';
|
|
29
30
|
export * from './infrastructure/transcripts.js';
|
|
30
31
|
export * from './infrastructure/transcript-store.js';
|
|
31
32
|
export * from './infrastructure/workspace/fake-workspace.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function createRunnerMemoryProfileDecorator(options) {
|
|
2
|
+
return (runner, name) => ({
|
|
3
|
+
...(runner.supportsSessionResume === undefined
|
|
4
|
+
? {}
|
|
5
|
+
: { supportsSessionResume: runner.supportsSessionResume }),
|
|
6
|
+
start: async (request, signal) => {
|
|
7
|
+
writeSample(options, 'runner.start.before', name, request.runId);
|
|
8
|
+
const execution = await runner.start(request, signal);
|
|
9
|
+
writeSample(options, 'runner.start.returned', name, request.runId);
|
|
10
|
+
return {
|
|
11
|
+
...execution,
|
|
12
|
+
result: execution.result.finally(() => {
|
|
13
|
+
writeSample(options, 'runner.result.settled', name, request.runId);
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function writeSample(options, phase, runner, runId) {
|
|
20
|
+
const memory = options.memoryUsage();
|
|
21
|
+
options.write(`${JSON.stringify({
|
|
22
|
+
type: 'wake.runner-memory',
|
|
23
|
+
phase,
|
|
24
|
+
at: options.now(),
|
|
25
|
+
pid: process.pid,
|
|
26
|
+
runner,
|
|
27
|
+
runId,
|
|
28
|
+
rss: memory.rss,
|
|
29
|
+
heapTotal: memory.heapTotal,
|
|
30
|
+
heapUsed: memory.heapUsed,
|
|
31
|
+
external: memory.external,
|
|
32
|
+
arrayBuffers: memory.arrayBuffers,
|
|
33
|
+
})}\n`);
|
|
34
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const defaultMaximumGitHubResponseBytes = 8 * 1024 * 1024;
|
|
2
|
+
export class GitHubResponseTooLargeError extends Error {
|
|
3
|
+
maximumBytes;
|
|
4
|
+
observedBytes;
|
|
5
|
+
constructor(maximumBytes, observedBytes) {
|
|
6
|
+
super(`GitHub response exceeded ${maximumBytes} bytes (observed ${observedBytes})`);
|
|
7
|
+
this.maximumBytes = maximumBytes;
|
|
8
|
+
this.observedBytes = observedBytes;
|
|
9
|
+
this.name = 'GitHubResponseTooLargeError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function createBoundedGitHubFetch(baseFetch = globalThis.fetch, maximumResponseBytes = defaultMaximumGitHubResponseBytes) {
|
|
13
|
+
return async (input, init) => {
|
|
14
|
+
const response = await baseFetch(input, init);
|
|
15
|
+
const declaredBytes = contentLength(response);
|
|
16
|
+
if (declaredBytes !== undefined && declaredBytes > maximumResponseBytes) {
|
|
17
|
+
await response.body?.cancel();
|
|
18
|
+
throw new GitHubResponseTooLargeError(maximumResponseBytes, declaredBytes);
|
|
19
|
+
}
|
|
20
|
+
return new Proxy(response, {
|
|
21
|
+
get(target, property) {
|
|
22
|
+
if (property === 'text')
|
|
23
|
+
return async () => decode(await readBoundedBody(target, maximumResponseBytes));
|
|
24
|
+
if (property === 'arrayBuffer')
|
|
25
|
+
return async () => (await readBoundedBody(target, maximumResponseBytes)).buffer;
|
|
26
|
+
if (property === 'json')
|
|
27
|
+
return async () => JSON.parse(decode(await readBoundedBody(target, maximumResponseBytes)));
|
|
28
|
+
const value = Reflect.get(target, property, target);
|
|
29
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function contentLength(response) {
|
|
35
|
+
const value = response.headers.get('content-length');
|
|
36
|
+
if (value === null)
|
|
37
|
+
return undefined;
|
|
38
|
+
const parsed = Number(value);
|
|
39
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;
|
|
40
|
+
}
|
|
41
|
+
async function readBoundedBody(response, maximumBytes) {
|
|
42
|
+
if (response.body === null)
|
|
43
|
+
return new Uint8Array();
|
|
44
|
+
const reader = response.body.getReader();
|
|
45
|
+
const chunks = [];
|
|
46
|
+
let observedBytes = 0;
|
|
47
|
+
try {
|
|
48
|
+
while (true) {
|
|
49
|
+
const chunk = await reader.read();
|
|
50
|
+
if (chunk.done)
|
|
51
|
+
return concatChunks(chunks, observedBytes);
|
|
52
|
+
observedBytes += chunk.value.byteLength;
|
|
53
|
+
if (observedBytes > maximumBytes) {
|
|
54
|
+
await reader.cancel();
|
|
55
|
+
throw new GitHubResponseTooLargeError(maximumBytes, observedBytes);
|
|
56
|
+
}
|
|
57
|
+
chunks.push(chunk.value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
reader.releaseLock();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function decode(bytes) {
|
|
65
|
+
return new TextDecoder().decode(bytes);
|
|
66
|
+
}
|
|
67
|
+
function concatChunks(chunks, length) {
|
|
68
|
+
const body = new Uint8Array(length);
|
|
69
|
+
let offset = 0;
|
|
70
|
+
for (const chunk of chunks) {
|
|
71
|
+
body.set(chunk, offset);
|
|
72
|
+
offset += chunk.byteLength;
|
|
73
|
+
}
|
|
74
|
+
return body;
|
|
75
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Octokit } from '@octokit/rest';
|
|
2
2
|
import { MergeMethod, ProviderPermission, PullRequestState } from '../../../activities/index.js';
|
|
3
3
|
import { GitHubOutboundAction } from '../contracts/vocabulary.js';
|
|
4
|
+
import { createBoundedGitHubFetch } from './bounded-fetch.js';
|
|
4
5
|
import { branch, getCombinedStatusForRef, getIssueLabels, getPullRequest, listCheckRunsForRef, listIssueComments, listIssues, listPullRequestFiles, listPullRequests, listReviewComments, listReviews, } from './client-reads.js';
|
|
5
6
|
import { createEtagCache } from './etag-cache.js';
|
|
6
7
|
// Octokit's request-log plugin reports every non-2xx response through this
|
|
@@ -29,6 +30,7 @@ function logGitHubRequestFailure(message) {
|
|
|
29
30
|
export function createGitHubClient(token) {
|
|
30
31
|
const octokit = new Octokit({
|
|
31
32
|
auth: token,
|
|
33
|
+
request: { fetch: createBoundedGitHubFetch() },
|
|
32
34
|
log: { debug() { }, info() { }, warn() { }, error: logGitHubRequestFailure },
|
|
33
35
|
});
|
|
34
36
|
const cache = createEtagCache();
|
|
@@ -197,6 +197,9 @@ async function createContainer(docker, options) {
|
|
|
197
197
|
`WAKE_HOME_INIT_DIRS=${homeInitDirectories.join('\n')}`,
|
|
198
198
|
]),
|
|
199
199
|
...(options.startEnabled === true ? ['-e', 'WAKE_START_ENABLED=true'] : []),
|
|
200
|
+
...(options.memoryProfile === undefined
|
|
201
|
+
? []
|
|
202
|
+
: ['-e', `WAKE_MEMORY_PROFILE=${options.memoryProfile}`]),
|
|
200
203
|
options.image,
|
|
201
204
|
]);
|
|
202
205
|
}
|