Repository navigation
refactor(server): detach PR lookup stacks instead of a custom cache #13311
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.
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 1 commit into
t3code/codex-turn-mapping
from
t3code/pr-lookup-cache-stack-only
Sep 23, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import * as Effect from "effect/Effect"; | ||
| import * as References from "effect/References"; | ||
|
|
||
| const snapshotStack = ( | ||
| frame: References.StackFrame | undefined, | ||
| ): References.StackFrame | undefined => { | ||
| if (frame === undefined) return undefined; | ||
| const stack = frame.stack(); | ||
| return { name: frame.name, stack: () => stack, parent: snapshotStack(frame.parent) }; | ||
| }; | ||
|
|
||
| /** | ||
| * Wrap a `Cache.get` so its lookup fiber inherits a materialized stack. The lazy | ||
| * caller frame would otherwise retain the caller's request snapshot for the TTL. | ||
| */ | ||
| export const detachStackFrame = <A, E, R>(effect: Effect.Effect<A, E, R>) => | ||
| Effect.gen(function* () { | ||
| const frame = snapshotStack(yield* References.CurrentStackFrame); | ||
| return yield* Effect.provideService(effect, References.CurrentStackFrame, frame); | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { Cache, Effect } from "effect"; | ||
| import { detachStackFrame } from "../detachStackFrame.ts"; | ||
| // `original` runs the bare Effect Cache to show the leak this helper prevents. | ||
| const original = process.argv.includes("original"); | ||
| const failure = process.argv.includes("failure"); | ||
| const lookup = () => (failure ? Effect.fail("unavailable") : Effect.succeed(1)); | ||
| const cache = await Effect.runPromise( | ||
| Cache.makeWith(lookup, { capacity: 8, timeToLive: () => "1 hour" }), | ||
| ); | ||
| const get = () => (original ? Cache.get(cache, "key") : detachStackFrame(Cache.get(cache, "key"))); | ||
| let reference; | ||
| await Effect.runPromise( | ||
| Effect.gen(function* () { | ||
| const snapshot = { values: Array.from({ length: 250000 }, (_, i) => i) }; | ||
| reference = new WeakRef(snapshot); | ||
| const request = Effect.fn("StackRetention.request")(function* () { | ||
| yield* Effect.exit(get()); | ||
| return snapshot.values.length; | ||
| }); | ||
| yield* request(); | ||
| }), | ||
| ); | ||
| for (let i = 0; i < 12; i++) { | ||
| await new Promise((resolve) => setImmediate(resolve)); | ||
| global.gc(); | ||
| } | ||
| const retained = reference.deref() !== undefined; | ||
| const cachedResult = await Effect.runPromise( | ||
| get().pipe(Effect.catch(() => Effect.succeed("unavailable"))), | ||
| ); | ||
| process.stdout.write(JSON.stringify({ retained, cachedResult })); | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium
testing/StackRetention.fixture.mjs:2On Node 22.16/22.17, the spawned process exits while loading
../detachStackFrame.tsbecause it is invoked only with--expose-gc; those Node versions still require--experimental-strip-typesfor.tsimports, so the fixture never reaches its assertions. Add that flag to the child-process invocation or use a JavaScript fixture/built output.🚀 Reply "fix it for me" or copy this AI Prompt for your agent: