Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/refresh-prepared-petri-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashintel/brunch": patch
---

Refresh prepared run metadata before reconciling direct lifecycle steps.
24 changes: 24 additions & 0 deletions src/executor/__tests__/orchestrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3623,6 +3623,30 @@ describe('drive', () => {
});
});

it('refreshes prepared metadata before reconciling a direct lifecycle step', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'brunch-drive-preparation-refresh-'));
await createRunAtCreated(cwd, ['task-1']);
await createWorktree({ cwd, runId: 'run-1', gitWorktree: createFakeGitWorktreePort() });

await expect(
drive({ cwd, runId: 'run-1', ports: fakePorts() }, linearScheduler, serialFiringPolicy, {
maxFirings: 1,
}),
).resolves.toEqual({
status: 'completed',
runStatus: 'worktree_populated',
});
await expect(readRunMetadata(runMetadataPath(cwd, 'run-1'))).resolves.toMatchObject({
status: 'worktree_populated',
petriObservationPrepared: true,
});
expect(
(await readPetriEvents(cwd)).flatMap((event) =>
event.kind === 'transition_fired' ? [event.transitionId] : [],
),
).toEqual(['worktree_create', 'populate']);
});

it('halts and repairs when lifecycle catch-up cannot persist its marking', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'brunch-drive-reconcile-marking-failure-'));
await createRunAtCreated(cwd, ['task-1']);
Expand Down
5 changes: 4 additions & 1 deletion src/executor/orchestrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async function driveOwned(
// unchanged is treated as stuck. Replace with per-step outcome classification
// if steps gain retry/abort semantics beyond advance-or-hold.
driveLoop: for (;;) {
const state = await readRunMetadata(metadataPath);
let state = await readRunMetadata(metadataPath);
if (!state) return { status: 'missing_run', runId: ctx.runId };
if (options.maxFirings !== undefined && firedTransitions >= options.maxFirings) {
return { status: 'completed', runStatus: state.status };
Expand Down Expand Up @@ -448,6 +448,9 @@ async function driveOwned(
observationPreparationAttempted = true;
try {
plan = await preparePetriObservation({ cwd: ctx.cwd, runId: ctx.runId });
const preparedState = await readRunMetadata(metadataPath);
if (!preparedState) return { status: 'missing_run', runId: ctx.runId };
state = preparedState;
} catch (error) {
const terminal = classifyDriveTerminal({
kind: 'step_halted',
Expand Down
Loading