GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Claude Process leak[MEMORY INTENSIVE], archiving, and stale claude session monitoring. by crafael23 · Pull Request #2042 · pingdotgg/t3code

Fix Claude Process leak[MEMORY INTENSIVE], archiving, and stale claude session monitoring. #2042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
juliusmarminge merged 12 commits into pingdotgg:main from crafael23:fixfeat-claude-process-cleanup-process-reaper
Apr 16, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fix Claude Process leak[MEMORY INTENSIVE], archiving, and stale claude session monitoring. #2042

Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
cf63c06
Prevent session leaks during archive and Claude restarts
crafael23 Apr 15, 2026
656f610
portable scripts to a ignored directory between branches.
crafael23 Apr 15, 2026
4f1c0e4
Increase reaper inactivity threshold to 30min and add test script
crafael23 Apr 15, 2026
d32e8cd
Merge branch 'main' into fixfeat-claude-process-cleanup-process-reaper
crafael23 Apr 15, 2026
d7a76f2
Format ClaudeAdapter and use catchCause for session replace cleanup
crafael23 Apr 15, 2026
f0277d7
Use catchCause in reaper to survive stop defects
crafael23 Apr 15, 2026
ec3ec19
Use catchCause in archive to survive session stop defects
crafael23 Apr 15, 2026
63386bf
Fix provider session replacement cleanup
juliusmarminge Apr 16, 2026
7422d26
Make codex replacement cleanup best-effort
juliusmarminge Apr 16, 2026
c811373
Use granular thread lookup for archive handling
juliusmarminge Apr 16, 2026
83b005e
Make archive session lookup best-effort
juliusmarminge Apr 16, 2026
59fdbb0
Preflight archive session cleanup
juliusmarminge Apr 16, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

3 changes: 2 additions & 1 deletion 3 apps/server/package.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"start": "node dist/bin.mjs",
"prepare": "effect-language-service patch",
"typecheck": "tsc --noEmit",
"test": "vitest run"
"test": "vitest run",
"test:process-reaper": "vitest run src/server.test.ts src/provider/Layers/ClaudeAdapter.test.ts src/provider/Layers/ProviderSessionDirectory.test.ts src/provider/Layers/ProviderSessionReaper.test.ts src/provider/Layers/CodexAdapter.test.ts"
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.2.77",
Expand Down
73 changes: 73 additions & 0 deletions 73 apps/server/src/codexAppServerManager.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,79 @@ describe("startSession", () => {
manager.stopAll();
}
});

it("disposes an existing session before starting a replacement for the same thread", async () => {
const manager = new CodexAppServerManager();
const existingContext = {
session: {
provider: "codex",
status: "ready",
threadId: asThreadId("thread-1"),
runtimeMode: "full-access",
createdAt: "2026-02-10T00:00:00.000Z",
updatedAt: "2026-02-10T00:00:00.000Z",
},
};

(
manager as unknown as {
sessions: Map<ThreadId, typeof existingContext>;
}
).sessions.set(asThreadId("thread-1"), existingContext);

const disposeSession = vi
.spyOn(
manager as unknown as {
disposeSession: (
context: typeof existingContext,
options?: { readonly emitLifecycleEvent?: boolean },
) => void;
},
"disposeSession",
)
.mockImplementation(() => {});
const assertSupportedCodexCliVersion = vi
.spyOn(
manager as unknown as {
assertSupportedCodexCliVersion: (input: {
binaryPath: string;
cwd: string;
homePath?: string;
}) => void;
},
"assertSupportedCodexCliVersion",
)
.mockImplementation(() => {});
const processCwd = vi.spyOn(process, "cwd").mockImplementation(() => {
throw new Error("cwd missing");
});

try {
await expect(
manager.startSession({
threadId: asThreadId("thread-1"),
provider: "codex",
binaryPath: "codex",
runtimeMode: "full-access",
}),
).rejects.toThrow("cwd missing");

expect(disposeSession).toHaveBeenCalledWith(existingContext, {
emitLifecycleEvent: false,
});
expect(assertSupportedCodexCliVersion).not.toHaveBeenCalled();
} finally {
disposeSession.mockRestore();
assertSupportedCodexCliVersion.mockRestore();
processCwd.mockRestore();
(
manager as unknown as {
sessions: Map<ThreadId, typeof existingContext>;
}
).sessions.clear();
manager.stopAll();
}
});
});

describe("sendTurn", () => {
Expand Down
30 changes: 28 additions & 2 deletions 30 apps/server/src/codexAppServerManager.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,17 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
let context: CodexSessionContext | undefined;

try {
const existingContext = this.sessions.get(threadId);
if (existingContext) {
await Effect.logWarning("codex app-server replacing existing session", {
threadId,
existingStatus: existingContext.session.status,
}).pipe(this.runPromise);
this.disposeSession(existingContext, {
emitLifecycleEvent: false,
});
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}

const resolvedCwd = input.cwd ?? process.cwd();

const session: ProviderSession = {
Expand Down Expand Up @@ -901,6 +912,19 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
return;
}

this.disposeSession(context, {
emitLifecycleEvent: true,
});
}

private disposeSession(
context: CodexSessionContext,
options?: { readonly emitLifecycleEvent?: boolean },
): void {
if (context.stopping) {
return;
}

context.stopping = true;

for (const pending of context.pending.values()) {
Expand All @@ -921,8 +945,10 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
status: "closed",
activeTurnId: undefined,
});
this.emitLifecycleEvent(context, "session/closed", "Session stopped");
this.sessions.delete(threadId);
if (options?.emitLifecycleEvent !== false) {
this.emitLifecycleEvent(context, "session/closed", "Session stopped");
}
this.sessions.delete(context.session.threadId);
}

listSessions(): ProviderSession[] {
Expand Down
65 changes: 65 additions & 0 deletions 65 apps/server/src/provider/Layers/ClaudeAdapter.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,71 @@ describe("ClaudeAdapterLive", () => {
);
});

it.effect("closes the previous session before replacing an existing thread session", () => {
const queries: FakeClaudeQuery[] = [];
const layer = makeClaudeAdapterLive({
createQuery: () => {
const query = new FakeClaudeQuery();
queries.push(query);
return query;
},
}).pipe(
Layer.provideMerge(ServerConfig.layerTest("/tmp/claude-adapter-test", "/tmp")),
Layer.provideMerge(ServerSettingsService.layerTest()),
Layer.provideMerge(NodeServices.layer),
);

return Effect.gen(function* () {
const adapter = yield* ClaudeAdapter;

const runtimeEventsFiber = yield* Stream.take(adapter.streamEvents, 6).pipe(
Stream.runCollect,
Effect.forkChild,
);

const firstSession = yield* adapter.startSession({
threadId: THREAD_ID,
provider: "claudeAgent",
runtimeMode: "full-access",
});

const secondSession = yield* adapter.startSession({
threadId: THREAD_ID,
provider: "claudeAgent",
runtimeMode: "full-access",
resumeCursor: firstSession.resumeCursor,
});

const runtimeEvents = Array.from(yield* Fiber.join(runtimeEventsFiber));
const activeSessions = yield* adapter.listSessions();

assert.equal(queries.length, 2);
assert.equal(queries[0]?.closeCalls, 1);
assert.equal(queries[1]?.closeCalls, 0);
assert.equal(yield* adapter.hasSession(THREAD_ID), true);
assert.equal(activeSessions.length, 1);
assert.deepEqual(activeSessions[0]?.resumeCursor, secondSession.resumeCursor);
assert.deepEqual(
runtimeEvents.map((event) => event.type),
[
"session.started",
"session.configured",
"session.state.changed",
"session.started",
"session.configured",
"session.state.changed",
],
);
assert.equal(
runtimeEvents.some((event) => event.type === "session.exited"),
false,
);
}).pipe(
Effect.provideService(Random.Random, makeDeterministicRandomService()),
Effect.provide(layer),
);
});

it.effect("stopSession does not throw into the SDK prompt consumer", () => {
// The SDK consumes user messages via `for await (... of prompt)`.
// Stopping a session must end that loop cleanly — not throw an error.
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.