@@ -850,15 +850,17 @@ function failedTimelineRunIds(
850850/**
851851 * Settled turns fold activity before their terminal assistant message behind
852852 * a "Worked for ..." row. Ordinary trailing work joins the fold, while failures
853- * and work still in progress stay visible. A thread without runs (a
854- * provider-native subagent) folds each prompt's response the same way.
853+ * and work still in progress stay visible. A prompt without a run (a
854+ * provider-native subagent, or a turn imported from V1) folds its response
855+ * the same way.
855856 */
856857function deriveTurnFolds ( input : {
857858 timelineEntries : ReadonlyArray < TimelineEntry > ;
858859 terminalAssistantMessageIds : ReadonlySet < string > ;
859860 latestRun : TimelineLatestRun | null ;
860861 unfoldedRunIds : ReadonlySet < RunId > ;
861- isWorking : boolean ;
862+ /** Keeps the latest runless response open; V2 work must not reopen imported turns. */
863+ runlessWorkActive : boolean ;
862864} ) : ReadonlyMap < string , TurnFold > {
863865 const interruptedRunIds = new Set < RunId > ( ) ;
864866 for ( const entry of input . timelineEntries ) {
@@ -888,8 +890,9 @@ function deriveTurnFolds(input: {
888890 const groupsByRunId = new Map < RunId , TurnGroup > ( ) ;
889891 const runlessFailedKeys = new Set < RunId > ( ) ;
890892
891- // Fold state is keyed by run, so each prompt of a runless thread lends its
892- // response a stable key of its own.
893+ // Fold state is keyed by run, so each runless prompt lends its response a
894+ // stable key of its own. Decide per prompt, not per thread: a V1 thread's
895+ // first V2 run must not unfold every imported turn above it.
893896 let runlessKey : RunId | null = null ;
894897 let pendingBoundary : { createdAt : string ; anchorEntryId : string } | null = null ;
895898 for ( const [ index , entry ] of input . timelineEntries . entries ( ) ) {
@@ -898,7 +901,13 @@ function deriveTurnFolds(input: {
898901 pendingBoundary = nextEntry
899902 ? { createdAt : entry . createdAt , anchorEntryId : nextEntry . id }
900903 : null ;
901- runlessKey = input . latestRun === null ? RunId . make ( `runless:${ entry . id } ` ) : null ;
904+ const boundaryRunId =
905+ entry . kind === "message"
906+ ? entry . message . runId
907+ : entry . kind === "work"
908+ ? entry . entry . runId
909+ : null ;
910+ runlessKey = boundaryRunId == null ? RunId . make ( `runless:${ entry . id } ` ) : null ;
902911 continue ;
903912 }
904913 const runId = timelineEntryFoldRunId ( entry , runlessKey ) ;
@@ -940,7 +949,7 @@ function deriveTurnFolds(input: {
940949 input . unfoldedRunIds . has ( runId ) ||
941950 interruptedRunIds . has ( runId ) ||
942951 runlessFailedKeys . has ( runId ) ||
943- ( input . isWorking && runId === runlessKey )
952+ ( input . runlessWorkActive && runId === runlessKey )
944953 ) {
945954 continue ;
946955 }
@@ -1229,12 +1238,13 @@ export function deriveMessagesTimelineRows(input: {
12291238 unsettledRunId,
12301239 isWorking : input . isWorking ,
12311240 } ) ;
1241+ const runlessWorkActive = input . isWorking && input . runlessWorkActive === true ;
12321242 const foldsByAnchorEntryId = deriveTurnFolds ( {
12331243 timelineEntries : timelineEntries ,
12341244 terminalAssistantMessageIds,
12351245 latestRun : input . latestRun ?? null ,
12361246 unfoldedRunIds : new Set ( [ ...activeVisualResponseRunIds , ...failedRunIds ] ) ,
1237- isWorking : input . isWorking ,
1247+ runlessWorkActive ,
12381248 } ) ;
12391249 const collapsedEntryIds = new Set < string > ( ) ;
12401250 for ( const fold of foldsByAnchorEntryId . values ( ) ) {
@@ -1252,7 +1262,6 @@ export function deriveMessagesTimelineRows(input: {
12521262 }
12531263 }
12541264 }
1255- const runlessWorkActive = input . isWorking && input . runlessWorkActive === true ;
12561265 const runIdIsActiveResponse = ( runId : RunId | null | undefined ) =>
12571266 runId == null ? runlessWorkActive : activeVisualResponseRunIds . has ( runId ) ;
12581267 const workEntryIsInActiveRun = ( entry : WorkLogEntry ) =>
0 commit comments