Repository navigation
fix: drop the driver's test-only observerEntries hook; test pruning through behaviour - #199
Merged
Merged
Conversation
…hrough behaviour observerEntries was a module global the Driver constructor overwrote with a closure over itself, so the last driver (its VM, globals and host context) stayed reachable after its run ended. It existed only for tests, so it is removed rather than made opt-in. The per-call pruning tests now check behaviour: WeakRefs to the ObservedCall each finished durable call's before hook saw are collected while the run is still alive, and a finished run is not retained after execute returns. Thanks to #197 / @kommander for finding the retention and for the regression test this adapts.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What was retained
#192 added
export const observerEntries: { last?: () => number } = {}tosrc/runtime/driver.ts, and everyDriverconstructor setobserverEntries.last = () => this.reported.size + this.observed.size. That closure captures the driver, so a module global kept the most recent driver (its VM, globals and host context) reachable long after its run finished.Change
The hook was test-only, so it is removed entirely (export and constructor line). Nothing in
src, the index exports or docs referenced it.How pruning is tested now
host-observe.test.ts,host-observe-promise.test.ts): a run does 20 observed durable calls and 20 unobserved ones, then parks on a hostgate()call. While the run is still alive, the test forces GC and checks that WeakRefs to theObservedCallobjects eachbeforehook received are all collected, so the driver'sobservedmap no longer holds finished calls. Then it releases the gate and checks the result. Commenting outthis.observed.delete(id)makes both tests fail.reportedset holds only numbers), so there is no separate assertion for them.executereturns.The GC checks force collection with
Bun.gc(true)and short sleeps, up to 50 rounds, and stop as soon as the objects are gone. Bun scans the stack conservatively and runs leave timers behind, so a single round was flaky, mainly under roundtrip. Both tests passed with--rerun-each 5, normal andPSYCHOSCRIPT_ROUNDTRIP=1.Supersedes #197 (thanks @kommander for finding it)