Skip to content

Commit be6693a

Browse files
committed
Remove dev-only timing instrumentation
1 parent 70a00c9 commit be6693a

File tree

17 files changed

+116
-348
lines changed

17 files changed

+116
-348
lines changed

apps/twig/src/main/lib/timing.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

apps/twig/src/main/services/agent/schemas.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export const startSessionInput = z.object({
4545
runMode: z.enum(["local", "cloud"]).optional(),
4646
adapter: z.enum(["claude", "codex"]).optional(),
4747
additionalDirectories: z.array(z.string()).optional(),
48-
/** Dev-only: timestamp from renderer when user submitted the task */
49-
submittedAt: z.number().optional(),
5048
});
5149

5250
export type StartSessionInput = z.infer<typeof startSessionInput>;

apps/twig/src/main/services/agent/service.ts

Lines changed: 62 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { app } from "electron";
2525
import { inject, injectable, preDestroy } from "inversify";
2626
import { MAIN_TOKENS } from "../../di/tokens.js";
2727
import { logger } from "../../lib/logger.js";
28-
import { createMainTimingCollector } from "../../lib/timing.js";
2928
import { TypedEventEmitter } from "../../lib/typed-event-emitter.js";
3029
import type { FsService } from "../fs/service.js";
3130
import 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

185182
interface 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

apps/twig/src/renderer/features/sessions/components/ConversationView.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ export const WithPendingPrompt: Story = {
451451
return events;
452452
})(),
453453
isPromptPending: true,
454-
promptStartedAt: Date.now() - 5000,
455454
repoPath: "/Users/jonathan/dev/twig",
456455
},
457456
};

apps/twig/src/renderer/features/sessions/components/ConversationView.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ type VirtualizedItem = ConversationItem | QueuedItem;
6060
interface ConversationViewProps {
6161
events: AcpMessage[];
6262
isPromptPending: boolean;
63-
promptStartedAt?: number | null;
6463
repoPath?: string | null;
6564
taskId?: string;
6665
}
@@ -71,7 +70,6 @@ const ESTIMATE_SIZE = 200;
7170
export function ConversationView({
7271
events,
7372
isPromptPending,
74-
promptStartedAt,
7573
repoPath,
7674
taskId,
7775
}: ConversationViewProps) {
@@ -209,7 +207,6 @@ export function ConversationView({
209207
<div className="pb-16">
210208
<SessionFooter
211209
isPromptPending={isPromptPending}
212-
promptStartedAt={promptStartedAt}
213210
lastGenerationDuration={
214211
lastTurn?.isComplete ? lastTurn.durationMs : null
215212
}

apps/twig/src/renderer/features/sessions/components/SessionFooter.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { formatDuration, GeneratingIndicator } from "./GeneratingIndicator";
55

66
interface SessionFooterProps {
77
isPromptPending: boolean;
8-
promptStartedAt?: number | null;
98
lastGenerationDuration: number | null;
109
lastStopReason?: string;
1110
queuedCount?: number;
@@ -14,7 +13,6 @@ interface SessionFooterProps {
1413

1514
export function SessionFooter({
1615
isPromptPending,
17-
promptStartedAt,
1816
lastGenerationDuration,
1917
lastStopReason,
2018
queuedCount = 0,
@@ -41,7 +39,7 @@ export function SessionFooter({
4139
return (
4240
<Box className="pt-3 pb-1">
4341
<Flex align="center" gap="2">
44-
<GeneratingIndicator startedAt={promptStartedAt} />
42+
<GeneratingIndicator />
4543
{queuedCount > 0 && (
4644
<Text size="1" color="gray">
4745
({queuedCount} queued)

apps/twig/src/renderer/features/sessions/components/SessionView.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ interface SessionViewProps {
3737
taskId?: string;
3838
isRunning: boolean;
3939
isPromptPending?: boolean;
40-
promptStartedAt?: number | null;
4140
onSendPrompt: (text: string) => void;
4241
onBashCommand?: (command: string) => void;
4342
onCancelPrompt: () => void;
@@ -58,7 +57,6 @@ export function SessionView({
5857
taskId,
5958
isRunning,
6059
isPromptPending = false,
61-
promptStartedAt,
6260
onSendPrompt,
6361
onBashCommand,
6462
onCancelPrompt,
@@ -366,7 +364,6 @@ export function SessionView({
366364
<ConversationView
367365
events={events}
368366
isPromptPending={isPromptPending}
369-
promptStartedAt={promptStartedAt}
370367
repoPath={repoPath}
371368
taskId={taskId}
372369
/>

apps/twig/src/renderer/features/sessions/service/service.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ const createMockSession = (
182182
startedAt: Date.now(),
183183
status: "connected",
184184
isPromptPending: false,
185-
promptStartedAt: null,
186185
pendingPermissions: new Map(),
187186
messageQueue: [],
188187
...overrides,

0 commit comments

Comments
 (0)