Skip to content

Commit b9b87e3

Browse files
committed
Stop service adoptee before running cascade:true deps (behind flag)
WIP: adds early adoptee stop logic in _execute(); will be gated behind a per-dependency flag (name TBD, e.g. preStop) before finalising. https://claude.ai/code/session_01Be7upyt3ZRNdHuhyi1W7eF
1 parent b9011ec commit b9b87e3

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/execution/service.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,34 @@ export class ServiceScriptExecution extends BaseExecutionWithCommand<ServiceScri
360360
void this.abort();
361361
});
362362

363+
const adoptee = this.#state.adoptee;
364+
// If any dependency has cascade:true, stop the adoptee before running
365+
// deps so they can freely write to files the service may have open.
366+
const shouldStopAdopteeEarly =
367+
adoptee !== undefined &&
368+
this._config.dependencies.some((dep) => dep.cascade);
369+
363370
this.#state = {
364371
id: 'executingDeps',
365372
deferredFingerprint: new Deferred(),
366-
adoptee: this.#state.adoptee,
373+
adoptee: shouldStopAdopteeEarly ? undefined : adoptee,
367374
};
368-
void this._executeDependencies().then((result) => {
369-
if (result.ok) {
370-
this.#onDepsExecuted(result.value);
371-
} else {
372-
this.#onDepExecErr(result);
375+
376+
void (shouldStopAdopteeEarly
377+
? adoptee.abort()
378+
: Promise.resolve()
379+
).then(() => {
380+
if (this.#state.id !== 'executingDeps') {
381+
// Service was aborted while waiting for the adoptee to stop.
382+
return;
373383
}
384+
void this._executeDependencies().then((result) => {
385+
if (result.ok) {
386+
this.#onDepsExecuted(result.value);
387+
} else {
388+
this.#onDepExecErr(result);
389+
}
390+
});
374391
});
375392
return this.#state.deferredFingerprint.promise;
376393
}

0 commit comments

Comments
 (0)