feat(callback): expose active lifecycle hook metadata - #6995
Open
kaligautier wants to merge 1 commit into
Open
Conversation
Expose immutable callback-scoped metadata through Context so shared callbacks can identify the lifecycle hook that invoked them. Keep the value task-local to isolate concurrent invocations. Closes google#6979 NO_UNIT_GUIDE=This extends the existing Context API and does not introduce a standalone code unit.
kaligautier
force-pushed
the
feat/callback-metadata-issue-6979
branch
from
September 3, 2026 13:50
33c7728 to
c861259
Compare
Contributor
Author
|
Hi @DeanChensj, I’ve rebased the PR onto the latest main and resolved the conflict. It is mergeable again. Thanks! |
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.
Link to Issue or Description of Change
Problem:
Callbacks reused across lifecycle stages cannot determine which hook invoked them from the context they receive.
Solution:
Expose immutable
CallbackInvocationInfothroughContext.callback_infowhile a callback is running. The hook value is task-local, so nested or concurrent invocations cannot leak metadata into one another. Both canonical callbacks and plugin callbacks are covered, and the value resets toNoneoutside callback execution.Testing Plan
Unit Tests:
Results:
247 passed13,680 passed; the one sandbox-only loopback networking failure passes when rerun with local networking enabledpre-commit run --from-ref origin/main --to-ref HEAD: passedManual End-to-End (E2E) Tests:
Ran an
InMemoryRunnerwith aMockModeland shared before/after model callbacks. The callbacks observed the expected scoped values and the context reset after execution:Checklist
Additional context
The remaining local Anthropic failures are also present without this change and come from the installed SDK version lacking
OutputTokensDetails; this PR does not modify Anthropic code or dependency files.