Skip to content

Reattach in-flight action results to the replacement agent stream #483

Done

Description

@samuelmbabhazi

Problem

An action can complete successfully on the agent after a connection interruption without reporting its outcome to the replacement connection. If the control plane redelivers the action while it is still running, the dispatcher ignores that delivery, but the running action still sends updates to its original, disconnected session.

This can leave the control plane waiting until the action expires and make a deployment fail despite a completed local effect. A further reconnection after completion can recover the journaled outcome; that extra reconnection should not be necessary.

Audited revision: 1295e534d7a1c3cd0a492449de8806aa532a4924.

A pre-publication comparison of this snapshot with main 2ee78ff1e96118b1732b98bc54c99f5f91b95a32 found that the only intervening change was to apps/api/src/modules/deployments/application/exec-sessions.spec.ts. None of the affected production paths changed.

Scenario and evidence

  1. The agent starts an action on connection A. Its effect remains in progress.
  2. Connection A ends. The action continues, as intended, under the agent's lifetime.
  3. The agent opens connection B. The control plane redelivers the unfinished action once.
  4. The dispatcher sees that the same action ID is running and returns without subscribing connection B to its progress or result.
  5. The action succeeds in the local journal. Its updates still target A, so B receives no terminal update.

The relevant code paths are:

Verification and limits

An isolated Go test used the production Dispatcher and SQLite journal, with a blocked step and two simulated session callbacks. The first callback was disabled, the same action was delivered to the second callback while still running, and the step was released. With the race detector enabled, the test observed:

  • zero updates on the replacement callback;
  • a completed local operation;
  • the durable success returned by a further delivery after completion, without rerunning the effect.

This was a bounded component test, not a real gRPC reconnection or VM test. The control plane's once-per-stream behavior was verified in source. No production deployment was interrupted.

Proposed correction

Make action progress/result delivery independent of the session that started execution. A replacement session should attach to an existing action and receive its latest durable state and subsequent outcome. Alternatively, use explicit acknowledgements and bounded redelivery until a terminal result is acknowledged. Preserve idempotency and release subscriptions when streams end.

Acceptance criteria

  • A transport integration test disconnects during an action, reconnects before it finishes, then observes the terminal result on the replacement stream without a third connection.
  • The side effect executes once; concurrent duplicate deliveries do not create duplicate execution.
  • Reconnection after completion still replays the stored result, including the action result payload.
  • Repeated stream replacement does not retain obsolete callbacks or block the executor.

Related work

Follow-up to closed #14, #15, and #134. Those cover enrollment, journaling and basic replay; this issue specifically covers redelivery while the original execution is still running. It does not require the future failover/lease implementation in #227.

Activity

  1. added
    bug
    priority:P1
    v0.1-stable
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:P1track:cross-cuttingv0.1-stable

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions