Skip to content

Commit 42a4625

Browse files
authored
fix(update): keep a committed post-core result when stopping the child signals (#125150)
* fix(update): keep a committed post-core result when stopping the child signals The post-core wait settles from three places: a result-file poll, child "error", and child "exit". The poll stopped the child before claiming the settle, and stopping delivers a signal, so the still-unclaimed exit handler could reject with "post-update process terminated by signal SIGTERM" for an update whose child had already written a valid result. The outer catch then restored the tentative plugin index, rolling back work that actually succeeded. Claim the settle first, then stop. The exit handler sees settled and returns. Net zero production lines; pure reordering plus the invariant comment. This is the error that leaked across tests in the agentic-cli shard on 2026-08-17 (run 31997770370), where it surfaced inside an unrelated test and cascaded into 34 failures in src/cli/update-cli.test.ts. Regression test drives the exact ordering: the child commits its result, then the parent's stop delivers SIGTERM. It fails on pre-fix code with "promise rejected ... instead of resolving / post-update process terminated by signal SIGTERM". * test(update): satisfy strict indexed access in the post-core signal regression
1 parent d6b2e14 commit 42a4625

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎src/cli/update-cli.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,30 @@ describe("update-cli", () => {
22172217
);
22182218
});
22192219

2220+
it("honors a committed post-core result when stopping the child delivers a signal", async () => {
2221+
// The poll owns the settle: it stops the child only after claiming the result. Stopping
2222+
// delivers SIGTERM, so an unclaimed exit handler would reject an update the child already
2223+
// committed and then roll its plugin index back.
2224+
const { root } = setupUpdatedRootRefresh();
2225+
readPackageVersion.mockImplementation(async (pkgRoot: string) =>
2226+
pkgRoot === root ? "0.0.1" : "2026.5.28",
2227+
);
2228+
spawn.mockImplementationOnce((_command: string, _args: string[], options: unknown) => {
2229+
const child = new EventEmitter() as EventEmitter & { kill: () => void };
2230+
const resultPath = expectDefined(
2231+
(options as { env: Record<string, string> }).env["OPENCLAW_UPDATE_POST_CORE_RESULT_PATH"],
2232+
"post-core result path test invariant",
2233+
);
2234+
fsSync.writeFileSync(resultPath, JSON.stringify({ status: "ok" }), "utf8");
2235+
child.kill = () => {
2236+
child.emit("exit", null, "SIGTERM");
2237+
};
2238+
return child;
2239+
});
2240+
2241+
await expect(updateCommand({ yes: true, restart: false })).resolves.not.toThrow();
2242+
});
2243+
22202244
it("keeps a child-committed plugin index when the post-core handoff is signaled", async () => {
22212245
const { root } = setupUpdatedRootRefresh();
22222246
readPackageVersion.mockImplementation(async (pkgRoot: string) =>

‎src/cli/update-cli/update-command-post-core.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,11 @@ export async function continuePostCoreUpdateInFreshProcess(params: {
614614
if (!pluginUpdate) {
615615
return;
616616
}
617-
stopPostCoreUpdateChild(child);
617+
// Claim the settle before stopping: the stop delivers a signal, and the exit
618+
// handler below rejects on any signal it still owns. Stopping first would fail
619+
// an update this child already committed and roll its plugin index back.
618620
finish({ kind: "plugin-update", pluginUpdate });
621+
stopPostCoreUpdateChild(child);
619622
})
620623
.catch(() => undefined);
621624
}, POST_CORE_UPDATE_RESULT_POLL_MS);

0 commit comments

Comments
 (0)