Skip to content

Release source rebinding closures after tokenization - #1011

Merged
bradhilton merged 3 commits into
mainfrom
hayek/rebind-success-lifetime-20260928
Sep 28, 2026
Merged

bradhilton merged 3 commits into
mainfrom
hayek/rebind-success-lifetime-20260928

Conversation

@bradhilton

@bradhilton bradhilton commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Successful trajectory, trace and group tokenization kept completed source graphs alive until cyclic GC after the caller dropped both the input and result. _rebind_history_sources retained its canonical exchanges through the recursive visitor's self-referencing closure. Clear that closure cell in finally, including when rebinding raises, so unowned graphs release promptly.

The public reproduction retained 32 of 32 completed inputs with GC disabled before the change and 0 of 32 afterward. Regression tests cover caller-held inputs/results, canonical source aliases, actual replacement of copied exchanges, repeated calls, callback/error ownership and finalizers that invoke nested rebinding.

Validation: 61 focused lifetime, model and parallel-tokenization tests passed on the production patch; all 21 final lifetime controls passed, including five new cases that fail against the original helper. Changed-file type and Ruff checks passed.

Fixes #1010.

@bradhilton
bradhilton marked this pull request as ready for review September 28, 2026 11:47
@bradhilton
bradhilton merged commit 99f3fd0 into main Sep 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release source-rebinding closure after successful trajectory tokenization

1 participant