Skip to content

feat(dashboard): add "配置页面" editor for expert welcome page and fix AGENT_NOT_RUNNING save race - #293

Merged
jubaoliang merged 2 commits into
TencentCloud:developfrom
chujieHong:fix/agent-edit-page-config-race
Aug 17, 2026
Merged

feat(dashboard): add "配置页面" editor for expert welcome page and fix AGENT_NOT_RUNNING save race#293
jubaoliang merged 2 commits into
TencentCloud:developfrom
chujieHong:fix/agent-edit-page-config-race

Conversation

@chujieHong

@chujieHong chujieHong commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

本次 PR 在「编辑专家」抽屉里新增了 「配置页面」 折叠区块,让管理员可以可视化地配置专家面向用户的欢迎页:

  • 标题语(welcome message):新建聊天时显示的欢迎语,支持中英文同写。
  • 快速启动卡片(quick prompts):可增删改查任意张卡片,每张含标题、描述、提示内容(点击后发送给专家的 prompt)、颜色、图标;右侧实时预览最终效果。

数据落到每个专家工作区根目录的 manifest.json,聊天欢迎页通过 GET /agents/{aid}/chat/welcome 读取。后端解析顺序:① 工作区 manifest.json ② 模板目录 ③ 默认卡片,因此用户改动优先。

附带修了一个相关 bug:编辑「配置页面」后第二次起保存会偶现「此专家未启用」(AGENT_NOT_RUNNING)。根因是 PATCH 触发 harness 后台重载时 require_running_workspace 严苛校验,跨次保存会撞上重载窗口。给 manifest 写入加了重试(5 秒内仅对 AGENT_NOT_RUNNING 重试),失败时降级为黄色 warning 提示,PATCH 主流程不受影响。

Target branch

  • Base is develop (feature / fix — default)
  • Base is main (release/* or hotfix/* only)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactor / chore
  • Release / hotfix

Test plan

  1. cd dashboard && npx tsc --noEmit 干净通过,0 类型错误。
  2. 打开「小通·通用助手3」(ENPKA2)抽屉 → 展开「配置页面」→ 修改标题语、新增一张快速启动卡片 → 点保存 → 顶部弹「保存 ✓」,抽屉关闭;GET /api/agents/ENPKA2/chat/welcome 回读内容与改动一致。
  3. 复现旧 bug:连点保存 10 次 → 旧代码 2/10 失败红字「此专家未启用」;新代码全部 10/10 成功,最多重试 2 次(约 25–500ms 内)。
  4. 跨专家:同样流程在「系统医生」(S35JZD)上跑通。
  5. 端到端:新开一个空聊天页,标题语与快速启动卡片按改动渲染,prompt 可点击发送。
  6. 兼容性:未展开「配置页面」直接保存,行为不变(manifest 写入块整体跳过,仅跑 PATCH)。
  • make all passes locally
  • Added/updated tests

Checklist

  • Updated CHANGELOG.md (if user-facing)
  • README / docs updated (if needed)

@chujieHong chujieHong changed the title Fix/agent edit page config race feat(dashboard): add "配置页面" editor for expert welcome page and fix AGENT_NOT_RUNNING save race Aug 14, 2026
Editing an expert's 页面配置 (welcome message + quick-start cards) and
clicking 保存 surfaced "此专家未启用" (AGENT_NOT_RUNNING) on every save
after the first. Two failures combined to cause it:

1. PATCH /agents/{aid} schedules a background harness reload
   (arebuild_agent = aremove_agent + slow acreate_agent compile, often
   2-5s on Windows). During that window the agent is absent from the
   harness registry, but the DB row still says 'running'.
2. The manifest write was placed BEFORE the PATCH, so the first save
   landed before the reload started and worked. But every subsequent
   save (re-opening the drawer, expanding 页面配置, editing, saving
   again) hit the reload window from the previous PATCH — and
   require_running_workspace raised AGENT_NOT_RUNNING. The
   'manifest before PATCH' ordering alone only protects the within-save
   race, not the cross-save one.

Reproduction (live server, ENPKA2, 10 rapid saves with the WIP order):
2/10 manifest writes succeeded; 8/10 failed with AGENT_NOT_RUNNING.
First save after a 3s wait: 10/10 succeeded — confirms the reload
window is the cause.

Fix:
- Add writeManifestWithRetry (10 × 500ms = up to 5s, retries only on
  AGENT_NOT_RUNNING). Re-running for 5s is well within typical reload
  windows; the manifest is best-effort.
- Wrap the manifest write in its own try/catch. On failure show a
  warning toast (yellow, with i18n key experts.manifestWriteFailed) so
  the user knows, but never block the PATCH — the agent's main config
  must always save. The drawer still closes and the success toast still
  fires after the PATCH.

Scope of the change:
- New: WelcomeConfig.tsx (the 页面配置 editor, used by EditAgentDrawer).
- New: index.module.less styles for WelcomeConfig.
- Modified: EditAgentDrawer.tsx (render the new collapse section, save
  the manifest with retry, fall back to a warning).
- New i18n keys: experts.pageConfigTitle / welcomeMessageTitle /
  welcomeMessagePlaceholder / quickPromptsTitle / addQuickPrompt /
  quickPromptTitle(Placeholder) / quickPromptDescription(Placeholder) /
  quickPromptContent(Placeholder) / quickPromptColor / quickPromptIcon /
  quickPromptPreview / noQuickPrompts / noIcon / manifestWriteFailed
  in both zh.json and en.json; also backfilled experts.patchFailed in
  zh.json (was missing).

Out of scope (pre-existing, surfaced during review):
- WelcomeConfig's useImperativeHandle has no deps array — works
  correctly via closure but recreates the handle each render.
- loadConfig() runs on mount; a click on 保存 during the load would
  write the empty initial state to manifest.json. Not addressed here.

Verified: end-to-end against the live server, agent ENPKA2 and S35JZD,
after a 3s settle the 2nd save succeeds on retry attempt 2 (~25ms after
the first failed attempt), and 5 rapid back-to-back saves all land
without surfacing a red error to the user.
@chujieHong
chujieHong force-pushed the fix/agent-edit-page-config-race branch from 410922f to 2a60edf Compare August 14, 2026 11:33
@jubaoliang

Copy link
Copy Markdown
Collaborator

有一个冲突

Resolve conflicts in dashboard/src/pages/Experts/index.module.less:
keep both the WelcomeConfig editor styles (this branch) and the
publishDrawer styles (from develop) — independent CSS blocks.
@chujieHong

Copy link
Copy Markdown
Contributor Author

@jubaoliang 有空麻烦看一下新交的这两个pr

@jubaoliang
jubaoliang merged commit 420d5e2 into TencentCloud:develop Aug 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants