Repository navigation
fix(triggers): bound host-executed trigger runs with a deadline (toby) - #4135
Merged
OliverBryant merged 2 commits intoDec 3, 2026
Merged
Conversation
The engine awaited a host trigger executor with no limit, so a hung host run stayed RUNNING forever and held its release-ledger slot. Run the executor under XAGENT_HOST_TRIGGER_RUN_TIMEOUT_SECONDS (default 1800s, matching the host's scheduled-run deadline). On expiry cancel the coroutine (abandoning one that ignores cancellation after a short grace), settle the run FAILED with a timeout reason, and release the ledger slot. A late-finishing host cannot overwrite the terminal state: the terminal write only moves RUNNING rows.
rogercloud
approved these changes
Dec 3, 2026
rogercloud
left a comment
Collaborator
There was a problem hiding this comment.
Major
src/xagent/web/services/triggers.py:2321— Abandoning an executor that ignores cancellation (deadline or shutdown path) ends the lifecycle task, sorelease_hold.adoptfrees the ledger slot while host code is still running andunsettled_totalstays at 0; a planned release then reads the process as drained/settled. Callrelease_hold.record_unsettled(...)when abandoning (and keep a reference to the task, see inline).
Minor
src/xagent/web/services/triggers.py:2346— A malformedXAGENT_HOST_TRIGGER_RUN_TIMEOUT_SECONDSpasses boot and fails every host run as "Host executor failed". Validate it at startup alongsidevalidate_activation_timeouts.src/xagent/web/services/triggers.py:2362— A second cancel during the deadline grace wait skips abandon/exception retrieval and records "Cancelled" instead of the timeout. The outer-cancel branch also never retrieves an exception raised during the grace. One_cancel_with_gracehelper fixes both and removes the duplicated sequence.src/xagent/web/services/trigger_executors.py:42— The host-facing contract still says the callable "may run for a long time". Document the deadline, that cancellation must be honoured, the 10s abandon grace, and that the executor now runs in its own Task.tests/web/api/test_host_executed_triggers.py:902— The late-host test depends on sleep margins, it re-tests the pre-existing RUNNING guard by hand, and the shutdown path with a stubborn executor is untested.example.env:2263— The new entry sits inside the activation-bounds block; move it next toXAGENT_TRIGGER_DISPATCHER_*.
Simplification
- tests/web/api/test_host_executed_triggers.py L886: shrink: the stubborn test inlines the
fire_trigger+ session open/close sequence. Callawait _fire_host_run_async(trigger_id, "evt-late").
net: -12 lines possible
Blocking: no — recommended event: APPROVE
…ate the run timeout at boot Abandoning an executor that ignores cancellation now records the run as unsettled in the release ledger, the cancel-and-grace logic is shared by the deadline and shutdown paths (always consuming the task outcome and keeping the timeout reason), and the run timeout is validated at startup with the activation timeouts.
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.
Part of xorbitsai/xagent-saas#3607
The engine awaited a host trigger executor with no deadline, so a hung host run stayed
RUNNINGforever and held its release-ledger slot (found in review of xorbitsai/xagent-saas#3754).XAGENT_HOST_TRIGGER_RUN_TIMEOUT_SECONDS(default 1800s, the same as the host's scheduled-run deadline; must be positive and finite).FAILEDwithTimeoutError: host executor exceeded the <n>s run deadline, the trigger'slast_erroris set, and the ledger slot is released as before.RUNNINGrows.Tests: normal completion, hung run (cancelled + failed + lease released), and a host that swallows cancellation and finishes late. Mutation-checked: no deadline, no cancel, a removed status guard and awaiting an uncancellable host all fail the tests.