Repository navigation
fix(gateway): a state trigger checks once more when a write lands while its check runs - #699
Merged
earakely-scale merged 3 commits intoNov 16, 2026
Conversation
…le its check runs A watched write found a state trigger already evaluating and asked nothing of it, so a check that had read the state from before the write could end unmatched and leave the trigger armed although its condition now held, until some later write. A write that lands while the check runs now marks it for a re-check, which runs once the check ends unmatched, and a match is detected as that write's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… checked again nor detected A removed trigger kept its armed status, so a re-check asked for before the removal could run it again and detect it, and so could its own slow check that matched afterwards, as on main. A check now repeats and detects only while the engine still holds that trigger, armed; one re-added under the same id is a new trigger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore the check that matched A write landing after a state check was scheduled but before it started asked for a recheck that the check's start cleared, so a match was detected as the earlier write. Each check now starts from the latest write that asked for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
deleted the
edgararakelyan/fd-5875-gateway-state-triggers-miss-a-write
branch
November 16, 2026 03:14
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.
What
A gateway state trigger (
when.type == "state") could miss a write that landed while its check was running (FD-5875).TriggerEngine._reevaluate_statesskipped any state trigger whoseevaluatingflag was set._eval_statecleared the flag when its check ended, and nothing ran the check again.its condition held, until some later watched write.
curbfinch-furnish-house), the agent'sSave search click is a watched tool call. Its re-check can run before the page's POST commits, and the POST, a
watched website request, then found the check under way and was dropped. The rug was posted only at the agent's
next call; that app's e2e test clicks once more to get past it.
How
_reevaluate_states: a write that finds a state trigger's check under way records itself (recheck) instead ofdoing nothing.
_eval_state: if the check ends unmatched while the trigger is armed and a re-check was asked for meanwhile, itruns the check again. That repeats as long as writes keep landing during checks. Each check starts from the latest
write that asked for it, including one that landed after it was scheduled but before it started. A match is
detected as that write: the last write before the check that matched. When several land during one check, that's
the last of them, which may not be the one that made the condition hold.
evaluatingandrecheckare cleared when the checks end, however they end.trigger removed during its check, or replaced under its id, no longer acts. That includes the case on
mainof aremoved trigger's own slow check matching afterwards.
Proof
tst/unit/env/gateway/triggers_test.py::test_a_write_landing_while_a_state_check_runs_has_it_checked_once_morereproduces the race:
it-now-holds: the trigger fires, detected as the second write (gdocs_append_text);it-still-doesnt: the check runs once more and the trigger stays armed;main(one read; the trigger stays armed);test_a_state_trigger_removed_while_its_check_runs_is_neither_checked_again_nor_detectedcovers a removal with are-check asked for, and a removal during the trigger's own check that then matches. Both fail without the guard.
test_a_write_landing_before_a_scheduled_state_check_starts_is_the_one_it_is_detected_aschecks the attribution.It fails without the change.
tst/unit/env/gateway: 1054 passed.Notes
deterministically. The gateway integration tier covers the existing triggers.
steps caused a watched write through some outside path (for example by driving a browser) would keep re-checking
until it matched. Nothing in the repository does that (a check's own reads skip the triggers), so there's no cap.
click after saving the search.
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
State triggers now check again when a watched write arrives during an unfinished check.
Reviews (6) · Last reviewed commit: "fix(gateway): a state check's match is d..." · Reviewed by Greptile