[codex] Add exit-aware lexical cleanup#240
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5b02ce85c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c5304405b0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88628654c2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e88c7fdef2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (exit === undefined) return undefined as A | ||
| released = true | ||
| if (isSuccessExit(exit)) { | ||
| yield* andFinally(r, toRegionExit(exit)) |
There was a problem hiding this comment.
Resume successful bracket cleanup exits outside the mask
When the bracket body succeeds but this release callback exits via a scoped control effect such as returnFrom or abort to an enclosing withScope, the effect is yielded while the uninterruptibleMask token is still active. ScopeBoundary consumes that control effect without resuming this iterator, so the mask-end in the outer finally never runs and run throws Interrupt mask invariant failed instead of returning the cleanup exit. The failure path avoids this by capturing cleanup with returnExit and resuming it through restore(...); the successful-body path needs equivalent handling for cleanup exits.
Useful? React with 👍 / 👎.
| if (exit === undefined) return undefined as A | ||
| finalized = true | ||
| if (isSuccessExit(exit)) { | ||
| yield* finally_(toRegionExit(exit)) |
There was a problem hiding this comment.
Resume successful finalizer exits outside the mask
When the protected program succeeds and an exit-aware cleanup returns a scoped control exit, e.g. ok('body').pipe(finalizing(() => returnFrom(S, 'cleanup')), withScope(S), run), this line yields that effect while the surrounding uninterruptibleMask is still active. The matching scope handler consumes the control effect without resuming this iterator, so the mask cleanup is skipped and run fails with Interrupt mask invariant failed; the non-success branch already avoids this by capturing the cleanup exit and re-emitting it through restore(...).
Useful? React with 👍 / 👎.
Summary
bracketandfinalizingso cleanup can inspect lexical region exits.RegionExittype for scope-less lexical exits, while preserving existing scopedExitforFinally-related APIs.bracketrelease andfinalizing(Fx)code paths for compatibility.Notes
This is a prototype PR. Scope-owned finalizers still receive
Exit, where scoped control exits have a resolved concrete scope. Exit-aware lexical cleanup now receivesRegionExit, so pre-boundary observations ofreturnFrom,abort, andinterruptFromdo not expose raw or unresolved scope tokens.For external task interruption before a typed exit is available, lexical cleanup receives
{ type: 'interrupted' }or{ type: 'interrupted', reason }.Callback cleanup exits are captured and combined with the primary lexical exit before resuming, matching the existing
finalizing(Fx)cleanup-exit behavior. That preserves primary failures across cleanupreturnFrom/abort/interruptFromexits and transactional rollback decisions.Validation
corepack pnpm buildcorepack pnpm typecheckcorepack pnpm lintcorepack pnpm test