Skip to content

fix(gateway): a state trigger checks once more when a write lands while its check runs - #699

Merged
earakely-scale merged 3 commits into
mainfrom
edgararakelyan/fd-5875-gateway-state-triggers-miss-a-write
Nov 16, 2026
Merged

earakely-scale merged 3 commits into
mainfrom
edgararakelyan/fd-5875-gateway-state-triggers-miss-a-write

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

A gateway state trigger (when.type == "state") could miss a write that landed while its check was running (FD-5875).

  • How the write went missing:
    • TriggerEngine._reevaluate_states skipped any state trigger whose evaluating flag was set.
    • _eval_state cleared the flag when its check ended, and nothing ran the check again.
    • So a check that read the state from before a write could end unmatched. The trigger then stayed armed although
      its condition held, until some later watched write.
  • Where it shows: a website app's world. In synthetic-pipelines' Curbfinch (curbfinch-furnish-house), the agent's
    Save 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 of
    doing nothing.
  • _eval_state: if the check ends unmatched while the trigger is armed and a re-check was asked for meanwhile, it
    runs 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.
  • Clean-up: evaluating and recheck are cleared when the checks end, however they end.
  • Removed triggers: a check repeats, and detects, only while the engine still holds that trigger and it's armed. A
    trigger removed during its check, or replaced under its id, no longer acts. That includes the case on main of a
    removed 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_more
reproduces the race:

  • the first write's check reads the state before the second write, then answers late;
  • the second write, another tool, lands while that check runs;
  • 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;
  • in both, the check reads twice and the flags are clear afterwards;
  • both cases fail on main (one read; the trigger stays armed);
  • test_a_state_trigger_removed_while_its_check_runs_is_neither_checked_again_nor_detected covers a removal with a
    re-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_as checks the attribution.
    It fails without the change.
  • tst/unit/env/gateway: 1054 passed.

Notes

  • Not run on a live gateway: the race needs a check that answers late, which the engine-level test sets up
    deterministically. The gateway integration tier covers the existing triggers.
  • Checks that write: the re-checks repeat only while watched writes keep landing during checks. A check whose own
    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.
  • Curbfinch's workaround: once a release has this, Curbfinch's e2e test in synthetic-pipelines can drop its extra
    click after saving the search.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

State triggers now check again when a watched write arrives during an unfinished check.

  • State triggers check again when a watched write lands during a check.

Reviews (6) · Last reviewed commit: "fix(gateway): a state check's match is d..." · Reviewed by Greptile

…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>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 15, 2026 16:58
Comment thread src/agent_env/env/gateway/triggers.py Resolved
earakely-scale and others added 2 commits November 15, 2026 09:02
… 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
earakely-scale merged commit 69b7fc9 into main Nov 16, 2026
62 of 65 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd-5875-gateway-state-triggers-miss-a-write branch November 16, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant