GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(server): stop idle private-memory growth from immortal parent spans by Benchance · Pull Request #5411 · pingdotgg/t3code Conversation
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Effect.gen(function* () { | ||
| const activation = yield* ServerActivation; | ||
| const detached = withoutAmbientParentSpan(effect); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🟠 High src/serverActivation.ts:25
withoutAmbientParentSpan casts the context after removing Tracer.ParentSpan back to Context.Context<NoInfer<R>>, so the return type still claims to satisfy effects whose environment explicitly includes Tracer.ParentSpan. If an effect passed to withoutAmbientParentSpan (or to forkParked, which wraps every input with it) directly uses Tracer.ParentSpan, the code type-checks but the forked fiber fails at runtime with Service not found because the service was removed from the child context. The cast masks a missing-service defect rather than surfacing it as a type error. Consider constraining the input type so Tracer.ParentSpan cannot appear in R.
- (context) => Context.omit(Tracer.ParentSpan)(context) as Context.Context<NoInfer<R>>, + (context) => Context.omit(Tracer.ParentSpan)(context) as Context.Context<Exclude<NoInfer<R>, Tracer.ParentSpan>>, + // Note: this cast is unsafe if R explicitly requires Tracer.ParentSpan; + // callers should ensure the input does not use that service directly.
In file @apps/server/src/serverActivation.ts around lines 25-27:
`withoutAmbientParentSpan` casts the context after removing `Tracer.ParentSpan` back to `Context.Context<NoInfer<R>>`, so the return type still claims to satisfy effects whose environment explicitly includes `Tracer.ParentSpan`. If an effect passed to `withoutAmbientParentSpan` (or to `forkParked`, which wraps every input with it) directly uses `Tracer.ParentSpan`, the code type-checks but the forked fiber fails at runtime with `Service not found` because the service was removed from the child context. The cast masks a missing-service defect rather than surfacing it as a type error. Consider constraining the input type so `Tracer.ParentSpan` cannot appear in `R`.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 17580be — return type is now Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>> with a matching context cast, so the stripped env is reflected in the type.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixes idle private-memory growth in the desktop/server process by preventing long-lived fibers (parked roots + background pollers) from inheriting short-lived startup Tracer.ParentSpan context, and by reducing tracing work on hot/idle paths.
Changes:
withoutAmbientParentSpan and apply it in forkParked to detach inherited Tracer.ParentSpan for long-lived roots.PortDiscovery.make wrapping span.withoutAmbientParentSpan clears inherited Tracer.ParentSpan without affecting sibling effects.Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/server/src/serverRuntimeStartup.ts | Documents why parked startup roots must detach ambient ParentSpan to avoid pinning startup spans. |
| apps/server/src/serverActivation.ts | Introduces withoutAmbientParentSpan and applies it to all forkParked forks. |
| apps/server/src/serverActivation.test.ts | Adds a unit test asserting ParentSpan detachment behavior. |
| apps/server/src/preview/PortScanner.ts | Detaches the poll fiber from ambient parent spans and disables tracing in the poll loop; removes PortDiscovery.make span wrapper. |
| apps/server/src/auth/ServerSecretStore.ts | Disables tracing for frequent secret reads to reduce idle trace volume and span retention. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| expect(stillHasParent).toBe(true); | ||
|
|
||
| const stripped = Context.omit(Tracer.ParentSpan)(Context.make(Tracer.ParentSpan, ambient)); | ||
| expect(Context.getOption(stripped, Tracer.ParentSpan)._tag).toBe("None"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 17580be — switched to Option.isNone.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Single layer-scoped polling fiber. Ticks are no-ops when no client is | ||
| // currently retained, so the cost is one Ref.get every POLL_INTERVAL. | ||
| yield* Effect.forkScoped(pollTick().pipe(Effect.repeat(Schedule.spaced(POLL_INTERVAL)))); | ||
|
|
||
| // currently retained. Run detached from any ambient ParentSpan (e.g. | ||
| // PortDiscovery.make) and without tracing idle no-ops — otherwise every | ||
| // 3s tick parents under an immortal span and grows server private memory. | ||
| yield* Effect.forkScoped( | ||
| withoutAmbientParentSpan( | ||
| pollTick().pipe( | ||
| Effect.repeat(Schedule.spaced(POLL_INTERVAL)), | ||
| Effect.withTracerEnabled(false), | ||
| ), | ||
| ), | ||
| ); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good catch — fixed in 17580be. Idle early-return now sits outside Effect.fn("PortDiscovery.pollTick") so no-op ticks create no span, and the blanket withTracerEnabled(false) on the poll loop is gone so active scans still get traced. ParentSpan detach stays via withoutAmbientParentSpan.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This memory-leak fix modifies span/tracing behavior for long-lived server processes. An unresolved high-severity comment identifies a type cast that could mask runtime 'Service not found' errors, which warrants human review to ensure correctness. You can customize Macroscope's approvability policy. Learn more. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Long-lived forkParked roots and PortDiscovery poll loops were inheriting Effect ParentSpan from short-lived startup/make spans. Nested hot-path spans (secret reads, idle poll ticks) kept parenting under those immortal spans and drove ~25-30MB/h private growth while idle. Detach ambient ParentSpan in forkParked, untrace idle port polls and secret gets, and drop PortDiscovery.make's wrapping span. Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Keep active PortDiscovery polls traced, tighten withoutAmbientParentSpan's R, and use Option.isNone in the test. Co-authored-by: Cursor <[email protected]>
17580be to
655748b
Compare
|
Closing in favor of #9824, which reimplements the same idle ParentSpan / background-fiber diagnosis with a type-safe Thanks @Benchance — the original analysis and first fix attempt here were what unblocked the follow-up. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[Bug]: Desktop server private memory climbs ~25-30 MB/h while idle (immortal Effect parent spans + always-on tracing)
There was an error while loading. Please reload this page.