@@ -258,6 +258,96 @@ describe("TaskService", () => {
258258 } ) ;
259259 } ) ;
260260
261+ describe ( "handleAgentReport" , ( ) => {
262+ it ( "should resolve awaiters even if parent history append fails" , async ( ) => {
263+ const parentWorkspaceId = "parent" ;
264+ const childWorkspaceId = "child" ;
265+
266+ const workspace = {
267+ id : childWorkspaceId ,
268+ path : "/tmp/agent" ,
269+ name : "agent" ,
270+ projectName : "proj" ,
271+ projectPath : "/proj" ,
272+ createdAt : "2025-01-01T00:00:00.000Z" ,
273+ parentWorkspaceId,
274+ agentType : "research" ,
275+ taskStatus : "running" ,
276+ taskModel : "openai:gpt-5-codex" ,
277+ } ;
278+
279+ const projects = new Map ( [
280+ [
281+ "/proj" ,
282+ {
283+ workspaces : [ workspace ] ,
284+ } ,
285+ ] ,
286+ ] ) ;
287+
288+ let idCounter = 0 ;
289+ const config = {
290+ generateStableId : ( ) => `id-${ idCounter ++ } ` ,
291+ getTaskSettings : ( ) => ( {
292+ maxParallelAgentTasks : 3 ,
293+ maxTaskNestingDepth : 3 ,
294+ } ) ,
295+ listWorkspaceConfigs : ( ) => [ ] ,
296+ getWorkspaceConfig : ( id : string ) => {
297+ if ( id !== childWorkspaceId ) {
298+ return null ;
299+ }
300+
301+ return { projectPath : "/proj" , workspace } ;
302+ } ,
303+ editConfig : ( edit : ( cfg : unknown ) => unknown ) => {
304+ edit ( { projects } ) ;
305+ } ,
306+ } ;
307+
308+ const historyService = {
309+ getHistory : ( _workspaceId : string ) => Ok ( [ ] ) ,
310+ appendToHistory : ( workspaceId : string , _message : MuxMessage ) => {
311+ if ( workspaceId === parentWorkspaceId ) {
312+ return Err ( "disk full" ) ;
313+ }
314+
315+ return Ok ( undefined ) ;
316+ } ,
317+ } ;
318+
319+ const partialService = {
320+ readPartial : ( ) => null ,
321+ writePartial : ( ) => Ok ( undefined ) ,
322+ } ;
323+
324+ const workspaceService = {
325+ emitChatEvent : ( _workspaceId : string , _event : unknown ) => undefined ,
326+ emitWorkspaceMetadata : ( _workspaceId : string ) => undefined ,
327+ remove : ( _workspaceId : string , _force ?: boolean ) => Ok ( undefined ) ,
328+ } ;
329+
330+ const aiService = {
331+ on : ( ) => undefined ,
332+ } ;
333+
334+ const service = new TaskService (
335+ config as never ,
336+ historyService as never ,
337+ partialService as never ,
338+ workspaceService as never ,
339+ aiService as never
340+ ) ;
341+
342+ const reportPromise = service . awaitAgentReport ( childWorkspaceId ) ;
343+
344+ await service . handleAgentReport ( childWorkspaceId , { reportMarkdown : "hello" } ) ;
345+
346+ expect ( await reportPromise ) . toEqual ( { reportMarkdown : "hello" } ) ;
347+ expect ( workspace . taskStatus ) . toBe ( "reported" ) ;
348+ } ) ;
349+ } ) ;
350+
261351 describe ( "onStreamEnd" , ( ) => {
262352 it ( "should finalize tasks when report enforcement resume fails" , async ( ) => {
263353 const parentWorkspaceId = "parent" ;
0 commit comments