Repository navigation
[lf.agentic.Session] Keep results that come in after an action's deadline. - #788
Merged
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1008473954
branch
25 times, most recently
from
October 28, 2026 18:29
639bb0b to
828df1d
Compare
…adline.
* While the session calls its event handler, it sets a thread-local flag
(`Session._running_event_handler()`), and `_log` skips the deadline check
under that flag. The flag is cleared again for the body of every action,
including one that a handler starts. So only logs that event handlers write
themselves, such as those of `lf.agentic.SessionLogging`, are exempt: a log
from an action (`session.info(...)` in `call`) is still a cancellation
point, as are query starts, action starts and `concurrent_map`, even when a
handler makes them. The flag covers every handler and leaves the handler
API unchanged. It is per thread, like the current action, so a handler
running on one thread does not exempt the logs that actions write on other
threads.
* `lf.query` marks a successful query completed in the `else` clause of its
`try`. An error raised there, for example by a `track_queries` end
callback, propagates as itself instead of
`AssertionError('Query is already completed.')`, and the query is marked
completed once.
* `Session.track_action` restores the parent action and execution in a
`finally`, so they are restored even when `on_action_end` raises.
* `Session.concurrent_map` turns a `TimeoutError` that escapes after the
action's deadline into `ActionTimeoutError`, as its docstring now says. Its
per-item timeout is capped at the action's remaining time, so after the
deadline such a timeout means that the action ran out of time. Before, this
happened only as a side effect of the deadline check in handler logs
(`SessionTest.test_max_execution_time` relies on it); a `TimeoutError`
within the budget is still raised as is.
Behavior change: in a session with a time budget, a model reply or an action
result that comes in after the deadline is now kept, logged and seen by every
handler, and an error raised after the deadline surfaces as itself instead of
being replaced by `ActionTimeoutError` (except the `concurrent_map` timeout
above). The action's next log, query, sub-action or `concurrent_map` after the
deadline still raises `ActionTimeoutError`. In any session, an error raised in
an `lf.query` end callback, including a session's `on_query_end` handler, now
reaches the caller as itself instead of `AssertionError`, and the current action
is restored even when `on_action_end` raises.
PiperOrigin-RevId: 1009059402
copybara-service
Bot
force-pushed
the
test_1008473954
branch
from
October 28, 2026 18:36
828df1d to
deae0c9
Compare
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.
[
lf.agentic.Session] Keep results that come in after an action's deadline.(
Session._running_event_handler()), and_logskips the deadline checkunder that flag. The flag is cleared again for the body of every action,
including one that a handler starts. So only logs that event handlers write
themselves, such as those of
lf.agentic.SessionLogging, are exempt: a logfrom an action (
session.info(...)incall) is still a cancellationpoint, as are query starts, action starts and
concurrent_map, even when ahandler makes them. The flag covers every handler and leaves the handler
API unchanged. It is per thread, like the current action, so a handler
running on one thread does not exempt the logs that actions write on other
threads.
lf.querymarks a successful query completed in theelseclause of itstry. An error raised there, for example by atrack_queriesendcallback, propagates as itself instead of
AssertionError('Query is already completed.'), and the query is markedcompleted once.
Session.track_actionrestores the parent action and execution in afinally, so they are restored even whenon_action_endraises.Session.concurrent_mapturns aTimeoutErrorthat escapes after theaction's deadline into
ActionTimeoutError, as its docstring now says. Itsper-item timeout is capped at the action's remaining time, so after the
deadline such a timeout means that the action ran out of time. Before, this
happened only as a side effect of the deadline check in handler logs
(
SessionTest.test_max_execution_timerelies on it); aTimeoutErrorwithin the budget is still raised as is.
Behavior change: in a session with a time budget, a model reply or an action
result that comes in after the deadline is now kept, logged and seen by every
handler, and an error raised after the deadline surfaces as itself instead of
being replaced by
ActionTimeoutError(except theconcurrent_maptimeoutabove). The action's next log, query, sub-action or
concurrent_mapafter thedeadline still raises
ActionTimeoutError. In any session, an error raised inan
lf.queryend callback, including a session'son_query_endhandler, nowreaches the caller as itself instead of
AssertionError, and the current actionis restored even when
on_action_endraises.