Repository navigation
fix(agent-service): reject prompts sent while a run is in flight - #8753
Conversation
Automated Reviewer SuggestionsBased on the
|
Backport auto-label reportThis
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8753 +/- ##
=========================================
Coverage 91.68% 91.68%
Complexity 5132 5132
=========================================
Files 1305 1305
Lines 58229 58242 +13
Branches 7600 7602 +2
=========================================
+ Hits 53385 53398 +13
Misses 2937 2937
Partials 1907 1907
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@bobbai00 Please take a look. |
bobbai00
left a comment
There was a problem hiding this comment.
🔴 3 must-fix · 2 advisory · 0 polish: the guard is correct and race-free, but it makes an idle stop permanent and rejects the feedback path #8711 names.
Design & architecture (1)
server.ts:501: feedback panel still sends mid-run, then shows success and clears its input (must-fix, see inline)
Correctness (2)
texera-agent.ts:505: an idlestop()now wedges the agent inSTOPPING(must-fix, see inline)texera-agent.ts:516: refresh await is outside thetrythat resets state (advisory, see inline)
Simplifications (1)
texera-agent.spec.ts:837: the sleep lets the test pass with the old ordering (advisory, see inline)
Conventions (1)
server.ws.spec.ts:318: failsformat:check, failingbuild / agent-service(must-fix, see inline)
Verification trace
Traced the check-then-act: nothing between server.ts:500 and server.ts:520 awaits, and sendMessage flips to GENERATING before its first await (texera-agent.ts:505-509), so two prompts cannot both pass. Locally at the head, bun test is 312 pass. A scratch test confirmed the idle-stop wedge. Moving the refresh await back above the flip keeps the new unit test green with the sleep and red without it.
Address review on apache#8753: - stop() is a no-op unless a run is GENERATING; an idle stop left the agent in STOPPING with no finally to reset it, so every later prompt was rejected as busy. The WS stop handler now broadcasts the agent's actual state instead of always STOPPING. - Move refreshWorkflowFromBackend inside the try so the finally always resets state. - Gate the operator feedback panel on the agent being AVAILABLE (like the chat panel); a mid-run Ctrl+Enter now warns and keeps the input instead of showing a false success toast and clearing it. - Drop the sleep from the busy unit test so it pins the ordering fix. - Prettier fix in server.ws.spec.ts.
bobbai00
left a comment
There was a problem hiding this comment.
🟡 5 resolved · 0 open · 3 new (3 new = 3 newly introduced · 0 late catches)
All five round-1 findings are fixed and pinned by tests. Three advisories remain.
Correctness (1)
server.ts:486: REST/stopstill answers "stopping" when the new guard makes it a no-op (advisory, see inline)
Simplifications (1)
agent.service.ts:966: repeatsgetAgentState's lookup (advisory, see inline)
Conventions (1)
agent-interaction.component.ts:189: PR description predates the round-2 changes (advisory, see inline)
Verification trace
Checked each round-1 fix at b503a23. Removing the stop() guard fails the three new idle-stop tests, and moving the refresh await back above the state flip fails the #8711 concurrency test. Locally bun test is 315 pass. The red build / frontend (ubuntu-latest) is the runner's playwright install step ("does not support chromium on ubuntu26.04-x64"), after all 6652 tests passed.
|
@CaroFernando can you check new comments and resolve them soon ? |
|
Removing release/v1.2. The warehouse re-pointing that #8711 describes depends on setDelegateWarehouse and the warehouseId carried by WsClientPromptCommand, neither of which exists on release/v1.2, and the patch does not apply to that branch. |
b503a23 to
37e4a3a
Compare
Address review on apache#8753: - stop() is a no-op unless a run is GENERATING; an idle stop left the agent in STOPPING with no finally to reset it, so every later prompt was rejected as busy. The WS stop handler now broadcasts the agent's actual state instead of always STOPPING. - Move refreshWorkflowFromBackend inside the try so the finally always resets state. - Gate the operator feedback panel on the agent being AVAILABLE (like the chat panel); a mid-run Ctrl+Enter now warns and keeps the input instead of showing a false success toast and clearing it. - Drop the sleep from the busy unit test so it pins the ordering fix. - Prettier fix in server.ws.spec.ts.
Address round-2 review on apache#8753: - POST /agents/:id/stop returned "stopping" even when the idle-stop no-op left the agent AVAILABLE. Return agent.getState(), matching the WS stop handler, and split the spec into mid-run and idle cases. - getAgentState now wraps getAgentStateSnapshot so the lookup and its UNAVAILABLE fallback live in one place.
bobbai00
left a comment
There was a problem hiding this comment.
🟢 3 resolved · 0 open · 0 new (0 new = 0 newly introduced · 0 late catches)
All three round-2 advisories are fixed, and I found nothing new after the rebase onto main. LGTM.
Verification trace
Checked at 37e4a3a. POST /agents/:id/stop now returns agent.getState() (server.ts:307), and reverting it to the old literal fails both new server.spec.ts stop tests. getAgentState delegates to getAgentStateSnapshot with the same result for both callers. After the rebase, sendMessage still has one caller (server.ts:513) and texera-agent.ts still writes state in exactly three places, so the busy guard and the idle-stop no-op hold. Locally bun test is 348 pass, and CI is green.
WsClientPromptCommand re-pointed the agent's warehouse via setDelegateWarehouse unconditionally, and TexeraAgent.sendMessage did not flip state to GENERATING until after an await, letting a second prompt slip through the same race window. A prompt/feedback message arriving mid-run could therefore re-point an in-flight run's warehouse mid-execution, and interleave with head/abortController/currentMessageId. sendMessage now flips state synchronously before its first await and rejects a concurrent call; the WebSocket handler rejects a busy agent before touching delegate config. Closes apache#8711
Address review on apache#8753: - stop() is a no-op unless a run is GENERATING; an idle stop left the agent in STOPPING with no finally to reset it, so every later prompt was rejected as busy. The WS stop handler now broadcasts the agent's actual state instead of always STOPPING. - Move refreshWorkflowFromBackend inside the try so the finally always resets state. - Gate the operator feedback panel on the agent being AVAILABLE (like the chat panel); a mid-run Ctrl+Enter now warns and keeps the input instead of showing a false success toast and clearing it. - Drop the sleep from the busy unit test so it pins the ordering fix. - Prettier fix in server.ws.spec.ts.
…test A bare "AVAILABLE" literal fails tsc --noEmit (the Typecheck CI step).
Address round-2 review on apache#8753: - POST /agents/:id/stop returned "stopping" even when the idle-stop no-op left the agent AVAILABLE. Return agent.getState(), matching the WS stop handler, and split the spec into mid-run and idle cases. - getAgentState now wraps getAgentStateSnapshot so the lookup and its UNAVAILABLE fallback live in one place.
37e4a3a to
66e6a67
Compare
What changes were proposed in this PR?
A prompt arriving while an agent run is already in flight could
re-point that run's warehouse mid-execution, and race on shared agent
state.
Before: prompt A starts run (GENERATING) -> prompt B arrives mid-run
-> setDelegateWarehouse() applies B's warehouse unconditionally
-> A's still-running execution tools read the new warehouse
After: prompt A starts run -> prompt B arrives mid-run -> rejected
with a busy error, A's warehouse/state untouched
Root cause, two parts:
server.ts'sWsClientPromptCommandhandler calledagent.setDelegateWarehouse(...)unconditionally on every prompt,with no check for whether a run was already in progress.
TexeraAgent.sendMessagedidn't flipstatetoGENERATINGuntilafter its first
await(refreshWorkflowFromBackend()). Since twomessagehandler invocations can interleave across that await, asecond prompt could see stale
stateand proceed concurrently,racing on
head,abortController, andcurrentMessageIdas well.Fix:
agent-service
sendMessagenow flipsstate(and resetsabortController)synchronously before any
await, and throws if alreadyGENERATING.refreshWorkflowFromBackend()runs inside thetry, so itsfinallyalways resets state.
agent.getState()and rejects a busyagent with a
WsServerErrorEventbefore it ever callssetDelegateWarehouse, so a rejected prompt's delegate config is leftuntouched.
stop()is now a no-op unless the agent isGENERATING. Before, anidle stop set
STOPPINGwith nothing to reset it, so the new busyguard rejected every later prompt.
happened: the WebSocket stop handler broadcasts
agent.getState(),and
POST /agents/:id/stopreturns{ status: agent.getState() }(
STOPPINGmid-run,AVAILABLEwhen idle) instead of a fixed"stopping". Nothing in the repo reads that response body.frontend
agent-interaction.component.ts) onlysends when the selected agent is
AVAILABLE, matching the chatpanel.
canSend()disables the Send button mid-run, andsendFeedbackToAgent()checks too, since Ctrl+Enter bypasses thedisabled button. A busy agent gets a warning toast, no success toast,
and the textarea keeps its text.
AgentService.getAgentStateSnapshot()reads an agent's lateststate synchronously without creating tracking for an unknown id.
getAgentState()now wraps it, so the lookup lives in one place.UI change, operator-feedback panel during an agent run:
Before: Send is enabled mid-run. Sending shows "Message sent to agent
successfully", clears the input, and the feedback lands as a second
prompt while the first run is still thinking. After: Send is disabled
mid-run. Ctrl+Enter shows only "Agent is busy. Please wait for the
current run to finish.", nothing is sent, and the text is kept.
Any related issues, documentation, discussions?
Closes #8711
How was this PR tested?
Regression tests, each verified red without its fix and green with it:
agent-service/src/agent/texera-agent.spec.ts: gates a mock LLM callopen, asserts a concurrent
sendMessage()call throws "busy" insteadof interleaving. With no sleep before the second call, it also fails
if the refresh await moves back above the state flip.
agent-service/src/agent/texera-agent.spec.ts: an idlestop()is ano-op, a
stop()while generating still moves toSTOPPING, andsendMessagesucceeds after an idle stop.agent-service/src/server.ws.spec.ts: the busy scenario over the realWebSocket protocol; also pins an initial
warehouseIdand asserts abusy-rejected prompt carrying a different
warehouseIdnever reachessetDelegateWarehouse. An idle WS stop reportsAVAILABLE.agent-service/src/server.spec.ts:POST /agents/:id/stopreturnsSTOPPINGmid-run andAVAILABLEwhen idle.agent-interaction.component.spec.ts: Send is disabled andCtrl+Enter is rejected while the agent is busy, with the input kept.
Run with:
cd agent-service && bun run format:check && bun run typecheck && bun test
348 tests pass (0 fail).
cd frontend && yarn format:ci && yarn lint && yarn test --watch=false
254 test files, 7295 tests pass (1 skipped, 0 fail).
Additionally verified manually against the real running stack (real
signed JWT, real WebSocket, and an actual LLM API key generating a real
response) rather than a stubbed model: sent two prompts back-to-back
with different
warehouseIds, confirmed the second is rejected with"Agent is busy processing another message" while the first's run — and
its
warehouseId— is unaffected. Also checked thatPOST /stopon anidle agent followed by a prompt runs normally, and that in the feedback
panel Send is disabled mid-run and Ctrl+Enter shows only the busy
warning with the input kept.
UI click path for the screenshots (Chromium, 1280x800 viewport, local-dev
stack, qwen/qwen4-max agent): open a workflow with a CSV File Scan
operator, create an agent in the AI Agents panel, click the operator's
chat button to open the feedback popover and select the agent, send a
multi-step prompt in the agent chat, then while it shows "Thinking..."
type feedback in the popover and click Send (before) or press Ctrl+Enter
(after).
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude