forked from ChaiHao/BPOS-MVP
修:工作台列表不实时刷新、办完的活不进「已完成」—— 两个 bug 叠在一起
用户实测报的。查下来是两处各自独立、叠在一起才显形的缺陷: **① SSE 订阅层的 queryKey 与实际键对不上(推送白推)** TanStack 的失效按**前缀**匹配,而工作台的键都以 `desk` 打头 (`['desk','tasks']` / `['desk','task',id]` / `['desk','messages']`); 订阅层却手写着 `['tasks']` / `['task',id]` / `['messages']` —— 一条也匹配不到。 推送照发、画面纹丝不动。修:订阅层一律取自 `queryKeys`,不写字面量; `['approvals']` 也收进 queryKeys(app-shell 原来手写)。 **② 推进器推完不广播(压根没推送)** 只有派发器(事件投递)广播;而任务从在办走到终态是**推进器**推的 —— 于是「办完的活不会自己挪到已完成」。修:推进器在 runtime/terminal 真变了时 广播 task + workflow(比对本轮前后,不变不发,免得每两秒给在线浏览器发噪声)。 实测(全程用 AI 测试账号,不碰真人工作台):起单 → 以 AI 身份答验收单 → 浏览器停在工作台,探针记到**任务列表自动重取 1 次**(修复前 0 次), SSE 三条 touch 齐到(task / task-advanced / workflow)。测完清运行数据。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
@@ -33,10 +33,26 @@ export async function advanceOnce(options: AdvancerOptions): Promise<number> {
|
||||
* 抢不到就跳过 —— 那边正推着,这边再推就是两条线同时改一份运行时状态。
|
||||
*/
|
||||
const ran = await taskMutex.tryRun(`task:${row.id}`, async () => {
|
||||
/** 这一轮之前它是什么样 —— 变了才广播,不然每两秒给在线浏览器发一次噪声 */
|
||||
const before = await container.task.get(row.id as never).catch(() => undefined);
|
||||
for (let tick = 0; tick < (options.maxTicks ?? 3); tick += 1) {
|
||||
try {
|
||||
const outcome = await container.task.tick(row.id as never);
|
||||
advanced += 1;
|
||||
|
||||
/*
|
||||
* 推进器改了状态就**广播**:任务从在办走到终态、或挂起去等人,
|
||||
* 都是在线的人该立刻看见的事。
|
||||
* 从前只有派发器(事件投递)广播,而任务是被**这里**推到终态的 ——
|
||||
* 于是「办完的活不会自己挪到已完成」,得刷页面才认(用户实测报的)。
|
||||
*/
|
||||
if (outcome.task.runtime !== before?.runtime || outcome.task.terminal !== before?.terminal) {
|
||||
container.broadcaster.publish({ kind: 'task', id: row.id, reason: 'advanced' });
|
||||
if (outcome.task.workflowId !== undefined) {
|
||||
container.broadcaster.publish({ kind: 'workflow', id: outcome.task.workflowId, reason: 'task-advanced' });
|
||||
}
|
||||
}
|
||||
|
||||
// 进入等待或终结就停手 —— 挂起在等的任务由事件唤醒,不空转
|
||||
if (outcome.task.runtime !== 'running' || outcome.task.terminal !== undefined) break;
|
||||
if (!outcome.progressed) break;
|
||||
|
||||
@@ -64,7 +64,7 @@ export function AppShell() {
|
||||
queryFn: () => call<{ messages: Array<{ id: string; read: boolean }> }>(listMessagesRoute),
|
||||
});
|
||||
const approvals = useQuery({
|
||||
queryKey: ['approvals'],
|
||||
queryKey: queryKeys.approvals,
|
||||
queryFn: () => call<{ approvals: Array<{ state: string }> }>(listApprovalsForMeRoute),
|
||||
});
|
||||
|
||||
|
||||
@@ -20,4 +20,5 @@ export const queryKeys = {
|
||||
tasks: ['desk', 'tasks'] as const,
|
||||
task: (id: string) => ['desk', 'task', id] as const,
|
||||
messages: ['desk', 'messages'] as const,
|
||||
approvals: ['desk', 'approvals'] as const,
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* 断线由 `EventSource` 自行重连;重连后整体失效一次,补上断线期间错过的变更。
|
||||
*/
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import { queryKeys } from './query.ts';
|
||||
|
||||
type Touch = { kind: 'task' | 'workflow' | 'staff' | 'system'; id: string; reason: string };
|
||||
|
||||
@@ -17,20 +18,30 @@ export function connectStream(queryClient: QueryClient): () => void {
|
||||
source.addEventListener('touch', (event) => {
|
||||
const touch = JSON.parse((event as MessageEvent<string>).data) as Touch;
|
||||
switch (touch.kind) {
|
||||
/*
|
||||
* **键名一律取自 `queryKeys`**,不手写字面量:TanStack 的失效按**前缀**匹配,
|
||||
* 而工作台的键都以 `desk` 打头(`['desk','tasks']`)。从前这里写的是 `['tasks']` ——
|
||||
* 前缀对不上,一条也匹配不到:推送照发,画面纹丝不动
|
||||
* (实测:任务办完了,列表不挪窝、「已完成」也不长出来)。
|
||||
*/
|
||||
case 'task':
|
||||
// 工作台三处 + 治理台任务面都以任务为轴,一起失效
|
||||
void queryClient.invalidateQueries({ queryKey: ['task', touch.id] });
|
||||
void queryClient.invalidateQueries({ queryKey: ['tasks'] });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.task(touch.id) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.tasks });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.approvals });
|
||||
void queryClient.invalidateQueries({ queryKey: ['gov', 'tasks'] });
|
||||
void queryClient.invalidateQueries({ queryKey: ['gov', 'tasklog', touch.id] });
|
||||
break;
|
||||
case 'workflow':
|
||||
// 流动了,自己名下的任务与审批都可能变 —— 工作台一并失效
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.tasks });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.approvals });
|
||||
void queryClient.invalidateQueries({ queryKey: ['gov', 'workflow', touch.id] });
|
||||
void queryClient.invalidateQueries({ queryKey: ['gov', 'tasks'] });
|
||||
void queryClient.invalidateQueries({ queryKey: ['gov', 'approvals'] });
|
||||
break;
|
||||
case 'staff':
|
||||
void queryClient.invalidateQueries({ queryKey: ['messages'] });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.messages });
|
||||
void queryClient.invalidateQueries({ queryKey: ['gov', 'staff'] });
|
||||
break;
|
||||
case 'system':
|
||||
|
||||
Reference in New Issue
Block a user