Repository navigation
feat(agent-service, frontend): give every agent a distinct name - #9808
Conversation
Backport auto-label reportThis Blocked by a red Backport Approvals check? That required check stays red until every
|
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9808 +/- ##
============================================
+ Coverage 91.85% 91.86% +0.01%
+ Complexity 5161 5156 -5
============================================
Files 1310 1310
Lines 58440 58437 -3
Branches 7629 7618 -11
============================================
+ Hits 53681 53686 +5
+ Misses 2863 2858 -5
+ Partials 1896 1893 -3
*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
left a comment
There was a problem hiding this comment.
🔴 1 must-fix · 2 advisory · 1 polish: naming now lives in the agent service, where it belongs; the form's hint can still promise a name the agent does not get.
Design & architecture (1)
agent-service/src/server.ts:53: the default-name rule has two other copies, one of them unreachable (advisory, see inline)
Correctness (1)
agent-registration.component.ts:136: an empty-name create gets no notice when the hint was stale (must-fix, see inline)
Conventions (1)
agent-service/src/server.ts:125:fixorfeatdecides the backport labels; the title is 78 characters (advisory, see inline)
Polish: 1 quick touch-up (see inline comments).
Verification trace
Traced concurrent creates in createAgentInstance: the name is resolved and reserved synchronously before the first await, and the agent reaches agentStore before finally releases the reservation, so two creates by one owner cannot take the same name and a failed create frees only its own. Names are compared per owner (server.ts:75), so a suffix reveals nothing about another user's agents.
…wo default name rules
…than the form showed
|
The retitle to feat did not clear the backport labels, since Backport Auto Label is hitting startup_failure repo-wide today. No backport is intended, so fix, release/v1.2 and release/v1.3 should be removed before this PR is merged. |
bobbai00
left a comment
There was a problem hiding this comment.
LGTM overall — all previous review items are addressed cleanly. Left one minor note inline on the stale-default notification message. Also note that fix, release/v1.2, and release/v1.3 labels still need to be removed to clear Backport Approval Check.
…over (apache#9809) ### What changes were proposed in this PR? When an agent's WebSocket closed unexpectedly, the AI Agents panel marked the agent unavailable and never tried again. The chat showed "Agent is disconnected. Please check your connection." and sending showed "WebSocket connection not available", with nothing logged. The only way back was to reopen the tab or reload the page. **Automatic reconnect** When the socket closes with a code other than 1000 while the agent's tab is open, `AgentService` reopens it after 1, 2, 4, 8 and 16 seconds and logs each attempt with `console.warn`. The agent service already sends a snapshot when a socket opens, so the agent's state and steps come back on their own. A successful reconnect starts the count over. After the fifth failed retry it logs an error and stops. Leaving the agent's tab or removing the agent cancels a pending retry. **Connection state** A new `AgentConnectionState` (Connecting, Connected, Lost) is tracked per agent, separate from `AgentState`, which only says what the agent is doing. `getConnectionStateObservable` exposes it, and `reconnectAgent` reconnects an open agent right away with a fresh count. **Chat banner** The banner still shows while the agent is unavailable, but now says what is happening: | Connection | Banner | | --- | --- | | Connecting, including the first connect when an existing agent is opened | Connecting to the agent... | | Lost | Could not reconnect to the agent service. Check that it is running, then try again. With a Reconnect button. | **Sending while disconnected.** `sendMessage` logs the agent id and socket state, then: | Case | Result | | --- | --- | | The agent's tab is not open | "Agent" is not connected. Open its tab in the agent panel to connect. | | The agent's tab is open | Starts a reconnect and shows: Reconnecting to "Agent". Send the message again once it is connected. | Both callers check the connection first, so these messages are a fallback. The chat box is disabled while the agent is unavailable, and the operator chat popover shows its own "Agent is not connected. Please open the agent chat panel first." The fallback covers a socket that closed without changing the agent's state, such as a normal close or the moment before `onclose` runs. **Workflow and auto-save after a reconnect** The snapshot sent on reconnect has no workflow, so an unexpected close now clears `wsWorkflowActive`. The canvas then follows the copy the agent saves to the database until a live step with workflow content takes over again. Auto-save, which the chat turns off while a run is in progress, now comes back on any AVAILABLE after it was turned off, so a run that ends during an outage no longer leaves it off. #### Demo video https://github.com/user-attachments/assets/b5ab3e81-5658-4628-9c4b-e795a6dc5661 ### Any related issues, documentation, discussions? Closes apache#9748 The agent naming part of apache#9748 is in apache#9808 Reported on the 1.2.1-incubating RC2 vote thread: https://lists.apache.org/thread/521g2csg8g8j27zbx1mw20375hwwn0tz ### How was this PR tested? * `agent.service.spec.ts`: a new "reconnecting" block using fake timers. It covers the state moving from Connecting to Connected, an open event from a replaced socket being ignored, each retry waiting its exact delay, giving up after five, the count starting over after a reconnect succeeds, deactivating or removing an agent cancelling a pending retry, and the guards and fresh count of `reconnectAgent`. Three `sendMessage` tests replace the old "not available" one: tab not open, tab open after a drop, and a socket that is still opening. A "workflow polling" test covers the database poll resuming after an unexpected close. * `agent-chat.component.spec.ts`: the connecting banner, the lost banner with its Reconnect button calling `reconnectAgent`, auto-save coming back after a run ends during a drop, and an idle reconnect leaving auto-save alone. * `agent-panel.component.spec.ts`: the panel's mock service gains `getConnectionStateObservable`. Checked against a local stack in the browser. Drops were simulated by closing the agent's socket, and an agent service outage by pointing new agent sockets at a closed port. A drop reconnected after about one second, and chat worked afterwards. During the outage the retries ran at about 1, 3, 7, 15 and 31 seconds, then the banner showed Reconnect. Reconnect during the outage started the count over, and once the outage ended the next retry connected. Reconnect after giving up connected on the first try. Switching tabs left only the open agent's socket open. Deleting an agent with a retry pending stopped further retries. After a drop the workflow poll ran again until a live step took over, and a run that ended during a drop had auto-save back on after the reconnect. ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5)
What changes were proposed in this PR?
This PR fixes the naming half of #9748. An agent created without a name was called "Bob", and two agents could have the same name with nothing to tell them apart.
Default name
An agent created without a name, or with only spaces, is now named "Agent N", where N is the lowest number none of the user's agents uses, so deleting Agent 2 makes Agent 2 the next default again. The registration form used to start with "Texera Agent" but cleared the box after the first agent, so every later agent created without typing a name became "Bob". The form now starts empty, shows the default name as its placeholder, and says "Leave empty to name it "Agent 2"." under the box.
Duplicate names
Names are trimmed, and a name the user already has gets the first free suffix: Analyst, Analyst (2), Analyst (3). Names are compared only within one user's agents, so two users can both have an Analyst. When a name is changed, the form says "An agent named "Analyst" already exists, so this one is named "Analyst (2)"." Deleting an agent frees its name.
Where the name is decided
The agent service picks the name in
createAgentInstance, since its agent store is the source of truth across browser tabs. A create waits oninitialize()and the workflow load before the agent reaches the store, so the chosen name is reserved for that owner in the meantime. Two creates at the same moment get Analyst and Analyst (2), and a create that fails releases its name. The frontend'snextDefaultAgentName()computes the same default from the agents it knows, only to show it in the form.Demo video
agent-naming-demo.mp4
Any related issues, documentation, discussions?
Part of #9748, covers request 1 and 2
The agent connection part of #9748 is in #9809
Reported on the 1.2.1-incubating RC2 vote thread: https://lists.apache.org/thread/521g2csg8g8j27zbx1mw20375hwwn0tz
How was this PR tested?
server.spec.ts: a table of cases forresolveAgentName(empty, spaces only, gaps, trimming, suffixes), and route tests for numbering, suffixes, names compared per owner, a deleted agent freeing its name, two concurrent creates, and a create that throws releasing the reserved name.agent-registration.component.spec.ts: the empty name box, the placeholder and hint, trimming, a blank name sent as no name, and the rename notice.agent.service.spec.ts:nextDefaultAgentNamefills the first gap.agent-panel.component.spec.ts: the panel's mock service gainsnextDefaultAgentName.Tested manually on a local stack in the AI Agents panel, as recorded in the demo video:
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)