@@ -374,6 +374,7 @@ import {
374374 useThreadProjection ,
375375 useThreadStatus ,
376376 useThreadHistory ,
377+ useQuietThreadShell ,
377378 useThreadShell ,
378379 useChildThreadInputs ,
379380 useThreadRefs ,
@@ -1108,7 +1109,7 @@ export default function ChatView(props: ChatViewProps) {
11081109 ? store . getDraftSession ( draftId )
11091110 : null ,
11101111 ) ;
1111- const serverThread = useThreadShell ( routeThreadRef ) ;
1112+ const serverThread = useQuietThreadShell ( routeThreadRef ) ;
11121113 const routeThreadDetailRef = resolveThreadDetailRef ( routeThreadRef , {
11131114 shellExists : serverThread !== null ,
11141115 waitForShell : draftThread !== null ,
@@ -1173,13 +1174,6 @@ export default function ChatView(props: ChatViewProps) {
11731174 }
11741175 return ids ;
11751176 } ) ( ) ;
1176- const markThreadVisited = useUiStateStore ( ( store ) => store . markThreadVisited ) ;
1177- const activeThreadLocalLastVisitedAt = useUiStateStore (
1178- ( store ) => store . threadLastVisitedAtById [ routeThreadKey ] ,
1179- ) ;
1180- const visitThreadMutation = useAtomCommand ( threadEnvironment . visit , { reportFailure : false } ) ;
1181- const lastDispatchedVisitRef = useRef < string | null > ( null ) ;
1182- const lastVisitDispatchAtRef = useRef ( 0 ) ;
11831177 const settings = useEnvironmentSettings ( environmentId ) ;
11841178 const clientSettingsHydrated = useClientSettingsHydrated ( ) ;
11851179 const setStickyComposerModelSelection = useComposerDraftStore (
@@ -1501,7 +1495,7 @@ export default function ChatView(props: ChatViewProps) {
15011495 }
15021496 return scopeThreadRef ( parentSubagentEnvironmentId , parentSubagentThreadId ) ;
15031497 } ) ( ) ;
1504- const parentSubagentThread = useThreadShell ( parentSubagentThreadRef ) ;
1498+ const parentSubagentThread = useQuietThreadShell ( parentSubagentThreadRef ) ;
15051499 const parentThreadLink =
15061500 parentSubagentThreadRef === null
15071501 ? null
@@ -1578,7 +1572,7 @@ export default function ChatView(props: ChatViewProps) {
15781572 container : workspaceLayoutElement ,
15791573 widthStorageKey : `t3code:preview-panel-width:${ activeThreadKey } ` ,
15801574 } ) ;
1581- const activeThreadShell = useThreadShell ( isServerThread ? activeThreadRef : null ) ;
1575+ const activeThreadShell = useQuietThreadShell ( isServerThread ? activeThreadRef : null ) ;
15821576 const timelineThreadError =
15831577 serverRuntime ?. status === "failed" &&
15841578 serverRuntime . lastErrorClass === "usage_limit" &&
@@ -2176,63 +2170,6 @@ export default function ChatView(props: ChatViewProps) {
21762170 } ;
21772171 const handlePreparedPullRequestThreadStable = useStableCallback ( handlePreparedPullRequestThread ) ;
21782172
2179- useEffect ( ( ) => {
2180- if ( ! serverThread ?. id ) return ;
2181- const threadUpdatedAt = Date . parse ( serverThread . updatedAt ) ;
2182- if ( Number . isNaN ( threadUpdatedAt ) ) return ;
2183- const effectiveLastVisitedAt = resolveThreadLastVisitedAt (
2184- serverThread . lastVisitedAt ,
2185- activeThreadLocalLastVisitedAt ,
2186- ) ;
2187- const lastVisitedAt = effectiveLastVisitedAt ? Date . parse ( effectiveLastVisitedAt ) : NaN ;
2188- if ( ! Number . isNaN ( lastVisitedAt ) && lastVisitedAt >= threadUpdatedAt ) return ;
2189-
2190- if ( serverThread . lastVisitedAt !== undefined ) {
2191- // Dedupe per watermark — the effect re-runs before the command's echo
2192- // lands. The dedupe also keeps a mark-unread on the open thread sticky:
2193- // the rewind leaves updatedAt untouched, so the already-dispatched key
2194- // skips a fresh visit until new activity lands or the thread is reopened.
2195- const dispatchKey = `${ routeThreadKey } :${ serverThread . updatedAt } ` ;
2196- if ( lastDispatchedVisitRef . current === dispatchKey ) return ;
2197- const dispatch = ( ) => {
2198- lastDispatchedVisitRef . current = dispatchKey ;
2199- lastVisitDispatchAtRef . current = Date . now ( ) ;
2200- void visitThreadMutation ( {
2201- environmentId : serverThread . environmentId ,
2202- input : { threadId : serverThread . id , visitedAt : serverThread . updatedAt } ,
2203- } ) ;
2204- } ;
2205- const latestRunCompletedAtMs = serverThread . latestRun ?. completedAt
2206- ? Date . parse ( serverThread . latestRun . completedAt )
2207- : NaN ;
2208- const hasUnseenCompletion =
2209- ! Number . isNaN ( latestRunCompletedAtMs ) &&
2210- ( Number . isNaN ( lastVisitedAt ) || latestRunCompletedAtMs > lastVisitedAt ) ;
2211- const elapsed = Date . now ( ) - lastVisitDispatchAtRef . current ;
2212- if ( hasUnseenCompletion || elapsed >= VISIT_DISPATCH_THROTTLE_MS ) {
2213- dispatch ( ) ;
2214- return ;
2215- }
2216- const timer = setTimeout ( dispatch , VISIT_DISPATCH_THROTTLE_MS - elapsed ) ;
2217- return ( ) => clearTimeout ( timer ) ;
2218- }
2219-
2220- markThreadVisited (
2221- scopedThreadKey ( scopeThreadRef ( serverThread . environmentId , serverThread . id ) ) ,
2222- serverThread . updatedAt ,
2223- ) ;
2224- } , [
2225- activeThreadLocalLastVisitedAt ,
2226- markThreadVisited ,
2227- routeThreadKey ,
2228- serverThread ?. environmentId ,
2229- serverThread ?. id ,
2230- serverThread ?. lastVisitedAt ,
2231- serverThread ?. latestRun ?. completedAt ,
2232- serverThread ?. updatedAt ,
2233- visitThreadMutation ,
2234- ] ) ;
2235-
22362173 const serverConfig = activeThread
22372174 ? ( activeEnvironment ?. serverConfig ?? null )
22382175 : ( primaryEnvironment ?. serverConfig ?? null ) ;
@@ -8775,6 +8712,7 @@ export default function ChatView(props: ChatViewProps) {
87758712 </ AlertDialogPopup >
87768713 </ AlertDialog >
87778714 < LinkPullRequestDialogHost />
8715+ < ThreadVisitWatermark threadRef = { routeThreadRef } />
87788716 { expandedImage && (
87798717 < ExpandedImageDialog
87808718 key = { expandedImageKey ( expandedImage ) }
@@ -8799,3 +8737,76 @@ function PreviewSessionSync(props: { readonly threadRef: ScopedThreadRef }) {
87998737 usePreviewSession ( props . threadRef ) ;
88008738 return null ;
88018739}
8740+
8741+ // The visit watermark is the one part of the chat view that follows the
8742+ // shell's updatedAt, which ticks while a run streams. Keeping it in a leaf lets
8743+ // ChatView read the quiet shell.
8744+ function ThreadVisitWatermark ( props : { readonly threadRef : ScopedThreadRef } ) {
8745+ const serverThread = useThreadShell ( props . threadRef ) ;
8746+ const threadKey = scopedThreadKey ( props . threadRef ) ;
8747+ const markThreadVisited = useUiStateStore ( ( store ) => store . markThreadVisited ) ;
8748+ const activeThreadLocalLastVisitedAt = useUiStateStore (
8749+ ( store ) => store . threadLastVisitedAtById [ threadKey ] ,
8750+ ) ;
8751+ const visitThreadMutation = useAtomCommand ( threadEnvironment . visit , { reportFailure : false } ) ;
8752+ const lastDispatchedVisitRef = useRef < string | null > ( null ) ;
8753+ const lastVisitDispatchAtRef = useRef ( 0 ) ;
8754+
8755+ useEffect ( ( ) => {
8756+ if ( ! serverThread ?. id ) return ;
8757+ const threadUpdatedAt = Date . parse ( serverThread . updatedAt ) ;
8758+ if ( Number . isNaN ( threadUpdatedAt ) ) return ;
8759+ const effectiveLastVisitedAt = resolveThreadLastVisitedAt (
8760+ serverThread . lastVisitedAt ,
8761+ activeThreadLocalLastVisitedAt ,
8762+ ) ;
8763+ const lastVisitedAt = effectiveLastVisitedAt ? Date . parse ( effectiveLastVisitedAt ) : NaN ;
8764+ if ( ! Number . isNaN ( lastVisitedAt ) && lastVisitedAt >= threadUpdatedAt ) return ;
8765+
8766+ if ( serverThread . lastVisitedAt !== undefined ) {
8767+ // Dedupe per watermark — the effect re-runs before the command's echo
8768+ // lands. The dedupe also keeps a mark-unread on the open thread sticky:
8769+ // the rewind leaves updatedAt untouched, so the already-dispatched key
8770+ // skips a fresh visit until new activity lands or the thread is reopened.
8771+ const dispatchKey = `${ threadKey } :${ serverThread . updatedAt } ` ;
8772+ if ( lastDispatchedVisitRef . current === dispatchKey ) return ;
8773+ const dispatch = ( ) => {
8774+ lastDispatchedVisitRef . current = dispatchKey ;
8775+ lastVisitDispatchAtRef . current = Date . now ( ) ;
8776+ void visitThreadMutation ( {
8777+ environmentId : serverThread . environmentId ,
8778+ input : { threadId : serverThread . id , visitedAt : serverThread . updatedAt } ,
8779+ } ) ;
8780+ } ;
8781+ const latestRunCompletedAtMs = serverThread . latestRun ?. completedAt
8782+ ? Date . parse ( serverThread . latestRun . completedAt )
8783+ : NaN ;
8784+ const hasUnseenCompletion =
8785+ ! Number . isNaN ( latestRunCompletedAtMs ) &&
8786+ ( Number . isNaN ( lastVisitedAt ) || latestRunCompletedAtMs > lastVisitedAt ) ;
8787+ const elapsed = Date . now ( ) - lastVisitDispatchAtRef . current ;
8788+ if ( hasUnseenCompletion || elapsed >= VISIT_DISPATCH_THROTTLE_MS ) {
8789+ dispatch ( ) ;
8790+ return ;
8791+ }
8792+ const timer = setTimeout ( dispatch , VISIT_DISPATCH_THROTTLE_MS - elapsed ) ;
8793+ return ( ) => clearTimeout ( timer ) ;
8794+ }
8795+
8796+ markThreadVisited (
8797+ scopedThreadKey ( scopeThreadRef ( serverThread . environmentId , serverThread . id ) ) ,
8798+ serverThread . updatedAt ,
8799+ ) ;
8800+ } , [
8801+ activeThreadLocalLastVisitedAt ,
8802+ markThreadVisited ,
8803+ threadKey ,
8804+ serverThread ?. environmentId ,
8805+ serverThread ?. id ,
8806+ serverThread ?. lastVisitedAt ,
8807+ serverThread ?. latestRun ?. completedAt ,
8808+ serverThread ?. updatedAt ,
8809+ visitThreadMutation ,
8810+ ] ) ;
8811+ return null ;
8812+ }
0 commit comments