bobbai00 commented on code in PR #8753:
URL: https://github.com/apache/texera/pull/8753#discussion_r4319200425
##########
agent-service/src/agent/texera-agent.ts:
##########
@@ -498,17 +498,23 @@ export class TexeraAgent {
}
async sendMessage(userMessage: string, messageSource?: "chat" | "feedback"):
Promise<AgentMessageResult> {
- const messageId =
`msg-${this.agentId}-${++this.messageCounter}-${Date.now()}`;
- let stepIndex = 0;
-
- await this.refreshWorkflowFromBackend();
-
+ // State flips synchronously, before the first await below, so a second
+ // prompt arriving while this one is mid-flight (e.g. during
+ // refreshWorkflowFromBackend) sees GENERATING and is rejected instead of
+ // interleaving with this run's head/abortController/currentMessageId
(#8711).
+ if (this.state !== AgentStateEnum.AVAILABLE) {
+ throw new Error("Agent is busy processing another message");
+ }
+ this.state = AgentStateEnum.GENERATING;
this.abortController = new AbortController();
- this.state = AgentStateEnum.GENERATING;
+ const messageId =
`msg-${this.agentId}-${++this.messageCounter}-${Date.now()}`;
+ let stepIndex = 0;
this.currentMessageId = messageId;
+ await this.refreshWorkflowFromBackend();
Review Comment:
valid
##########
agent-service/src/agent/texera-agent.ts:
##########
@@ -498,17 +498,23 @@ export class TexeraAgent {
}
async sendMessage(userMessage: string, messageSource?: "chat" | "feedback"):
Promise<AgentMessageResult> {
- const messageId =
`msg-${this.agentId}-${++this.messageCounter}-${Date.now()}`;
- let stepIndex = 0;
-
- await this.refreshWorkflowFromBackend();
-
+ // State flips synchronously, before the first await below, so a second
+ // prompt arriving while this one is mid-flight (e.g. during
+ // refreshWorkflowFromBackend) sees GENERATING and is rejected instead of
+ // interleaving with this run's head/abortController/currentMessageId
(#8711).
+ if (this.state !== AgentStateEnum.AVAILABLE) {
Review Comment:
valid
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]