Skip to content

refactor(server): detach PR lookup stacks instead of a custom cache - #13311

Merged
juliusmarminge merged 1 commit into
t3code/codex-turn-mappingfrom
t3code/pr-lookup-cache-stack-only
Sep 23, 2026
Merged

juliusmarminge merged 1 commit into
t3code/codex-turn-mappingfrom
t3code/pr-lookup-cache-stack-only

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #13304.

#13304 stopped cached PR lookups from retaining caller thread snapshots by replacing Effect's Cache with a hand-rolled LookupResultCache. The leak comes only from the caller's lazy stack frame, which the Cache lookup fiber inherits. Materializing that frame before Cache.get is enough.

This adds a 20-line detachStackFrame helper, routes the three PR-lookup Cache.get calls through it, and returns to Cache.makeWith. The custom cache and its expiry, eviction, and cancellation tests are removed, since Effect's Cache owns that behavior again.

Verification:

  • The isolated GC fixture releases the caller snapshot with the helper for both successful and failed lookups, while keeping the result cached. Bare Cache (original mode) retains it on success; the failed-lookup control retained it in one of two runs.
  • detachStackFrame.memory.test.ts and GitManager.test.ts pass (116 tests). Scoped lint, formatting, and the server typecheck pass.

Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code


Devin Review

The PR lookup leak came from the caller's lazy stack frame, which the Effect
Cache lookup fiber inherits. Materialize that frame before Cache.get and go
back to Effect's Cache, dropping the hand-rolled replacement and its
expiry/eviction/cancellation tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Sep 23, 2026
@@ -0,0 +1,31 @@
import { Cache, Effect } from "effect";
import { detachStackFrame } from "../detachStackFrame.ts";

Copy link
Copy Markdown
Contributor

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:2

On Node 22.16/22.17, the spawned process exits while loading ../detachStackFrame.ts because it is invoked only with --expose-gc; those Node versions still require --experimental-strip-types for .ts imports, 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:
In file @apps/server/src/git/testing/StackRetention.fixture.mjs around line 2:

On Node 22.16/22.17, the spawned process exits while loading `../detachStackFrame.ts` because it is invoked only with `--expose-gc`; those Node versions still require `--experimental-strip-types` for `.ts` imports, so the fixture never reaches its assertions. Add that flag to the child-process invocation or use a JavaScript fixture/built output.

@macroscopeapp

macroscopeapp Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Would Approve

Macroscope's review found this PR approvable — This is a focused PR-lookup cache refactor that preserves lookup, TTL, eviction, and invalidation behavior while preventing cached fibers from retaining request snapshots. The supplied Medium finding identifies a supported-Node test-fixture compatibility problem, which remains a separate correctness issue.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 4.9 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.7 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 20.4 KiB — 29.3 KiB ✅
Codex Live turn messages — 2 — 8 ✅
Claude Total thread wire — 4.9 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.7 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 20.8 KiB — 29.3 KiB ✅
Claude Live turn messages — 2 — 8 ✅

Baseline: unavailable · PR result: d768a00 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 106.1 KiB
  • Claude decoded thread snapshot: 106.4 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@juliusmarminge
juliusmarminge merged commit cde4737 into t3code/codex-turn-mapping Sep 23, 2026
24 of 26 checks passed
@juliusmarminge
juliusmarminge deleted the t3code/pr-lookup-cache-stack-only branch September 23, 2026 21:26
juliusmarminge added a commit that referenced this pull request Sep 23, 2026
…13311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
juliusmarminge added a commit that referenced this pull request Sep 23, 2026
…13311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
juliusmarminge added a commit that referenced this pull request Sep 24, 2026
…13311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
juliusmarminge added a commit that referenced this pull request Sep 24, 2026
…13311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
juliusmarminge added a commit that referenced this pull request Sep 24, 2026
…13311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
juliusmarminge added a commit that referenced this pull request Sep 25, 2026
…13311)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant