@@ -10,7 +10,7 @@ import {
1010 setDetachedTaskDeliveryStatusByRunId ,
1111 startTaskRunByRunId ,
1212} from "./task-executor.js" ;
13- import { findTaskByRunId , resetTaskRegistryForTests } from "./task-registry.js" ;
13+ import { getTaskById , resetTaskRegistryForTests } from "./task-registry.js" ;
1414
1515const ORIGINAL_STATE_DIR = process . env . OPENCLAW_STATE_DIR ;
1616const hoisted = vi . hoisted ( ( ) => {
@@ -67,8 +67,7 @@ describe("task-executor", () => {
6767 await withTaskExecutorStateDir ( async ( ) => {
6868 const created = createQueuedTaskRun ( {
6969 runtime : "acp" ,
70- ownerKey : "agent:main:main" ,
71- scopeKind : "session" ,
70+ requesterSessionKey : "agent:main:main" ,
7271 childSessionKey : "agent:codex:acp:child" ,
7372 runId : "run-executor-queued" ,
7473 task : "Investigate issue" ,
@@ -90,7 +89,7 @@ describe("task-executor", () => {
9089 terminalSummary : "Done." ,
9190 } ) ;
9291
93- expect ( findTaskByRunId ( "run-executor-queued" ) ) . toMatchObject ( {
92+ expect ( getTaskById ( created . taskId ) ) . toMatchObject ( {
9493 taskId : created . taskId ,
9594 status : "succeeded" ,
9695 startedAt : 100 ,
@@ -104,8 +103,7 @@ describe("task-executor", () => {
104103 await withTaskExecutorStateDir ( async ( ) => {
105104 const created = createRunningTaskRun ( {
106105 runtime : "subagent" ,
107- ownerKey : "agent:main:main" ,
108- scopeKind : "session" ,
106+ requesterSessionKey : "agent:main:main" ,
109107 childSessionKey : "agent:codex:subagent:child" ,
110108 runId : "run-executor-fail" ,
111109 task : "Write summary" ,
@@ -131,7 +129,7 @@ describe("task-executor", () => {
131129 deliveryStatus : "failed" ,
132130 } ) ;
133131
134- expect ( findTaskByRunId ( "run-executor-fail" ) ) . toMatchObject ( {
132+ expect ( getTaskById ( created . taskId ) ) . toMatchObject ( {
135133 taskId : created . taskId ,
136134 status : "failed" ,
137135 progressSummary : "Collecting results" ,
@@ -145,8 +143,7 @@ describe("task-executor", () => {
145143 await withTaskExecutorStateDir ( async ( ) => {
146144 const created = createRunningTaskRun ( {
147145 runtime : "acp" ,
148- ownerKey : "agent:main:main" ,
149- scopeKind : "session" ,
146+ requesterSessionKey : "agent:main:main" ,
150147 requesterOrigin : {
151148 channel : "telegram" ,
152149 to : "telegram:123" ,
@@ -167,7 +164,7 @@ describe("task-executor", () => {
167164 terminalSummary : "Writable session required." ,
168165 } ) ;
169166
170- expect ( findTaskByRunId ( "run-executor-blocked" ) ) . toMatchObject ( {
167+ expect ( getTaskById ( created . taskId ) ) . toMatchObject ( {
171168 taskId : created . taskId ,
172169 status : "succeeded" ,
173170 terminalOutcome : "blocked" ,
@@ -182,8 +179,7 @@ describe("task-executor", () => {
182179
183180 const child = createRunningTaskRun ( {
184181 runtime : "acp" ,
185- ownerKey : "agent:main:main" ,
186- scopeKind : "session" ,
182+ requesterSessionKey : "agent:main:main" ,
187183 childSessionKey : "agent:codex:acp:child" ,
188184 runId : "run-linear-cancel" ,
189185 task : "Inspect a PR" ,
@@ -200,7 +196,7 @@ describe("task-executor", () => {
200196 found : true ,
201197 cancelled : true ,
202198 } ) ;
203- expect ( findTaskByRunId ( "run-linear-cancel" ) ) . toMatchObject ( {
199+ expect ( getTaskById ( child . taskId ) ) . toMatchObject ( {
204200 taskId : child . taskId ,
205201 status : "cancelled" ,
206202 } ) ;
@@ -221,8 +217,7 @@ describe("task-executor", () => {
221217
222218 const child = createRunningTaskRun ( {
223219 runtime : "subagent" ,
224- ownerKey : "agent:main:main" ,
225- scopeKind : "session" ,
220+ requesterSessionKey : "agent:main:main" ,
226221 childSessionKey : "agent:codex:subagent:child" ,
227222 runId : "run-subagent-cancel" ,
228223 task : "Inspect a PR" ,
@@ -239,7 +234,7 @@ describe("task-executor", () => {
239234 found : true ,
240235 cancelled : true ,
241236 } ) ;
242- expect ( findTaskByRunId ( "run-subagent-cancel" ) ) . toMatchObject ( {
237+ expect ( getTaskById ( child . taskId ) ) . toMatchObject ( {
243238 taskId : child . taskId ,
244239 status : "cancelled" ,
245240 } ) ;
@@ -249,4 +244,42 @@ describe("task-executor", () => {
249244 } ) ;
250245 } ) ;
251246 } ) ;
247+
248+ it ( "scopes run-id updates to the matching runtime and session" , async ( ) => {
249+ await withTaskExecutorStateDir ( async ( ) => {
250+ const victim = createRunningTaskRun ( {
251+ runtime : "acp" ,
252+ requesterSessionKey : "agent:victim:main" ,
253+ childSessionKey : "agent:victim:acp:child" ,
254+ runId : "run-shared-executor-scope" ,
255+ task : "Victim ACP task" ,
256+ deliveryStatus : "pending" ,
257+ } ) ;
258+ const attacker = createRunningTaskRun ( {
259+ runtime : "cli" ,
260+ requesterSessionKey : "agent:attacker:main" ,
261+ childSessionKey : "agent:attacker:main" ,
262+ runId : "run-shared-executor-scope" ,
263+ task : "Attacker CLI task" ,
264+ deliveryStatus : "not_applicable" ,
265+ } ) ;
266+
267+ failTaskRunByRunId ( {
268+ runId : "run-shared-executor-scope" ,
269+ runtime : "cli" ,
270+ sessionKey : "agent:attacker:main" ,
271+ endedAt : 40 ,
272+ lastEventAt : 40 ,
273+ error : "attacker controlled error" ,
274+ } ) ;
275+
276+ expect ( getTaskById ( attacker . taskId ) ) . toMatchObject ( {
277+ status : "failed" ,
278+ error : "attacker controlled error" ,
279+ } ) ;
280+ expect ( getTaskById ( victim . taskId ) ) . toMatchObject ( {
281+ status : "running" ,
282+ } ) ;
283+ } ) ;
284+ } ) ;
252285} ) ;
0 commit comments