@atolis-hq/wake 0.3.97 → 0.3.99

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.
Files changed (28) hide show
  1. package/dist/src/activities/agent/agent-activity.js +4 -2
  2. package/dist/src/bootstrap/initialise.js +6 -6
  3. package/dist/src/bootstrap/integration-runtime.js +3 -1
  4. package/dist/src/bootstrap/runner-registry.js +1 -1
  5. package/dist/src/bootstrap/version.js +1 -1
  6. package/dist/src/execution/application/execution-activity.js +11 -0
  7. package/dist/src/execution/contracts/config.js +8 -1
  8. package/dist/src/execution/contracts/vocabulary.js +1 -0
  9. package/dist/src/execution/infrastructure/process-execution.js +113 -30
  10. package/dist/src/execution/infrastructure/runners/claude.js +20 -4
  11. package/dist/src/execution/infrastructure/runners/codex.js +1 -1
  12. package/dist/src/execution/infrastructure/runners/command.js +2 -2
  13. package/dist/src/execution/infrastructure/runners/cursor.js +1 -1
  14. package/dist/src/execution/infrastructure/workspace/prepare-workspace.js +1 -1
  15. package/dist/src/integrations/application/poll-service.js +20 -11
  16. package/dist/src/integrations/fake/inbound-translator.js +13 -2
  17. package/dist/src/integrations/github/application/inbound-translator.js +252 -33
  18. package/dist/src/integrations/github/contracts/events.js +37 -0
  19. package/dist/src/resources/application/resource-correlation-retry.js +110 -0
  20. package/dist/src/resources/application/resource-projections.js +58 -6
  21. package/dist/src/resources/application/resource-repository.js +15 -1
  22. package/dist/src/resources/application/resource-service.js +16 -0
  23. package/dist/src/resources/contracts/events.js +45 -1
  24. package/dist/src/resources/contracts/vocabulary.js +4 -0
  25. package/dist/src/resources/domain/resource.js +50 -1
  26. package/dist/src/surfaces/web-assets/assets/{index-0vTT3Aar.js → index-YyzRROrS.js} +12 -12
  27. package/dist/src/surfaces/web-assets/index.html +1 -1
  28. package/package.json +1 -1
@@ -12,6 +12,7 @@ export function createAgentActivity(templates, contextReader) {
12
12
  resumeStartedAt: context.resumeStartedAt,
13
13
  usageBaseline: context.usageBaseline,
14
14
  workspace: context.workspace,
15
+ reportRunnerTimeout: context.reportRunnerTimeout,
15
16
  });
16
17
  await capturePrompt(context, invocation.workItemId, request);
17
18
  const result = await runnerResult(context, invocation.workItemId, request);
@@ -76,7 +77,7 @@ async function recordTranscript(context, write) {
76
77
  async function agentRequest(invocation, templates, contextReader, context) {
77
78
  const input = invocation.input;
78
79
  const template = await resolveTemplate(input.template, invocation.workItemId, templates, contextReader, context.resumeSessionId !== undefined, context.resumeStartedAt);
79
- return requestFrom(input, context.runId ?? invocation.activationId, template, context.runnerContext, context.resumeSessionId, context.usageBaseline, context.workspace);
80
+ return requestFrom(input, context.runId ?? invocation.activationId, template, context.runnerContext, context.resumeSessionId, context.usageBaseline, context.workspace, context.reportRunnerTimeout);
80
81
  }
81
82
  async function resolveTemplate(name, workItemId, templates, contextReader, isResume, observedSince) {
82
83
  if (name === undefined)
@@ -132,7 +133,7 @@ function escapeUntrustedJson(json) {
132
133
  }
133
134
  // The runner request maps each independently optional execution concern.
134
135
  // eslint-disable-next-line max-params, complexity
135
- function requestFrom(input, runId, template, runnerContext, resumeSessionId, usageBaseline, workspace) {
136
+ function requestFrom(input, runId, template, runnerContext, resumeSessionId, usageBaseline, workspace, reportRunnerTimeout) {
136
137
  return {
137
138
  runId,
138
139
  prompt: input.prompt ?? template.prompt,
@@ -144,6 +145,7 @@ function requestFrom(input, runId, template, runnerContext, resumeSessionId, usa
144
145
  ...(resumeSessionId === undefined ? {} : { resumeSessionId }),
145
146
  ...(usageBaseline === undefined ? {} : { usageBaseline }),
146
147
  ...workspaceFields(workspace),
148
+ ...(reportRunnerTimeout === undefined ? {} : { onTimeout: reportRunnerTimeout }),
147
149
  };
148
150
  }
149
151
  function workspaceFields(workspace) {
@@ -22,12 +22,12 @@ function configYaml(containerName) {
22
22
  execution:
23
23
  agentRunners:
24
24
  fake: { kind: fake }
25
- claude-haiku: { kind: claude-cli, command: claude, model: haiku, timeoutMs: 1800000 }
26
- claude-opus: { kind: claude-cli, command: claude, model: claude-opus-4-8, timeoutMs: 1800000 }
27
- codex-luna: { kind: codex-cli, command: codex, model: gpt-5.6-luna, timeoutMs: 1800000 }
28
- codex-terra: { kind: codex-cli, command: codex, model: gpt-5.6-terra, timeoutMs: 1800000 }
29
- codex-sol: { kind: codex-cli, command: codex, model: gpt-5.6-sol, timeoutMs: 1800000 }
30
- cursor-composer: { kind: cursor-cli, command: cursor, model: composer-2.5, timeoutMs: 1800000 }
25
+ claude-haiku: { kind: claude-cli, command: claude, model: haiku }
26
+ claude-opus: { kind: claude-cli, command: claude, model: claude-opus-4-8 }
27
+ codex-luna: { kind: codex-cli, command: codex, model: gpt-5.6-luna }
28
+ codex-terra: { kind: codex-cli, command: codex, model: gpt-5.6-terra }
29
+ codex-sol: { kind: codex-cli, command: codex, model: gpt-5.6-sol }
30
+ cursor-composer: { kind: cursor-cli, command: cursor, model: composer-2.5 }
31
31
  runnerPools:
32
32
  light: [fake]
33
33
  standard: [fake]
@@ -1,8 +1,10 @@
1
+ import { join } from 'node:path';
1
2
  import { ControlStreamKind, ScheduleService, createIntakePipeline, createRunnerPipeline, createWorkCancellationPolicy, } from '../control-plane/index.js';
2
3
  import { RunRepository, createRuntimeMemoryProfile, } from '../execution/index.js';
3
4
  import { AgentRunPublicationReactor, ArtifactRegistrationReactor, DeliveryOutcomeReactor, DeliveryService, IntegrationStreamKind, PollService, ProviderRegistry, fakeProviderDefinition, } from '../integrations/index.js';
4
5
  import { EventActorKind, } from '../kernel/index.js';
5
6
  import { compileWorkflowSelectors, createPullRequestTransitionEvidence, createResourceTransitionReactor, createWatchReactor, selectWorkflow, workflowName, } from '../orchestration/index.js';
7
+ import { withFileLock } from '../persistence/index.js';
6
8
  import { BuiltInResourceCapability, resourceId, } from '../resources/index.js';
7
9
  import { hydrateFakeProviderEvidence } from './fake-provider-files.js';
8
10
  import { createRuntimeProjectionRunner } from './projection-runtime.js';
@@ -133,7 +135,7 @@ export async function composeIntegrationRuntime(input) {
133
135
  return observeMemory(memoryProfile, 'intake.poll', async () => {
134
136
  let appended = 0;
135
137
  for (const provider of providers)
136
- appended += await new PollService(input.journal, provider).pollOnce(signal);
138
+ appended += await withFileLock(join(input.wakeRoot, '.wake', 'locks', `poll-${provider.adapter}.lock`), async () => (await new PollService(input.journal, provider).pollOnce(signal)).appended);
137
139
  return appended;
138
140
  });
139
141
  },
@@ -24,7 +24,7 @@ function createConfiguredRunner(name, runner, scenarios) {
24
24
  case 'command': {
25
25
  if (runner.command === undefined)
26
26
  throw new Error('Command runner requires a command');
27
- return createCommandRunner(runner.command, runner.args, runner.timeoutMs);
27
+ return createCommandRunner(runner.command, runner.args, runner.runnerTimeouts);
28
28
  }
29
29
  }
30
30
  }
@@ -108,4 +108,4 @@ export function resolveWakeVersion(options = {}) {
108
108
  return `g${headHash.slice(0, 7)}`;
109
109
  return '0.1.0-dev';
110
110
  }
111
- export const wakeVersion = "ga522ca7";
111
+ export const wakeVersion = "gee137de";
@@ -1,7 +1,9 @@
1
1
  import { ExecutionEventType } from '../contracts/events.js';
2
2
  import { ProviderQuotaExceededFailureKind } from '../contracts/runner.js';
3
+ import { ExecutionCancellationReason } from '../contracts/vocabulary.js';
3
4
  import { parseAgentRunnerResponse } from '../infrastructure/agent-runner-adapter.js';
4
5
  import { createRunEvent } from './run-lifecycle.js';
6
+ import { confirmCancellation, requestCancellation } from './run-liveness-service.js';
5
7
  export async function executeActivity(runtime, currentRunId, request) {
6
8
  const { activation, context, occurredAt, runner } = request;
7
9
  const controller = new AbortController();
@@ -37,6 +39,7 @@ export async function executeActivity(runtime, currentRunId, request) {
37
39
  }),
38
40
  reportExternalExecution: externalExecutionReporter(runtime, currentRunId, context, activation),
39
41
  reportRunnerResult: runnerResultReporter(runtime, currentRunId, context, activation, request),
42
+ reportRunnerTimeout: runnerTimeoutReporter(runtime, currentRunId),
40
43
  };
41
44
  return runtime.activities.execute({
42
45
  activationId: activation.activationId,
@@ -49,6 +52,14 @@ export async function executeActivity(runtime, currentRunId, request) {
49
52
  resources: context.resources,
50
53
  }, executionContext);
51
54
  }
55
+ function runnerTimeoutReporter(runtime, currentRunId) {
56
+ return async (kind) => {
57
+ await requestCancellation(runtime.repository, runtime.dependencies.clock, currentRunId, kind === 'idle'
58
+ ? ExecutionCancellationReason.IdleTimeout
59
+ : ExecutionCancellationReason.Timeout, runtime.active);
60
+ await confirmCancellation(runtime.repository, runtime.dependencies.clock, currentRunId);
61
+ };
62
+ }
52
63
  function externalExecutionReporter(runtime, currentRunId, context, activation) {
53
64
  return async (reference) => {
54
65
  const loaded = await runtime.repository.load(currentRunId);
@@ -3,7 +3,14 @@ const isReservedFlag = (arg) => arg === '--output-format' || arg === '--resume';
3
3
  const agentRunnerBase = {
4
4
  model: z.string().trim().min(1).optional(),
5
5
  effort: z.string().trim().min(1).optional(),
6
- timeoutMs: z.number().int().positive().default(1_800_000),
6
+ runnerTimeouts: z
7
+ .object({
8
+ idleMs: z.number().int().positive().default(600_000),
9
+ hardMs: z.number().int().positive().default(7_200_000),
10
+ cancellationGraceMs: z.number().int().positive().default(30_000),
11
+ })
12
+ .strict()
13
+ .prefault({}),
7
14
  args: z.array(z.string()).default([]),
8
15
  };
9
16
  const commandRunner = (kind) => z
@@ -14,6 +14,7 @@ export const ExecutionCancellationReason = defineClosedVocabulary({
14
14
  WorkCancelled: 'work-cancelled',
15
15
  WorkClosed: 'work-closed',
16
16
  WorkflowSuperseded: 'workflow-superseded',
17
+ IdleTimeout: 'idle-timeout',
17
18
  Timeout: 'timeout',
18
19
  Shutdown: 'shutdown',
19
20
  Maintenance: 'maintenance',
@@ -2,46 +2,81 @@ import { spawn } from 'node:child_process';
2
2
  // Agent CLIs can emit arbitrarily large machine-readable transcripts. Capture
3
3
  // raw bytes ourselves so overflow never enters a third-party string buffer.
4
4
  const maximumCapturedProcessOutputBytes = 1024 * 1024;
5
- export function runProcess(command, args, cwd, signal, timeoutMs, shell = false) {
5
+ export function runProcess(command, args, cwd, signal, options, shell = false) {
6
6
  const child = spawn(command, args, {
7
7
  ...(cwd === undefined ? {} : { cwd }),
8
8
  shell,
9
9
  ...(shell && process.platform !== 'win32' ? { detached: true } : {}),
10
10
  stdio: ['ignore', 'pipe', 'pipe'],
11
11
  });
12
- const result = captureProcessOutput(child, signal, timeoutMs, shell);
13
- return {
14
- result,
15
- cancel: async () => {
16
- terminate(child, shell);
17
- },
18
- };
12
+ return captureProcessOutput(child, signal, options, shell);
19
13
  }
20
- function captureProcessOutput(child, signal, timeoutMs, shell) {
21
- return new Promise((resolve) => {
14
+ // Lifecycle coordination must share these closures so first-event-wins is atomic.
15
+ // eslint-disable-next-line max-lines-per-function
16
+ function captureProcessOutput(child, signal, options, shell) {
17
+ let terminatePromise;
18
+ const terminate = () => (terminatePromise ??= terminateGracefully(child, shell, options?.cancellationGraceMs));
19
+ let cancel = terminate;
20
+ // eslint-disable-next-line max-lines-per-function
21
+ const result = new Promise((resolve) => {
22
22
  const stdout = [];
23
23
  const stderr = [];
24
24
  const combinedOutput = [];
25
25
  let capturedBytes = 0;
26
26
  let timedOut = false;
27
+ let timeoutKind;
27
28
  let overflowed = false;
28
29
  let error;
30
+ let settled = false;
31
+ let idleTimeout;
32
+ let hardTimeout;
33
+ const clearTimeouts = () => {
34
+ if (idleTimeout !== undefined)
35
+ clearTimeout(idleTimeout);
36
+ if (hardTimeout !== undefined)
37
+ clearTimeout(hardTimeout);
38
+ };
39
+ const terminateForTimeout = async (kind) => {
40
+ if (settled)
41
+ return;
42
+ settled = true;
43
+ timedOut = true;
44
+ timeoutKind = kind;
45
+ clearTimeouts();
46
+ try {
47
+ await options?.onTimeout?.(kind);
48
+ }
49
+ finally {
50
+ void terminate();
51
+ }
52
+ };
53
+ const resetIdleTimeout = () => {
54
+ if (settled || options?.idleMs === undefined)
55
+ return;
56
+ if (idleTimeout !== undefined)
57
+ clearTimeout(idleTimeout);
58
+ idleTimeout = setTimeout(() => void terminateForTimeout('idle'), options.idleMs);
59
+ };
29
60
  const terminateForOverflow = () => {
61
+ if (settled)
62
+ return;
63
+ settled = true;
30
64
  overflowed = true;
65
+ clearTimeouts();
31
66
  child.stdout?.destroy();
32
67
  child.stderr?.destroy();
33
- terminate(child, shell);
68
+ void terminate();
34
69
  };
35
70
  const capture = (destination) => (chunk) => {
36
- if (overflowed)
71
+ if (settled)
37
72
  return;
73
+ resetIdleTimeout();
38
74
  const remaining = maximumCapturedProcessOutputBytes - capturedBytes;
39
75
  if (remaining <= 0 || chunk.length > remaining) {
40
- if (remaining > 0) {
41
- const captured = chunk.subarray(0, remaining);
42
- destination.push(captured);
43
- combinedOutput.push(captured);
44
- }
76
+ if (remaining > 0)
77
+ destination.push(chunk.subarray(0, remaining));
78
+ if (remaining > 0)
79
+ combinedOutput.push(chunk.subarray(0, remaining));
45
80
  capturedBytes = maximumCapturedProcessOutputBytes;
46
81
  terminateForOverflow();
47
82
  return;
@@ -52,20 +87,33 @@ function captureProcessOutput(child, signal, timeoutMs, shell) {
52
87
  };
53
88
  child.stdout?.on('data', capture(stdout));
54
89
  child.stderr?.on('data', capture(stderr));
55
- const timeout = timeoutMs === undefined
56
- ? undefined
57
- : setTimeout(() => {
58
- timedOut = true;
59
- terminate(child, shell);
60
- }, timeoutMs);
61
- const onAbort = () => terminate(child, shell);
90
+ resetIdleTimeout();
91
+ if (options?.hardMs !== undefined)
92
+ hardTimeout = setTimeout(() => void terminateForTimeout('hard'), options.hardMs);
93
+ const onAbort = () => {
94
+ if (settled)
95
+ return;
96
+ settled = true;
97
+ clearTimeouts();
98
+ void terminate();
99
+ };
100
+ cancel = () => {
101
+ if (!settled) {
102
+ settled = true;
103
+ clearTimeouts();
104
+ }
105
+ return terminate();
106
+ };
62
107
  signal.addEventListener('abort', onAbort, { once: true });
108
+ if (signal.aborted)
109
+ onAbort();
63
110
  child.once('error', (caught) => {
64
111
  error = caught;
65
112
  });
66
113
  child.once('close', (exitCode) => {
67
- if (timeout !== undefined)
68
- clearTimeout(timeout);
114
+ if (!settled)
115
+ settled = true;
116
+ clearTimeouts();
69
117
  signal.removeEventListener('abort', onAbort);
70
118
  resolve({
71
119
  stdout: Buffer.concat(stdout).toString('utf8'),
@@ -73,6 +121,7 @@ function captureProcessOutput(child, signal, timeoutMs, shell) {
73
121
  combinedOutput: Buffer.concat(combinedOutput),
74
122
  exitCode: exitCode ?? undefined,
75
123
  timedOut,
124
+ ...(timeoutKind === undefined ? {} : { timeoutKind }),
76
125
  ...(overflowed
77
126
  ? {
78
127
  failureKind: 'output-limit',
@@ -82,17 +131,51 @@ function captureProcessOutput(child, signal, timeoutMs, shell) {
82
131
  });
83
132
  });
84
133
  });
134
+ return { result, cancel };
85
135
  }
86
- function terminate(child, shell = false) {
136
+ async function terminateGracefully(child, shell, cancellationGraceMs) {
137
+ if (child.exitCode !== null || child.signalCode !== null)
138
+ return;
139
+ terminate(child, shell, 'SIGTERM');
140
+ // Windows does not distinguish these signals, so its SIGTERM already has
141
+ // immediate-kill semantics and waiting would not make cancellation gentler.
142
+ if (process.platform === 'win32')
143
+ return;
144
+ await waitForExit(child, cancellationGraceMs ?? 0);
145
+ if (child.exitCode === null && child.signalCode === null)
146
+ terminate(child, shell, 'SIGKILL');
147
+ }
148
+ function terminate(child, shell, signal) {
149
+ if (shell && process.platform === 'win32' && child.pid !== undefined) {
150
+ const taskkill = spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
151
+ stdio: 'ignore',
152
+ windowsHide: true,
153
+ });
154
+ taskkill.unref();
155
+ return;
156
+ }
87
157
  if (shell && process.platform !== 'win32' && child.pid !== undefined) {
88
158
  try {
89
- process.kill(-child.pid);
159
+ process.kill(-child.pid, signal);
90
160
  return;
91
161
  }
92
162
  catch {
93
163
  // The process may have already exited; fall through to the direct signal.
94
164
  }
95
165
  }
96
- if (!child.killed && child.exitCode === null)
97
- child.kill();
166
+ if (child.exitCode === null && child.signalCode === null)
167
+ child.kill(signal);
168
+ }
169
+ function waitForExit(child, timeoutMs) {
170
+ if (child.exitCode !== null || child.signalCode !== null)
171
+ return Promise.resolve();
172
+ return new Promise((resolve) => {
173
+ const timeout = setTimeout(done, timeoutMs);
174
+ child.once('exit', done);
175
+ function done() {
176
+ clearTimeout(timeout);
177
+ child.removeListener('exit', done);
178
+ resolve();
179
+ }
180
+ });
98
181
  }
@@ -4,7 +4,7 @@ import { ExecutionCancellationReason, RunStatus } from '../../contracts/vocabula
4
4
  import { runProcess } from '../process-execution.js';
5
5
  export function createClaudeRunner(options = {}) {
6
6
  return cliRunner('claude', options.command ?? 'claude', (request) => claudeCommandArgs(request, options.args, options), {
7
- ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
7
+ ...(options.runnerTimeouts === undefined ? {} : { runnerTimeouts: options.runnerTimeouts }),
8
8
  ...(options.model === undefined ? {} : { defaultModel: options.model }),
9
9
  parseSuccessfulOutput: parseClaudeOutput,
10
10
  classifyFailure: classifyClaudeFailure,
@@ -93,7 +93,10 @@ export function cliRunner(name, command, args, options = {}) {
93
93
  return {
94
94
  supportsSessionResume: options.supportsSessionResume === true,
95
95
  async start(request, signal) {
96
- const process = runProcess(command, args(request), request.workspacePath, signal, options.timeoutMs);
96
+ const process = runProcess(command, args(request), request.workspacePath, signal, {
97
+ ...options.runnerTimeouts,
98
+ ...(request.onTimeout === undefined ? {} : { onTimeout: request.onTimeout }),
99
+ });
97
100
  return {
98
101
  identity: {
99
102
  kind: ExternalExecutionKind.Process,
@@ -124,8 +127,12 @@ export function cliRunner(name, command, args, options = {}) {
124
127
  function failureFor(value, options) {
125
128
  if (value.timedOut)
126
129
  return {
127
- kind: ExecutionCancellationReason.Timeout,
128
- message: `Runner timed out after ${options.timeoutMs}ms`,
130
+ kind: value.timeoutKind === 'idle'
131
+ ? ExecutionCancellationReason.IdleTimeout
132
+ : ExecutionCancellationReason.Timeout,
133
+ message: value.timeoutKind === 'idle'
134
+ ? timeoutMessage('idle', options.runnerTimeouts?.idleMs)
135
+ : timeoutMessage('hard', options.runnerTimeouts?.hardMs),
129
136
  };
130
137
  if (value.failureKind !== undefined)
131
138
  return {
@@ -137,6 +144,15 @@ function failureFor(value, options) {
137
144
  return classified;
138
145
  return { kind: 'process-exit', message: value.stderr || `exit ${value.exitCode}` };
139
146
  }
147
+ function timeoutMessage(kind, timeoutMs) {
148
+ if (timeoutMs === undefined)
149
+ return kind === 'idle'
150
+ ? 'Runner exceeded its idle timeout'
151
+ : 'Runner exceeded its hard timeout';
152
+ return kind === 'idle'
153
+ ? `Runner was idle for ${timeoutMs}ms`
154
+ : `Runner exceeded the hard timeout of ${timeoutMs}ms`;
155
+ }
140
156
  function parseSuccessfulOutput(stdout, request, parser) {
141
157
  if (parser === undefined)
142
158
  return {};
@@ -38,7 +38,7 @@ function extractCodexErrorMessage(stdout) {
38
38
  }
39
39
  export function createCodexRunner(options = {}) {
40
40
  return cliRunner('codex', options.command ?? 'codex', (request) => codexCommandArgs(request, options.args, options), {
41
- ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
41
+ ...(options.runnerTimeouts === undefined ? {} : { runnerTimeouts: options.runnerTimeouts }),
42
42
  ...(options.model === undefined ? {} : { defaultModel: options.model }),
43
43
  parseSuccessfulOutput: parseCodexOutput,
44
44
  classifyFailure: classifyCodexFailure,
@@ -1,4 +1,4 @@
1
1
  import { cliRunner } from './claude.js';
2
- export function createCommandRunner(command, args, timeoutMs) {
3
- return cliRunner('command', command, () => [...args], { timeoutMs });
2
+ export function createCommandRunner(command, args, runnerTimeouts) {
3
+ return cliRunner('command', command, () => [...args], { runnerTimeouts });
4
4
  }
@@ -18,7 +18,7 @@ export function classifyCursorFailure(input) {
18
18
  }
19
19
  export function createCursorRunner(options = {}) {
20
20
  return cliRunner('cursor', options.command ?? 'cursor', (request) => cursorCommandArgs(request, options.args, options), {
21
- ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
21
+ ...(options.runnerTimeouts === undefined ? {} : { runnerTimeouts: options.runnerTimeouts }),
22
22
  ...(options.model === undefined ? {} : { defaultModel: options.model }),
23
23
  parseSuccessfulOutput: parseCursorOutput,
24
24
  classifyFailure: classifyCursorFailure,
@@ -1,7 +1,7 @@
1
1
  import { runProcess } from '../process-execution.js';
2
2
  const prepareOutputTailBytes = 4096;
3
3
  export async function prepareWorkspace(path, hook) {
4
- const process = runProcess(hook.command, [], path, new AbortController().signal, hook.timeoutMs, true);
4
+ const process = runProcess(hook.command, [], path, new AbortController().signal, { hardMs: hook.timeoutMs }, true);
5
5
  const result = await process.result;
6
6
  if (result.exitCode === 0 && !result.timedOut && result.failureKind === undefined)
7
7
  return;
@@ -6,21 +6,30 @@ export class PollService {
6
6
  this.journal = journal;
7
7
  this.instance = instance;
8
8
  }
9
- /** Resolves to the count of newly appended drafts, so callers can tell activity from a quiet poll. */
9
+ /** Persists every independently durable draft and reports partial progress. */
10
10
  async pollOnce(signal) {
11
+ const adapter = this.instance.adapter;
11
12
  const drafts = await this.instance.source.poll(signal);
12
13
  let appended = 0;
14
+ let failed = 0;
13
15
  for (const draft of drafts) {
14
- if (!this.instance.eventTypes.includes(draft.eventType))
15
- throw new Error(`Provider ${this.instance.adapter} emitted an unknown event type`);
16
- const stream = integrationStream(this.instance.adapter);
17
- const existing = await this.journal.readStream(stream);
18
- if (existing.some((event) => event.eventId === draft.eventId))
19
- continue;
20
- await this.journal.append(stream, existing.length, [{ ...draft, stream }]);
21
- appended += 1;
16
+ try {
17
+ if (!this.instance.eventTypes.includes(draft.eventType))
18
+ throw new Error(`Provider ${adapter} emitted an unknown event type`);
19
+ const stream = integrationStream(adapter);
20
+ const existing = await this.journal.readStream(stream);
21
+ if (existing.some((event) => event.eventId === draft.eventId))
22
+ continue;
23
+ await this.journal.append(stream, existing.length, [{ ...draft, stream }]);
24
+ appended += 1;
25
+ }
26
+ catch (error) {
27
+ failed += 1;
28
+ console.error(`Polling ${adapter} could not persist ${draft.eventId}`, error);
29
+ }
22
30
  }
23
- await this.instance.source.markPollPersisted?.();
24
- return appended;
31
+ if (failed === 0)
32
+ await this.instance.source.markPollPersisted?.();
33
+ return { appended, failed };
25
34
  }
26
35
  }
@@ -32,6 +32,7 @@ export class FakeInboundTranslator {
32
32
  this.services = services;
33
33
  }
34
34
  async runOnce(limit = 100) {
35
+ await this.services.resources.retryPendingWorkCorrelations();
35
36
  const checkpoint = `reactor:integration.${this.adapter}.inbound`;
36
37
  const events = await this.services.journal.readAll(await this.services.checkpoints.load(checkpoint), limit);
37
38
  for (const event of events) {
@@ -88,8 +89,18 @@ export class FakeInboundTranslator {
88
89
  if (existing === null)
89
90
  return false;
90
91
  const correlation = (await this.services.resources.correlations(existing.resourceId)).find((candidate) => candidate.role === ResourceCorrelationRole.Primary);
91
- if (correlation === undefined)
92
- throw new Error(`Resource ${existing.resourceId} lacks a primary work correlation`);
92
+ if (correlation === undefined) {
93
+ if (existing.revision !== evidence.revision)
94
+ await this.services.resources.discover({
95
+ resourceId: existing.resourceId,
96
+ kind: existing.kind,
97
+ externalKey,
98
+ capabilities: existing.capabilities,
99
+ ...(evidence.revision === undefined ? {} : { revision: evidence.revision }),
100
+ }, context);
101
+ await this.services.resources.noteMissingPrimaryCorrelation(existing.resourceId, 'Resource has no active primary WorkItem correlation', context);
102
+ return true;
103
+ }
93
104
  if (existing.revision !== evidence.revision)
94
105
  await this.services.resources.discover({
95
106
  resourceId: existing.resourceId,