@@ -25,7 +25,6 @@ import { app } from "electron";
2525import { inject , injectable , preDestroy } from "inversify" ;
2626import { MAIN_TOKENS } from "../../di/tokens.js" ;
2727import { logger } from "../../lib/logger.js" ;
28- import { createMainTimingCollector } from "../../lib/timing.js" ;
2928import { TypedEventEmitter } from "../../lib/typed-event-emitter.js" ;
3029import type { FsService } from "../fs/service.js" ;
3130import type { ProcessTrackingService } from "../process-tracking/service.js" ;
@@ -178,8 +177,6 @@ interface SessionConfig {
178177 additionalDirectories ?: string [ ] ;
179178 /** Permission mode to use for the session */
180179 permissionMode ?: string ;
181- /** Dev-only: timestamp from renderer when user submitted the task */
182- submittedAt ?: number ;
183180}
184181
185182interface ManagedSession {
@@ -420,8 +417,6 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
420417 isReconnect : boolean ,
421418 isRetry = false ,
422419 ) : Promise < ManagedSession | null > {
423- const tc = createMainTimingCollector ( log ) ;
424-
425420 const {
426421 taskId,
427422 taskRunId,
@@ -431,13 +426,8 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
431426 adapter,
432427 additionalDirectories,
433428 permissionMode,
434- submittedAt,
435429 } = config ;
436430
437- if ( submittedAt ) {
438- tc . record ( "ipcTransit" , Date . now ( ) - submittedAt ) ;
439- }
440-
441431 // Preview sessions don't need a real repo — use a temp directory
442432 const repoPath = taskId === "__preview__" ? tmpdir ( ) : rawRepoPath ;
443433
@@ -448,21 +438,15 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
448438 }
449439
450440 // Kill any lingering processes from previous runs of this task
451- tc . timeSync ( "killProcesses" , ( ) =>
452- this . processTracking . killByTaskId ( taskId ) ,
453- ) ;
441+ this . processTracking . killByTaskId ( taskId ) ;
454442
455443 // Clean up any prior session for this taskRunId before creating a new one
456- await tc . time ( "cleanup" , ( ) => this . cleanupSession ( taskRunId ) ) ;
444+ await this . cleanupSession ( taskRunId ) ;
457445 }
458446
459447 const channel = `agent-event:${ taskRunId } ` ;
460- const mockNodeDir = tc . timeSync ( "mockNode" , ( ) =>
461- this . setupMockNodeEnvironment ( taskRunId ) ,
462- ) ;
463- tc . timeSync ( "setupEnv" , ( ) =>
464- this . setupEnvironment ( credentials , mockNodeDir ) ,
465- ) ;
448+ const mockNodeDir = this . setupMockNodeEnvironment ( taskRunId ) ;
449+ this . setupEnvironment ( credentials , mockNodeDir ) ;
466450
467451 // Preview sessions don't persist logs — no real task exists
468452 const isPreview = taskId === "__preview__" ;
@@ -479,74 +463,69 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
479463 } ) ;
480464
481465 try {
482- const acpConnection = await tc . time ( "agentRun" , ( ) =>
483- agent . run ( taskId , taskRunId , {
484- adapter,
485- codexBinaryPath :
486- adapter === "codex" ? getCodexBinaryPath ( ) : undefined ,
487- processCallbacks : {
488- onProcessSpawned : ( info ) => {
489- this . processTracking . register (
490- info . pid ,
491- "agent" ,
492- `agent:${ taskRunId } ` ,
493- {
494- taskRunId,
495- taskId,
496- command : info . command ,
497- } ,
466+ const acpConnection = await agent . run ( taskId , taskRunId , {
467+ adapter,
468+ codexBinaryPath : adapter === "codex" ? getCodexBinaryPath ( ) : undefined ,
469+ processCallbacks : {
470+ onProcessSpawned : ( info ) => {
471+ this . processTracking . register (
472+ info . pid ,
473+ "agent" ,
474+ `agent:${ taskRunId } ` ,
475+ {
476+ taskRunId,
498477 taskId,
499- ) ;
500- } ,
501- onProcessExited : ( pid ) => {
502- this . processTracking . unregister ( pid , "agent-exited" ) ;
503- } ,
478+ command : info . command ,
479+ } ,
480+ taskId ,
481+ ) ;
504482 } ,
505- } ) ,
506- ) ;
483+ onProcessExited : ( pid ) => {
484+ this . processTracking . unregister ( pid , "agent-exited" ) ;
485+ } ,
486+ } ,
487+ } ) ;
507488 const { clientStreams } = acpConnection ;
508489
509- const connection = tc . timeSync ( "clientConnection" , ( ) =>
510- this . createClientConnection ( taskRunId , channel , clientStreams ) ,
490+ const connection = this . createClientConnection (
491+ taskRunId ,
492+ channel ,
493+ clientStreams ,
511494 ) ;
512495
513- await tc . time ( "initialize" , ( ) =>
514- connection . initialize ( {
515- protocolVersion : PROTOCOL_VERSION ,
516- clientCapabilities : {
517- fs : {
518- readTextFile : true ,
519- writeTextFile : true ,
520- } ,
521- terminal : true ,
496+ await connection . initialize ( {
497+ protocolVersion : PROTOCOL_VERSION ,
498+ clientCapabilities : {
499+ fs : {
500+ readTextFile : true ,
501+ writeTextFile : true ,
522502 } ,
523- } ) ,
524- ) ;
503+ terminal : true ,
504+ } ,
505+ } ) ;
525506
526- const mcpServers = tc . timeSync ( "buildMcp" , ( ) =>
527- adapter === "codex" ? [ ] : this . buildMcpServers ( credentials ) ,
528- ) ;
507+ const mcpServers =
508+ adapter === "codex" ? [ ] : this . buildMcpServers ( credentials ) ;
529509
530510 let configOptions : SessionConfigOption [ ] | undefined ;
531511 let agentSessionId : string ;
532512
533513 if ( isReconnect && adapter === "codex" && config . sessionId ) {
534- const loadResponse = await tc . time ( "loadSession" , ( ) =>
535- connection . loadSession ( {
536- sessionId : config . sessionId ! ,
537- cwd : repoPath ,
538- mcpServers,
539- } ) ,
540- ) ;
514+ const loadResponse = await connection . loadSession ( {
515+ sessionId : config . sessionId ! ,
516+ cwd : repoPath ,
517+ mcpServers,
518+ } ) ;
541519 configOptions = loadResponse . configOptions ?? undefined ;
542520 agentSessionId = config . sessionId ;
543521 } else if ( isReconnect && adapter !== "codex" ) {
544522 if ( ! config . sessionId ) {
545523 throw new Error ( "Cannot resume session without sessionId" ) ;
546524 }
547525 const systemPrompt = this . buildPostHogSystemPrompt ( credentials ) ;
548- const resumeResponse = await tc . time ( "resumeSession" , ( ) =>
549- connection . extMethod ( "_posthog/session/resume" , {
526+ const resumeResponse = await connection . extMethod (
527+ "_posthog/session/resume" ,
528+ {
550529 sessionId : config . sessionId ! ,
551530 cwd : repoPath ,
552531 mcpServers,
@@ -564,7 +543,7 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
564543 } ,
565544 } ) ,
566545 } ,
567- } ) ,
546+ } ,
568547 ) ;
569548 const resumeMeta = resumeResponse ?. _meta as
570549 | {
@@ -575,31 +554,26 @@ export class AgentService extends TypedEventEmitter<AgentServiceEvents> {
575554 agentSessionId = config . sessionId ;
576555 } else {
577556 const systemPrompt = this . buildPostHogSystemPrompt ( credentials ) ;
578- const newSessionResponse = await tc . time ( "newSession" , ( ) =>
579- connection . newSession ( {
580- cwd : repoPath ,
581- mcpServers,
582- _meta : {
583- taskRunId,
584- systemPrompt,
585- ...( permissionMode && { permissionMode } ) ,
586- ...( additionalDirectories ?. length && {
587- claudeCode : {
588- options : { additionalDirectories } ,
589- } ,
590- } ) ,
591- } ,
592- } ) ,
593- ) ;
557+ const newSessionResponse = await connection . newSession ( {
558+ cwd : repoPath ,
559+ mcpServers,
560+ _meta : {
561+ taskRunId,
562+ systemPrompt,
563+ ...( permissionMode && { permissionMode } ) ,
564+ ...( additionalDirectories ?. length && {
565+ claudeCode : {
566+ options : { additionalDirectories } ,
567+ } ,
568+ } ) ,
569+ } ,
570+ } ) ;
594571 configOptions = newSessionResponse . configOptions ?? undefined ;
595572 agentSessionId = newSessionResponse . sessionId ;
596573 }
597574
598575 config . sessionId = agentSessionId ;
599576
600- const sessionType = isReconnect ? "reconnect" : "create" ;
601- tc . summarize ( `getOrCreateSession(${ sessionType } )` ) ;
602-
603577 const session : ManagedSession = {
604578 taskRunId,
605579 taskId,
@@ -1293,7 +1267,6 @@ For git operations while detached:
12931267 : undefined ,
12941268 permissionMode :
12951269 "permissionMode" in params ? params . permissionMode : undefined ,
1296- submittedAt : "submittedAt" in params ? params . submittedAt : undefined ,
12971270 } ;
12981271 }
12991272
0 commit comments