Class PendingAbortRegistry

java.lang.Object
com.google.genkit.ai.agent.internal.PendingAbortRegistry

public final class PendingAbortRegistry extends Object
Registry mapping a still-PENDING detached turn's snapshot id to the live AtomicBoolean abort signal handed to that turn's AgentFnContext.

This is the only case where an external caller can know a turn's snapshot id WHILE the turn is still running: DetachController.detach(...) writes the pending snapshot and returns its id immediately, before the background work finishes. Foreground turns have no resolvable id until after they return, so there is no reachable window in which to abort them externally — the registry intentionally only covers detached turns.

DetachController.detach(com.google.genkit.ai.agent.SessionRunner<S>, com.google.genkit.ai.agent.SessionStore<S>, com.google.genkit.ai.agent.SessionStoreOptions, com.google.genkit.ai.agent.internal.StreamEmitter<S>, java.util.concurrent.atomic.AtomicBoolean, com.google.genkit.ai.agent.internal.DetachController.DetachedTurn<S>) registers the signal for a snapshot id when the background turn starts, and removes it in a finally block when the turn finishes (success, failure, or abort) so entries never leak. Agent.abort(String) looks up the signal and flips it (in addition to the existing snapshot-store status mutation, which remains the source of truth for anything that reads the snapshot after the fact, e.g. a poller that only checks status).

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    register(String snapshotId, AtomicBoolean signal)
    Registers signal as the abort flag for the pending detached turn identified by snapshotId.
    static boolean
    signal(String snapshotId)
    Flips the abort signal registered for snapshotId to true, if one is currently registered (i.e. the turn is a still-running detached turn).
    static void
    unregister(String snapshotId)
    Removes the registration for snapshotId, if present.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • register

      public static void register(String snapshotId, AtomicBoolean signal)
      Registers signal as the abort flag for the pending detached turn identified by snapshotId.
      Parameters:
      snapshotId - the pending snapshot id
      signal - the abort signal handed to that turn's AgentFnContext
    • unregister

      public static void unregister(String snapshotId)
      Removes the registration for snapshotId, if present. Safe to call more than once.
      Parameters:
      snapshotId - the pending snapshot id
    • signal

      public static boolean signal(String snapshotId)
      Flips the abort signal registered for snapshotId to true, if one is currently registered (i.e. the turn is a still-running detached turn).
      Parameters:
      snapshotId - the snapshot id to signal
      Returns:
      true if a signal was found and flipped; false if no turn is currently registered under that id (already finished, foreground, or unknown)