Skip to content

feat(agent-service, frontend): give every agent a distinct name - #9808

Merged
bobbai00 merged 8 commits into
apache:mainfrom
zyratlo:fix/agent-naming
Dec 4, 2026
Merged

bobbai00 merged 8 commits into
apache:mainfrom
zyratlo:fix/agent-naming

Conversation

@zyratlo

@zyratlo zyratlo commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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 on initialize() 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's nextDefaultAgentName() 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 for resolveAgentName (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: nextDefaultAgentName fills the first gap.
  • agent-panel.component.spec.ts: the panel's mock service gains nextDefaultAgentName.

Tested manually on a local stack in the AI Agents panel, as recorded in the demo video:

  1. With no agents, the name box is empty, the placeholder is "Agent 1", and the hint says to leave it empty for that name.
  2. Creating three agents with an empty name, an empty name, and only spaces gives Agent 1, Agent 2 and Agent 3.
  3. After deleting Agent 2, the form offers Agent 2, and creating with an empty name gives Agent 2.
  4. Creating "Analyst", "Analyst" and " Analyst " gives Analyst, Analyst (2) and Analyst (3), with the rename notice on the last two.
  5. After deleting Analyst, creating "Analyst" gives Analyst with no notice.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Dec 1, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 December 1, 2026 19:52
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there, and the labels left on a merged PR are exactly the branches it reached.

Blocked by a red Backport Approvals check? That required check stays red until every release/* label below is either approved by its branch's release manager or removed. To unblock a backport you do not want:

  • Remove that branch's release/* label to decline just it (the removal is remembered, so it is not added again).
  • Add the no-backport-needed label to decline every branch at once.
  • If this PR is not really a fix, change its title away from fix: and all of these labels are removed automatically; retitling back to fix: re-adds them.
Release branch Analysis
✅ release/v1.3 Already labeled — this fix is queued to backport here. @mengw15 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other.
✅ release/v1.2 Already labeled — this fix is queued to backport here. @xuang7 decides: approving sends the fix here, removing this label declines it. The merge waits on one or the other.

Auto-label run.

@github-actions github-actions Bot added fix frontend Changes related to the frontend GUI agent-service labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @bobbai00, @aglinxinyuan, @yangzhang75
    You can notify them by mentioning @bobbai00, @aglinxinyuan, @yangzhang75 in a comment.

@codecov-commenter

codecov-commenter commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.86%. Comparing base (2d0a0a3) to head (37cfc9c).
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø) Carriedforward from 8c1925a
agent-service 99.57% <100.00%> (+<0.01%) ⬆️
amber 86.09% <ø> (-0.01%) ⬇️ Carriedforward from 8c1925a
computing-unit-managing-service 63.75% <ø> (-0.21%) ⬇️ Carriedforward from 8c1925a
config-service 87.50% <ø> (ø) Carriedforward from 8c1925a
file-service 82.16% <ø> (-0.02%) ⬇️ Carriedforward from 8c1925a
frontend 96.50% <100.00%> (+<0.01%) ⬆️
notebook-migration-service 83.84% <ø> (ø) Carriedforward from 8c1925a
pyamber 98.70% <ø> (+0.13%) ⬆️ Carriedforward from 8c1925a
result-service 86.48% <ø> (ø) Carriedforward from 8c1925a
workflow-compiling-service 80.90% <ø> (ø) Carriedforward from 8c1925a

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bobbai00 bobbai00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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: fix or feat decides 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.

Comment thread agent-service/src/server.ts Resolved
Comment thread agent-service/src/server.ts Resolved
Comment thread agent-service/src/server.spec.ts Resolved
@zyratlo zyratlo changed the title fix(agent-service, frontend): give unnamed and duplicate agents distinct names feat(agent-service, frontend): give every agent a distinct name Dec 3, 2026
@zyratlo

zyratlo commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

@zyratlo
zyratlo requested a review from bobbai00 December 3, 2026 18:05

@bobbai00 bobbai00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bobbai00 bobbai00 removed fix release/v1.2 back porting to release/v1.2 release/v1.3 back porting to release/v1.3 labels Dec 3, 2026
@bobbai00
bobbai00 removed request for mengw15 and xuang7 December 3, 2026 21:27
@bobbai00
bobbai00 enabled auto-merge December 3, 2026 21:27
@bobbai00
bobbai00 added this pull request to the merge queue Dec 4, 2026
Merged via the queue into apache:main with commit 0810947 Dec 4, 2026
24 checks passed
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Dec 4, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-service frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants