Skip to content

fix: skip session config call when local session is idle-killed#1765

Merged
jonathanlab merged 1 commit intomainfrom
posthog-code/handle-idle-kill-recovery-properly
Apr 21, 2026
Merged

fix: skip session config call when local session is idle-killed#1765
jonathanlab merged 1 commit intomainfrom
posthog-code/handle-idle-kill-recovery-properly

Conversation

@jonathanlab
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab commented Apr 21, 2026

No description provided.

Generated-By: PostHog Code
Task-Id: 3a57f0a0-4443-471a-8891-1dd7bbf70c95
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 21, 2026

Prompt To Fix All With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/sessions/service/service.test.ts
Line: 1500-1521

Comment:
**Incomplete assertions and missing `connecting` status coverage**

The `disconnected` test only checks that the backend call is skipped, but unlike the idle-killed test above it doesn't verify that the local session state and persisted config are still updated — which is the other half of the intended behaviour. Additionally, the `connecting` status is handled in the same conditional in `service.ts` but has no test at all.

Consider also parameterising all three cases (`idleKilled`, `disconnected`, `connecting`) into a single test, per the team's preference for parameterised tests. Example:

```ts
it.each([
  { desc: "idle-killed", overrides: { status: "error" as const, idleKilled: true } },
  { desc: "disconnected", overrides: { status: "disconnected" as const } },
  { desc: "connecting",   overrides: { status: "connecting" as const } },
])(
  "skips backend call when local session is $desc so reconnect restore handles it",
  async ({ overrides }) => {
    const service = getSessionService();
    mockSessionStoreSetters.getSessionByTaskId.mockReturnValue(
      createMockSession({
        ...overrides,
        configOptions: [
          { id: "mode", name: "Mode", type: "select", category: "mode", currentValue: "default", options: [] },
        ],
      }),
    );

    await service.setSessionConfigOption("task-123", "mode", "acceptEdits");

    expect(mockTrpcAgent.setConfigOption.mutate).not.toHaveBeenCalled();
    expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledTimes(1);
    expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledWith(
      "run-123",
      { configOptions: [expect.objectContaining({ id: "mode", currentValue: "acceptEdits" })] },
    );
    expect(mockSessionConfigStore.updatePersistedConfigOptionValue)
      .toHaveBeenCalledWith("run-123", "mode", "acceptEdits");
  },
);
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: skip session config call when local..." | Re-trigger Greptile

Comment on lines +1500 to +1521
it("skips backend call when local session is reconnecting (disconnected status)", async () => {
const service = getSessionService();
mockSessionStoreSetters.getSessionByTaskId.mockReturnValue(
createMockSession({
status: "disconnected",
configOptions: [
{
id: "mode",
name: "Mode",
type: "select",
category: "mode",
currentValue: "default",
options: [],
},
],
}),
);

await service.setSessionConfigOption("task-123", "mode", "acceptEdits");

expect(mockTrpcAgent.setConfigOption.mutate).not.toHaveBeenCalled();
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Incomplete assertions and missing connecting status coverage

The disconnected test only checks that the backend call is skipped, but unlike the idle-killed test above it doesn't verify that the local session state and persisted config are still updated — which is the other half of the intended behaviour. Additionally, the connecting status is handled in the same conditional in service.ts but has no test at all.

Consider also parameterising all three cases (idleKilled, disconnected, connecting) into a single test, per the team's preference for parameterised tests. Example:

it.each([
  { desc: "idle-killed", overrides: { status: "error" as const, idleKilled: true } },
  { desc: "disconnected", overrides: { status: "disconnected" as const } },
  { desc: "connecting",   overrides: { status: "connecting" as const } },
])(
  "skips backend call when local session is $desc so reconnect restore handles it",
  async ({ overrides }) => {
    const service = getSessionService();
    mockSessionStoreSetters.getSessionByTaskId.mockReturnValue(
      createMockSession({
        ...overrides,
        configOptions: [
          { id: "mode", name: "Mode", type: "select", category: "mode", currentValue: "default", options: [] },
        ],
      }),
    );

    await service.setSessionConfigOption("task-123", "mode", "acceptEdits");

    expect(mockTrpcAgent.setConfigOption.mutate).not.toHaveBeenCalled();
    expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledTimes(1);
    expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledWith(
      "run-123",
      { configOptions: [expect.objectContaining({ id: "mode", currentValue: "acceptEdits" })] },
    );
    expect(mockSessionConfigStore.updatePersistedConfigOptionValue)
      .toHaveBeenCalledWith("run-123", "mode", "acceptEdits");
  },
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/sessions/service/service.test.ts
Line: 1500-1521

Comment:
**Incomplete assertions and missing `connecting` status coverage**

The `disconnected` test only checks that the backend call is skipped, but unlike the idle-killed test above it doesn't verify that the local session state and persisted config are still updated — which is the other half of the intended behaviour. Additionally, the `connecting` status is handled in the same conditional in `service.ts` but has no test at all.

Consider also parameterising all three cases (`idleKilled`, `disconnected`, `connecting`) into a single test, per the team's preference for parameterised tests. Example:

```ts
it.each([
  { desc: "idle-killed", overrides: { status: "error" as const, idleKilled: true } },
  { desc: "disconnected", overrides: { status: "disconnected" as const } },
  { desc: "connecting",   overrides: { status: "connecting" as const } },
])(
  "skips backend call when local session is $desc so reconnect restore handles it",
  async ({ overrides }) => {
    const service = getSessionService();
    mockSessionStoreSetters.getSessionByTaskId.mockReturnValue(
      createMockSession({
        ...overrides,
        configOptions: [
          { id: "mode", name: "Mode", type: "select", category: "mode", currentValue: "default", options: [] },
        ],
      }),
    );

    await service.setSessionConfigOption("task-123", "mode", "acceptEdits");

    expect(mockTrpcAgent.setConfigOption.mutate).not.toHaveBeenCalled();
    expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledTimes(1);
    expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledWith(
      "run-123",
      { configOptions: [expect.objectContaining({ id: "mode", currentValue: "acceptEdits" })] },
    );
    expect(mockSessionConfigStore.updatePersistedConfigOptionValue)
      .toHaveBeenCalledWith("run-123", "mode", "acceptEdits");
  },
);
```

How can I resolve this? If you propose a fix, please make it concise.

@jonathanlab jonathanlab enabled auto-merge (squash) April 21, 2026 14:11
@jonathanlab jonathanlab merged commit ca8c683 into main Apr 21, 2026
15 checks passed
@jonathanlab jonathanlab deleted the posthog-code/handle-idle-kill-recovery-properly branch April 21, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants