@@ -115,7 +115,9 @@ function respond(request) {
115115 const text = request.params.prompt.map(block => block.text ?? "").join("");
116116 if (text !== "no-accept") update({sessionUpdate: "session_info_update", _meta: {"executablemd.session-materialization/v1": {state: "accepted"}}});
117117 update({sessionUpdate: "agent_message_chunk", content: {type: "text", text: "answer:" + text}});
118- if (text === "fail") {
118+ if (text === "diagnostic") {
119+ send({jsonrpc: "2.0", id: request.id, error: {code: -32041, message: "Internal error", data: {details: "/work/project: adapter unavailable", authorization: "excluded raw field"}}});
120+ } else if (text === "fail") {
119121 send({jsonrpc: "2.0", id: request.id, error: {code: -32000, message: "backend refusal"}});
120122 } else {
121123 reply(request.id, {stopReason: text === "cancel" ? "cancelled" : "end_turn", _meta: {codex: {turnId: "turn-" + text}, opaque: {left: [3, null]}}});
@@ -403,6 +405,60 @@ describe(
403405 }
404406 } ) ;
405407
408+ it ( "1039 A1/A5: real protocol failure details reach the terminal Error" , function * ( ) {
409+ const current = yield * runtimeWorld ( ) ;
410+ const turn = current . runtime . startTurn ( {
411+ handle : current . handle ,
412+ text : "diagnostic" ,
413+ mode : "prompt" ,
414+ requestId : "actual-request" ,
415+ } ) ;
416+ const channel = createChannel < import ( "@executablemd/core" ) . AgentPromptEvent , string > ( ) ;
417+ const subscription = yield * channel ;
418+ const consumer = yield * spawn ( ( ) =>
419+ consumeTurn (
420+ turn ,
421+ { agent : "scribe" , session : { sessionKey : "released" , cwd : current . dir } } ,
422+ channel ,
423+ ( ) => { } ,
424+ ) ,
425+ ) ;
426+ const events = [ ] ;
427+ let next = yield * subscription . next ( ) ;
428+ while ( ! next . done ) {
429+ events . push ( next . value ) ;
430+ next = yield * subscription . next ( ) ;
431+ }
432+ yield * consumer ;
433+ expect ( next . value ) . toBe ( "answer:diagnostic" ) ;
434+ const terminal = events . find ( ( event ) => event . type === "terminal" ) ;
435+ const result = yield * until ( turn . result ) ;
436+ expect ( result ) . toMatchObject ( {
437+ status : "failed" ,
438+ error : {
439+ origin : "runtime" ,
440+ acp : { code : - 32041 , details : "/work/project: adapter unavailable" } ,
441+ } ,
442+ } ) ;
443+ expect ( JSON . stringify ( result ) ) . not . toContain ( "excluded raw field" ) ;
444+ expect ( terminal ?. error ?. message ) . toBe ( "Internal error" ) ;
445+ expect (
446+ terminal ?. error && Reflect . get ( terminal . error , "executablemd.agent.prompt-diagnostic" ) ,
447+ ) . toEqual ( {
448+ provider : "acp" ,
449+ operation : "session/prompt" ,
450+ stage : "runtime-turn" ,
451+ requestId : "actual-request" ,
452+ code : "RUNTIME" ,
453+ origin : "runtime" ,
454+ acp : {
455+ code : - 32041 ,
456+ message : "Internal error" ,
457+ details : "/work/project: adapter unavailable" ,
458+ } ,
459+ } ) ;
460+ } ) ;
461+
406462 it ( "a final save failure keeps the returned reply inspectable and does not reprompt" , function * ( ) {
407463 const current = yield * world ( ) ;
408464 let fail = true ;
0 commit comments