fix(orchestration-v2): protect pending Claude resumes
This commit is contained in:
1 parent
d45c3e7f9a
commit
c99767e518
2 files changed
+33
-2
No files matched your search
@@ -87,6 +87,7 @@ const CLAUDE_TEST_RUNTIME_POLICY = ProviderAdapterV2RuntimePolicy.make({
|
||||
type TestClaudeSubagentRegistryEntry = {
|
||||
readonly task: { readonly status: "running" | "waiting" | "completed" };
|
||||
readonly activation: { readonly id: string };
|
||||
readonly resumePending?: boolean;
|
||||
};
|
||||
|
||||
function testRegistryEntry(
|
||||
@@ -165,6 +166,32 @@ describe("ClaudeAdapterV2 subagent registry", () => {
|
||||
assert.strictEqual((yield* Ref.get(registry)).get("task-race"), terminal);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rejects a stale terminal update while a resume is pending activation", () =>
|
||||
Effect.gen(function* () {
|
||||
const observed = testRegistryEntry("running", "activation-1");
|
||||
const resumePending = {
|
||||
...testRegistryEntry("running", "activation-1"),
|
||||
resumePending: true,
|
||||
};
|
||||
const staleTerminal = testRegistryEntry("completed", "activation-1");
|
||||
const registry = yield* Ref.make(
|
||||
new Map<string, TestClaudeSubagentRegistryEntry>([["task-race", resumePending]]),
|
||||
);
|
||||
|
||||
const committed = yield* commitClaudeSubagentRegistryEntry({
|
||||
registry,
|
||||
taskId: "task-race",
|
||||
observed,
|
||||
candidate: staleTerminal,
|
||||
activeStart: false,
|
||||
isReopen: false,
|
||||
});
|
||||
|
||||
assert.isFalse(committed);
|
||||
assert.strictEqual((yield* Ref.get(registry)).get("task-race"), resumePending);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
describe("ClaudeAdapterV2 background-work status", () => {
|
||||
|
||||
@@ -2201,6 +2201,7 @@ interface ActiveClaudeProviderRetry {
|
||||
interface ClaudeSubagentRegistryEntry {
|
||||
readonly task: Pick<OrchestrationV2Subagent, "status">;
|
||||
readonly activation: { readonly id: string };
|
||||
readonly resumePending?: boolean;
|
||||
}
|
||||
|
||||
export const commitClaudeSubagentRegistryEntry = Effect.fnUntraced(function* <
|
||||
@@ -2224,10 +2225,13 @@ export const commitClaudeSubagentRegistryEntry = Effect.fnUntraced(function* <
|
||||
registered !== undefined &&
|
||||
input.observed !== undefined &&
|
||||
registered.activation.id === input.observed.activation.id;
|
||||
// Wake buffering marks a resume before its task_started replay can open
|
||||
// the next activation. The retained activation id belongs to the settled
|
||||
// generation, so no terminal update is valid during that handoff.
|
||||
if (
|
||||
(!input.activeStart &&
|
||||
registered !== input.observed &&
|
||||
(registeredSettled || !sameObservedActivation)) ||
|
||||
(registered?.resumePending === true ||
|
||||
(registered !== input.observed && (registeredSettled || !sameObservedActivation)))) ||
|
||||
(registeredSettled && input.activeStart && !(input.isReopen && registered === input.observed))
|
||||
) {
|
||||
return [false, current] as const;
|
||||
|
||||
Reference in new issue
Block a user