@@ -19,6 +19,7 @@ import type {
1919 OrchestrationV2CheckpointScope ,
2020 OrchestrationV2ExecutionNode ,
2121 OrchestrationV2PlanArtifact ,
22+ OrchestrationV2PendingRuntimeRequestSummary ,
2223 PlanId ,
2324 OrchestrationV2ConversationMessage ,
2425 OrchestrationV2DomainEvent ,
@@ -1427,20 +1428,27 @@ function buildVisibleTurnItems(input: {
14271428 ] ) ;
14281429}
14291430
1431+ function pendingRuntimeRequestSummary (
1432+ request : OrchestrationV2ThreadProjection [ "runtimeRequests" ] [ number ] | null ,
1433+ ) : OrchestrationV2PendingRuntimeRequestSummary | null {
1434+ if ( request === null ) return null ;
1435+ return {
1436+ id : request . id ,
1437+ kind : request . kind ,
1438+ createdAt : request . createdAt ,
1439+ blocking : request . responseCapability . type !== "message" ,
1440+ } ;
1441+ }
1442+
14301443function secretRequestAsPendingInput (
14311444 item : OrchestrationV2TurnItem | null ,
1432- ) : OrchestrationV2ThreadProjection [ "runtimeRequests" ] [ number ] | null {
1445+ ) : OrchestrationV2PendingRuntimeRequestSummary | null {
14331446 if ( item ?. type !== "secret_request" || item . nodeId === null ) return null ;
14341447 return {
14351448 id : RuntimeRequestId . make ( item . id ) ,
1436- nodeId : item . nodeId ,
1437- providerTurnId : item . providerTurnId ,
1438- nativeRequestRef : null ,
14391449 kind : "user_input" ,
1440- status : "pending" ,
1441- responseCapability : { type : "message" } ,
14421450 createdAt : item . startedAt ?? item . updatedAt ,
1443- resolvedAt : null ,
1451+ blocking : true ,
14441452 } ;
14451453}
14461454
@@ -1469,27 +1477,31 @@ export function threadShellFromProjection(
14691477 . filter ( isActivityRunForShell )
14701478 . toSorted ( ( left , right ) => right . ordinal - left . ordinal ) [ 0 ] ?? null ;
14711479 const liveRunIds = new Set ( projection . runs . filter ( isActivityRunForShell ) . map ( ( run ) => run . id ) ) ;
1472- const pendingRuntimeRequest =
1480+ let pendingRuntimeRequest = pendingRuntimeRequestSummary (
14731481 projection . runtimeRequests
14741482 . filter ( ( request ) => request . status === "pending" )
14751483 . toSorted (
14761484 ( left , right ) =>
14771485 DateTime . toEpochMillis ( right . createdAt ) - DateTime . toEpochMillis ( left . createdAt ) ,
1478- ) [ 0 ] ??
1479- secretRequestAsPendingInput (
1480- projection . turnItems
1481- . filter (
1482- ( item ) =>
1483- item . type === "secret_request" &&
1484- item . status === "waiting" &&
1485- item . runId !== null &&
1486- liveRunIds . has ( item . runId ) ,
1487- )
1488- . toSorted (
1489- ( left , right ) =>
1490- DateTime . toEpochMillis ( right . updatedAt ) - DateTime . toEpochMillis ( left . updatedAt ) ,
1491- ) [ 0 ] ?? null ,
1492- ) ;
1486+ ) [ 0 ] ?? null ,
1487+ ) ;
1488+ if ( pendingRuntimeRequest === null || pendingRuntimeRequest . blocking === false ) {
1489+ pendingRuntimeRequest =
1490+ secretRequestAsPendingInput (
1491+ projection . turnItems
1492+ . filter (
1493+ ( item ) =>
1494+ item . type === "secret_request" &&
1495+ item . status === "waiting" &&
1496+ item . runId !== null &&
1497+ liveRunIds . has ( item . runId ) ,
1498+ )
1499+ . toSorted (
1500+ ( left , right ) =>
1501+ DateTime . toEpochMillis ( right . updatedAt ) - DateTime . toEpochMillis ( left . updatedAt ) ,
1502+ ) [ 0 ] ?? null ,
1503+ ) ?? pendingRuntimeRequest ;
1504+ }
14931505 const userMessages = projection . messages
14941506 . filter ( ( message ) => message . role === "user" )
14951507 . toSorted (
@@ -1546,14 +1558,7 @@ export function threadShellFromProjection(
15461558 latestRootProviderFailure ( latestRun , projection . turnItems ) ,
15471559 providerSession ?. lastError ?? null ,
15481560 ) ,
1549- pendingRuntimeRequest :
1550- pendingRuntimeRequest === null
1551- ? null
1552- : {
1553- id : pendingRuntimeRequest . id ,
1554- kind : pendingRuntimeRequest . kind ,
1555- createdAt : pendingRuntimeRequest . createdAt ,
1556- } ,
1561+ pendingRuntimeRequest,
15571562 // Thread detail owns message bodies. Keeping them out of shell rows makes
15581563 // initial hydration and streaming updates independent of transcript size.
15591564 latestVisibleMessage : null ,
@@ -1648,7 +1653,7 @@ type ShellThreadState = {
16481653 readonly lastError : string | null ;
16491654 readonly lastErrorClass : OrchestrationV2ThreadShell [ "lastErrorClass" ] ;
16501655 readonly usageLimitResetAt : OrchestrationV2ThreadShell [ "usageLimitResetAt" ] ;
1651- readonly pendingRuntimeRequest : OrchestrationV2ThreadProjection [ "runtimeRequests" ] [ number ] | null ;
1656+ readonly pendingRuntimeRequest : OrchestrationV2PendingRuntimeRequestSummary | null ;
16521657 readonly latestUserMessageAt : DateTime . Utc | null ;
16531658 readonly latestUserAuthoredMessageAt : DateTime . Utc | null ;
16541659 readonly hasActionableProposedPlan : boolean ;
@@ -1801,14 +1806,7 @@ function shellFromState(input: {
18011806 lastError : input . state . lastError ,
18021807 lastErrorClass : input . state . lastErrorClass ,
18031808 usageLimitResetAt : input . state . usageLimitResetAt ,
1804- pendingRuntimeRequest :
1805- input . state . pendingRuntimeRequest === null
1806- ? null
1807- : {
1808- id : input . state . pendingRuntimeRequest . id ,
1809- kind : input . state . pendingRuntimeRequest . kind ,
1810- createdAt : input . state . pendingRuntimeRequest . createdAt ,
1811- } ,
1809+ pendingRuntimeRequest : input . state . pendingRuntimeRequest ,
18121810 latestVisibleMessage : null ,
18131811 latestUserMessageAt : input . state . latestUserMessageAt ,
18141812 latestUserAuthoredMessageAt : input . state . latestUserAuthoredMessageAt ,
@@ -5791,14 +5789,21 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
57915789 pendingTurnItemsByThreadId,
57925790 } = input ;
57935791 const thread = yield * decodeThreadPayload ( row . payload_json ) ;
5794- const pendingRuntimeRequest =
5792+ let pendingRuntimeRequest =
57955793 row . pending_request_payload_json !== null
5796- ? yield * decodeRuntimeRequestPayload ( row . pending_request_payload_json )
5797- : row . pending_secret_request_payload_json !== null
5798- ? secretRequestAsPendingInput (
5799- yield * decodeTurnItemPayload ( row . pending_secret_request_payload_json ) ,
5800- )
5801- : null ;
5794+ ? pendingRuntimeRequestSummary (
5795+ yield * decodeRuntimeRequestPayload ( row . pending_request_payload_json ) ,
5796+ )
5797+ : null ;
5798+ if (
5799+ ( pendingRuntimeRequest === null || pendingRuntimeRequest . blocking === false ) &&
5800+ row . pending_secret_request_payload_json !== null
5801+ ) {
5802+ pendingRuntimeRequest =
5803+ secretRequestAsPendingInput (
5804+ yield * decodeTurnItemPayload ( row . pending_secret_request_payload_json ) ,
5805+ ) ?? pendingRuntimeRequest ;
5806+ }
58025807 let terminalFailureItem =
58035808 row . terminal_failure_payload_json === null
58045809 ? null
0 commit comments