Describe the bug
For a Think sub-agent, connection state set during onConnect can be lost before the first client message. Immediately after connection.setState(...), connection.state is correct; when the first message arrives on the same connection, it is null.
To Reproduce
- Connect a browser to a
Think instance through a parent Agent as a sub-agent.
- In
onConnect, call:
connection.setState({ userId: "user-123" });
- Immediately send a chat message.
- Read
connection.state while handling that message.
- Observe that the state is
null.
Expected behavior
Connection state set in onConnect should be available to subsequent messages on that connection.
Version:
agents@0.22.0
@cloudflare/think@0.17.0
Additional context
This appears to be a regression from agents@0.20.1. It only reproduces through the sub-agent/facet connection path.
A suspected cause is the operation queue added in PR #2090: Think sends initial connection frames before application onConnect, so setState is queued behind them. The connect handler can finish before the state reaches the root socket, allowing the first client frame to replay stale null metadata into the sub-agent.
Describe the bug
For a Think sub-agent, connection state set during
onConnectcan be lost before the first client message. Immediately afterconnection.setState(...),connection.stateis correct; when the first message arrives on the same connection, it isnull.To Reproduce
Thinkinstance through a parent Agent as a sub-agent.onConnect, call:connection.statewhile handling that message.null.Expected behavior
Connection state set in
onConnectshould be available to subsequent messages on that connection.Version:
agents@0.22.0@cloudflare/think@0.17.0Additional context
This appears to be a regression from
agents@0.20.1. It only reproduces through the sub-agent/facet connection path.A suspected cause is the operation queue added in PR #2090: Think sends initial connection frames before application
onConnect, sosetStateis queued behind them. The connect handler can finish before the state reaches the root socket, allowing the first client frame to replay stalenullmetadata into the sub-agent.