Total workspace count not updated when a workspace is created asynchronously (e.g., via @-mention of an AI user) #3276
Zak Siddiqui opened 12 hours ago

Summary

The total workspace count shown in the UI keeps displaying a stale value when a new workspace is created asynchronously — for example, when an AI user is @-mentioned in a comment and the agent subsequently creates a workspace. The count only corrects itself after a full page refresh or after an unrelated comment is added or deleted. Although this report uses the AI @-mention flow as the trigger, the affected value is the total workspace count, so the problem is not limited to AI-user workspaces.

What currently happens (Actual behavior)

  1. A user @-mentions an AI user in a comment (any comment box).
  2. OneDev enqueues the job; the AI agent picks it up and creates the workspace asynchronously — potentially seconds after the comment was saved.
  3. Once the workspace exists, the total workspace count displayed in the UI is not refreshed. It still shows the value from whenever the surrounding fragment was last rendered.
  4. The count finally shows the correct value only after:
    • a full page reload, or
    • adding or deleting a comment (which triggers a server-side re-render of the comment/description fragment).

What I want to happen (Expected behavior)

  • The total workspace count should update automatically whenever workspaces are created or removed, without requiring a page refresh or unrelated comment activity.
  • Ideally, the server pushes a "workspace created/deleted" event to connected clients and the UI updates the count in place.
  • Acceptable minimum: if real-time updating is out of scope, the UI should not display a number that can silently go stale — e.g., fetch the count on demand and present it as an explicitly loaded statistic.

Steps to reproduce

  1. Open any issue and add a comment that @-mentions an AI user.
  2. Submit the comment and note the total workspace count currently displayed.
  3. Wait until the AI agent has processed the mention and the workspace exists (confirm via the workspace list).
  4. Look at the total workspace count again without reloading the page.

Observed: the count is unchanged, even though a new workspace now exists.

Root cause analysis (suspected)

Three factors combine to produce the stale value:

  1. The total count is rendered server-side inside a page fragment. It is not an independently refreshed value. Any full re-render of that fragment (page load, comment add/delete) recomputes it — which is exactly when users see it "fix itself."
  2. No push notification or polling for workspace lifecycle events. Nothing tells the client "a workspace was created/removed," so there is no trigger to re-render the fragment — or even just the count.
  3. Workspace creation via @-mention is asynchronous. The mention only enqueues the work. When the comment is saved and its fragment returned to the browser, the workspace usually does not exist yet — so the freshly rendered count is already out of date the moment it appears.

Scope note: The @-mention flow is merely the easiest reproducible trigger here. Any other mechanism that creates or deletes workspaces asynchronously would leave the total count equally stale, so the fix should target the count's update mechanism, not the AI-mention flow specifically.

Suggested fix

Preferred:

  • Emit a server-side event whenever any workspace is created or deleted (e.g., over the web-socket/event mechanism OneDev already uses).
  • On the client, listen for the event and update the total count in place.

Alternative (if real-time updates are out of scope):

  • Stop embedding a possibly stale number in the fragment. Fetch the count on demand (e.g., when the workspace section is opened) and present it as an explicitly loaded statistic.

Motivation / Impact

  • Misleading UI: The count contradicts the actual number of workspaces. This makes the UI look broken and undermines trust in other displayed statistics.
  • Risk of duplicate work: A user seeing a count that suggests their workspace wasn't created may re-mention the AI user — duplicating jobs or creating unnecessary workspaces.
  • Hard to diagnose: Since the count is the visible indicator of success, users will likely file reports like "the AI did nothing" or "mentions are broken" when the actual problem is a stale number.
  • Confusing refresh behavior: The count correcting itself only after unrelated actions (adding/deleting a comment) looks like flaky behavior rather than a deterministic bug, making reproduction and triage harder.
  • Broader blast radius than it first appears: Because the value is the total count, it can mislead any user — not just those working with AI mentions — about the actual number of workspaces in the system.

Workaround

Refresh the page (or add/remove a comment) to force a server-side re-render of the fragment; the count will then be correct.

Acceptance criteria

  •  After a workspace is created via @-mention of an AI user, the total workspace count updates without a page reload or comment edits.
  •  Workspace creation/deletion through any mechanism (not just AI mentions) updates the count without a reload.
  •  No regression: adding/deleting comments still renders the comment fragment correctly.
  • Zak Siddiqui changed title 12 hours ago
    Previous Value Current Value
    Workspace count for AI user not updated after workspace is created via @-mention
    Workspace count not updated after workspace is created via @-mention
  • Zak Siddiqui changed title 12 hours ago
    Previous Value Current Value
    Workspace count not updated after workspace is created via @-mention
    Total workspace count not updated when a workspace is created asynchronously (e.g., via @-mention of an AI user)
  • Zak Siddiqui changed fields 12 hours ago
    Name Previous Value Current Value
    Priority
    Normal
    Minor
1/1
Type
Bug
Priority
Minor
Assignee
Affected Versions
17.2.1
Labels
No labels
Issue Votes (0)
Watchers (2)
Reference
OD-3276
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover