HarnessGateway.runWakeup throws NPE for external session ids when no outbound route is recorded (route registry gap)
Summary
HarnessGateway.runWakeup(String userId, String sessionId) throws a NullPointerException during RuntimeContext assembly when the given session id has a resolvable gate key but no outbound route — which is exactly the situation for external (application-assigned) session ids driven through ChatUiChannel, e.g. by WakeupDispatcher after a background task completes.
Environment
- AgentScope Java 2.0.4 (
io.agentscope:agentscope-harness:2.0.4, verified against the 2.0.4 sources jar)
Analysis (2.0.4 sources)
runWakeupresolves the gate key first and safely skips unknown sessions:
// HarnessGateway.java:641-646
String gateKey = resolveSessionGateKey(sessionId);
if (gateKey == null) {
log.debug("runWakeup: unknown sessionId={}, skipping", sessionId);
return Mono.empty();
}
- But when the gate key resolves, the outbound address is put into the RuntimeContext unconditionally:
// HarnessGateway.java:651-655
RuntimeContext.Builder rtcBuilder =
RuntimeContext.builder()
.sessionId(sessionId)
.put("gateKey", gateKey)
.put("outboundAddress", resolveRoute(sessionId)); // <-- may be null
RuntimeContext.Builder.putstores into aConcurrentHashMap, which rejects null values → NPE at assembly time (the wakeup round never starts):
// RuntimeContext.java:375-380
public Builder put(String key, Object value) {
...
this.stringExtras.put(key, value); // ConcurrentHashMap
}
- Why the route is missing for external ids: routes are only recorded when
runStreamdelivers to a channel, under the gateway's own generated session id (gw-...), inlastRouteBySession/ theROUTE_NAMESPACEstore (resolveRoute, HarnessGateway.java:778-803). An external session id only ever gets a gate key:- via
registerExternalSession(HarnessGateway.java:588-597), which writes only the SESSION_NAMESPACE mapping — no route, and - there is no public API to register a route for an external session id.
- via
So for application-driven sessions: gateKey ✔, route ✘ → step 2 NPEs.
Reproduction
- Build a
GatewayBootstrapwith aHarnessAgentand drive turns throughchatUiChannel.sendStream(SendOptions.of(userId, businessSessionId), msgs)(the channel resolves its own internalgw-...session id internally). - Register the external session:
gateway.registerExternalSession(businessSessionId, gateKey). - Enqueue a wakeup for it on the shared bus:
bus.enqueueWakeup(userId, businessSessionId, agentId). WakeupDispatcherdrains the queue and callsHarnessGateway.runWakeup(userId, businessSessionId)→ NPE (ConcurrentHashMap.put(key, null)), the wakeup round never runs.
Expected behavior
One of:
- Tolerate a missing route the same way an unknown session is tolerated — skip the
outboundAddressentry (or the whole wakeup) with a debug log; - or let
registerExternalSession(a new overload) also record the outbound route for the external session id.
The unknown sessionId, skipping branch suggests "skip when not resolvable" is already the intended semantics — the route lookup just wasn't given the same treatment.
Workaround we currently ship
A custom WakeupDispatcher.WakeupTarget that never calls HarnessGateway.runWakeup: it drains the session inbox itself and drives the round via channel.sendStream(SendOptions.of(userId, sessionId), ...) — functionally equivalent push-back without touching the route registry.