@@ -46,8 +46,6 @@ import { ANALYTICS_EVENTS } from "@/types/analytics";
4646
4747const log = logger . scope ( "session-service" ) ;
4848
49- export const PREVIEW_TASK_ID = "__preview__" ;
50-
5149interface AuthCredentials {
5250 apiKey : string ;
5351 apiHost : string ;
@@ -62,7 +60,6 @@ interface ConnectParams {
6260 executionMode ?: ExecutionMode ;
6361 adapter ?: "claude" | "codex" ;
6462 model ?: string ;
65- reasoningLevel ?: string ;
6663}
6764
6865// --- Singleton Service Instance ---
@@ -98,8 +95,6 @@ export class SessionService {
9895 permission ?: { unsubscribe : ( ) => void } ;
9996 }
10097 > ( ) ;
101- /** Version counter to discard stale preview session results */
102- private previewVersion = 0 ;
10398
10499 /**
105100 * Connect to a task session.
@@ -141,15 +136,8 @@ export class SessionService {
141136 }
142137
143138 private async doConnect ( params : ConnectParams ) : Promise < void > {
144- const {
145- task,
146- repoPath,
147- initialPrompt,
148- executionMode,
149- adapter,
150- model,
151- reasoningLevel,
152- } = params ;
139+ const { task, repoPath, initialPrompt, executionMode, adapter, model } =
140+ params ;
153141 const { id : taskId , latest_run : latestRun } = task ;
154142 const taskTitle = task . title || task . description || "Task" ;
155143
@@ -226,7 +214,6 @@ export class SessionService {
226214 executionMode ,
227215 adapter ,
228216 model ,
229- reasoningLevel ,
230217 ) ;
231218 }
232219 } catch ( error ) {
@@ -373,7 +360,6 @@ export class SessionService {
373360 executionMode ?: ExecutionMode ,
374361 adapter ?: "claude" | "codex" ,
375362 model ?: string ,
376- reasoningLevel ?: string ,
377363 ) : Promise < void > {
378364 if ( ! auth . client ) {
379365 throw new Error ( "Unable to reach server. Please check your connection." ) ;
@@ -433,15 +419,6 @@ export class SessionService {
433419 ) ;
434420 }
435421
436- // Set reasoning level if provided (e.g., from Codex adapter's preview session)
437- if ( reasoningLevel ) {
438- await this . setSessionConfigOptionByCategory (
439- taskId ,
440- "thought_level" ,
441- reasoningLevel ,
442- ) ;
443- }
444-
445422 if ( initialPrompt ?. length ) {
446423 await this . sendPrompt ( taskId , initialPrompt ) ;
447424 }
@@ -465,127 +442,6 @@ export class SessionService {
465442 sessionStoreSetters . removeSession ( session . taskRunId ) ;
466443 }
467444
468- // --- Preview Session Management ---
469-
470- /**
471- * Start a lightweight preview session for the task input page.
472- * This session is used solely to retrieve adapter-specific config options
473- * (models, modes, reasoning levels) without creating a real PostHog task.
474- *
475- * Uses a version counter to prevent race conditions when rapidly switching
476- * adapters — stale results from a previous start are discarded.
477- */
478- async startPreviewSession ( params : {
479- adapter : "claude" | "codex" ;
480- repoPath ?: string ;
481- } ) : Promise < void > {
482- // Increment version to invalidate any in-flight start
483- const version = ++ this . previewVersion ;
484-
485- // Cancel any existing preview session first
486- await this . cancelPreviewSession ( ) ;
487-
488- // Check if a newer start was requested while we were cancelling
489- if ( version !== this . previewVersion ) {
490- log . info ( "Preview session start superseded, skipping" , { version } ) ;
491- return ;
492- }
493-
494- const auth = this . getAuthCredentials ( ) ;
495- if ( ! auth ) {
496- log . info ( "Skipping preview session - not authenticated" ) ;
497- return ;
498- }
499-
500- const taskRunId = `preview-${ crypto . randomUUID ( ) } ` ;
501- const session = this . createBaseSession (
502- taskRunId ,
503- PREVIEW_TASK_ID ,
504- "Preview" ,
505- ) ;
506- session . adapter = params . adapter ;
507- sessionStoreSetters . setSession ( session ) ;
508-
509- try {
510- const result = await trpcVanilla . agent . start . mutate ( {
511- taskId : PREVIEW_TASK_ID ,
512- taskRunId,
513- repoPath : params . repoPath || "~" ,
514- apiKey : auth . apiKey ,
515- apiHost : auth . apiHost ,
516- projectId : auth . projectId ,
517- adapter : params . adapter ,
518- } ) ;
519-
520- // Check again after the async start — a newer call may have superseded us
521- if ( version !== this . previewVersion ) {
522- log . info (
523- "Preview session start superseded after agent.start, cleaning up stale session" ,
524- { taskRunId, version } ,
525- ) ;
526- // Clean up the session we just started but is now stale
527- trpcVanilla . agent . cancel
528- . mutate ( { sessionId : taskRunId } )
529- . catch ( ( err ) => {
530- log . warn ( "Failed to cancel stale preview session" , {
531- taskRunId,
532- error : err ,
533- } ) ;
534- } ) ;
535- sessionStoreSetters . removeSession ( taskRunId ) ;
536- return ;
537- }
538-
539- const configOptions = result . configOptions as
540- | SessionConfigOption [ ]
541- | undefined ;
542-
543- sessionStoreSetters . updateSession ( taskRunId , {
544- status : "connected" ,
545- channel : result . channel ,
546- configOptions,
547- } ) ;
548-
549- this . subscribeToChannel ( taskRunId ) ;
550-
551- log . info ( "Preview session started" , {
552- taskRunId,
553- adapter : params . adapter ,
554- configOptionsCount : configOptions ?. length ?? 0 ,
555- } ) ;
556- } catch ( error ) {
557- // Only clean up if we're still the current version
558- if ( version === this . previewVersion ) {
559- log . error ( "Failed to start preview session" , { error } ) ;
560- sessionStoreSetters . removeSession ( taskRunId ) ;
561- }
562- }
563- }
564-
565- /**
566- * Cancel and clean up the preview session.
567- * Unsubscribes and removes from store first (so nothing writes to the old
568- * session), then awaits the cancel on the main process.
569- */
570- async cancelPreviewSession ( ) : Promise < void > {
571- const session = sessionStoreSetters . getSessionByTaskId ( PREVIEW_TASK_ID ) ;
572- if ( ! session ) return ;
573-
574- const { taskRunId } = session ;
575-
576- // Unsubscribe and remove from store first so nothing writes to the old session
577- this . unsubscribeFromChannel ( taskRunId ) ;
578- sessionStoreSetters . removeSession ( taskRunId ) ;
579-
580- try {
581- await trpcVanilla . agent . cancel . mutate ( { sessionId : taskRunId } ) ;
582- } catch ( error ) {
583- log . warn ( "Failed to cancel preview session" , { taskRunId, error } ) ;
584- }
585-
586- log . info ( "Preview session cancelled" , { taskRunId } ) ;
587- }
588-
589445 // --- Subscription Management ---
590446
591447 private subscribeToChannel ( taskRunId : string ) : void {
@@ -655,7 +511,6 @@ export class SessionService {
655511 }
656512
657513 this . connectingTasks . clear ( ) ;
658- this . previewVersion = 0 ;
659514 }
660515
661516 private handleSessionEvent ( taskRunId : string , acpMsg : AcpMessage ) : void {
0 commit comments