Skip to content

ASDP: Heartbeat upstream messages don't refresh agent_instances.last_seen_at, so idle External Agents are marked unhealthy ~45s after connecting and never get dispatched #3659

Description

@Shaw-shaw

Summary

An External Agent instance (binding.kind = external-application) connected over ASDP gRPC is marked unhealthy by the control plane roughly 45-55 seconds after connecting, even though it is sending Heartbeat messages every 15s exactly as designed and the connection is never actually dropped. Once marked unhealthy, the scheduler's available() check (internal/scheduler/scheduler.go) never selects that instance again, so AgentTasks assigned to it stay in queued forever — the outbox event just keeps retrying with "policy runtime candidate 0 is unavailable" and never delivers.

This affects every External Agent built with agentscope-extensions-controlplane (Java SDK) that doesn't otherwise have an active session reporting state — i.e. exactly the common "freshly registered, idle, waiting for the platform to dispatch the first task" situation.

Root cause

  • internal/controller/control_outbox_dispatcher.go dispatches a queued AgentTask via Scheduler.DispatchTask → dispatchTask → selectCandidate/selectOrderedCandidate → Resolver.available(ctx, task, candidate).
  • For DataPlaneExternalApplication bindings, available() (internal/scheduler/scheduler.go) only returns true if instance.Health == controlmodel.RuntimeHealthHealthy.
  • Health is maintained by RuntimeControlSweeper (cmd/service-controlplane/main.go, flag -runtime-offline-timeout, default 45s), which marks an instance unhealthy once last_seen_at is older than that timeout.
  • last_seen_at is only refreshed by specific upstream ASDP message handlers in internal/asdp/service.go's Connect() receive loop (handleSessionReport, handleExecutionAttempt, handleEventReport, handleContextReport, handleInventoryReport, handleConversationTurnReport).
  • The Upstream_Heartbeat case in that same switch (around line 173) does not call into any of those handlers or otherwise touch the runtime registry — it only echoes a Downstream_Heartbeat ack back to the client:
case *Upstream_Heartbeat:
    if err := conn.Send(&Downstream{
        Payload: &Downstream_Heartbeat{Heartbeat: &Heartbeat{Timestamp: p.Heartbeat.Timestamp}},
    }); err != nil {
        logger.V(1).Info("heartbeat response failed", "instance", meta.InstanceKey)
    }
  • The Java SDK's GrpcTransport (agentscope-extensions-controlplane) sends exactly this Heartbeat message every 15s (HEARTBEAT_INTERVAL_MS = 15_000L) and nothing else while the instance is idle with no active sessions — there is no other upstream report type to send until a session/task actually exists. So for a freshly-registered, idle External Agent, last_seen_at is set once at connect time and never refreshed again, and the sweeper reliably flips it to unhealthy ~45s later.

Reproduction

  1. Register a Java External Agent via agentscope-extensions-controlplane's ControlPlane.newBridge(...) with startGrpc(true), enableEvents(true), pointing controlPlane at the control plane's ASDP gRPC address.
  2. Confirm the handshake: control-plane logs show "asdp-connect" "handshake accepted" and "asdp" "data plane connected".
  3. Query rt.agent_instances for that agent_id/binding_id repeatedly over the next ~60s:
    select instance_key, health, last_seen_at, generation, updated_at
    from rt.agent_instances where agent_id = '<agent-id>';
    last_seen_at stays pinned to the connect timestamp; health flips from whatever it started as to unhealthy ~45-55s after connect, and never recovers.
  4. Create an Issue directly assigned to that Agent (POST /api/v1/issues with assigneeType: "agent"). The resulting AgentTask stays status: "queued" indefinitely.
  5. Check rt.control_outbox for the agent-task.queued.v1 event on that task:
    select event_type, attempts, last_error from rt.control_outbox where aggregate_id = '<task-id>';
    last_error reads "control event delivery deferred: policy runtime candidate 0 is unavailable", with attempts climbing indefinitely.

Reproduced this 3 times across independent connections (generations 3, 4, 5 in our test), each time the instance went unhealthy 48-54 seconds after connecting — consistent with the 45s runtime-offline-timeout plus sweep-interval slop, and consistent with "last_seen_at never updated after connect."

Confirmed with FINE-level java.util.logging enabled on the SDK side that the client never logs a reconnect/stream-error during this window — the gRPC stream stays up the whole time from the client's perspective. The problem is entirely server-side: heartbeats arrive and are acked, but are never recorded as a liveness signal.

Expected behavior

Receiving an Upstream_Heartbeat should refresh the instance's last_seen_at (and implicitly keep/restore health = healthy), the same way the other upstream report types do — a heartbeat's entire purpose is to prove liveness to exactly this kind of staleness check.

Suggested fix

In internal/asdp/service.go, the case *Upstream_Heartbeat: branch should call the same kind of liveness-refresh the other handlers use (e.g. whatever HeartbeatAgentInstance/last_seen_at update path handleSessionReport etc. ultimately reach), in addition to sending the ack.

Environment

  • agentscope-service BETA1 Docker Compose deployment (as-controlplane:2.1.0-BETA1), ASDP gRPC exposed from the container on its existing internal port (:15010).
  • Client: agentscope-extensions-controlplane:2.1.0-BETA1 (Java), registered as an external-application binding, SDK version 0.1.0.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions