Skip to content

Track the context lock grant by generation instead of identity - #2306

Open
fzyzcjy wants to merge 1 commit into
tom/refactor-miles/op13-123from
tom/refactor-miles/op13-164
Open

Track the context lock grant by generation instead of identity#2306
fzyzcjy wants to merge 1 commit into
tom/refactor-miles/op13-123from
tom/refactor-miles/op13-164

Conversation

@fzyzcjy

@fzyzcjy fzyzcjy commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Part of #1837

@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from 5c3ea6c to 3d6d377 Compare August 10, 2026 16:33
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch 2 times, most recently from da51a5d to 78fa1e8 Compare August 12, 2026 02:48
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from 3d6d377 to 713dea7 Compare August 12, 2026 02:48
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch from 78fa1e8 to 582433e Compare August 12, 2026 09:32
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from 2dcc80e to ee4fcd8 Compare August 12, 2026 14:31
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch from 582433e to 4b77013 Compare August 12, 2026 14:31
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from ee4fcd8 to 8ac71f7 Compare August 12, 2026 14:36
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch from 4b77013 to 353701e Compare August 12, 2026 14:36
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from 8ac71f7 to df3785e Compare August 12, 2026 23:56
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch 2 times, most recently from 9cda90f to b9f6c85 Compare August 13, 2026 01:13
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from df3785e to ba00f18 Compare August 13, 2026 01:13
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch 2 times, most recently from fdd4378 to e4d25da Compare August 13, 2026 03:25
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from 60ddb90 to bc4c262 Compare August 13, 2026 06:00
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch from e4d25da to b792f3e Compare August 13, 2026 06:00
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from bc4c262 to 0897379 Compare August 13, 2026 06:39
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch 2 times, most recently from 548c5ac to eb802e1 Compare August 14, 2026 04:45

@guapisolo guapisolo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generation-scoped grants now expire child-task authorization at release/detach while preserving in-section fan-out and cross-task reattach. Verified in PR #2306 before safe merge checkpoint #2176.

A child task spawned inside a critical section inherits the holder's
contextvars, so under the identity model it kept believing it held the
lock after the holder let go. Stamp each grant with a generation the lock
invalidates on release, detach and re-acquire, so an inherited grant
expires the moment the section it belonged to ends.

detach() expires the generation rather than merely clearing the holder's
own contextvar, and reattach() issues a fresh one behind a locked-state
assert, so no grant can outlive its window or name a generation that is
no longer active. acquire() and reattach() share one check: a live grant
blocks, an expired one does not.

Tests not executed (test run ban); statically checked only.
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-123 branch from cfca09e to ca730fd Compare August 29, 2026 12:38
@fzyzcjy
fzyzcjy force-pushed the tom/refactor-miles/op13-164 branch from eb802e1 to 6adfc83 Compare August 29, 2026 12:38
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.

2 participants