Skip to content

Commit edefc50

Browse files
authored
fix(workflow): select the first task card in the assign dialog, and show a failed Tasks load as an error (#1600)
Fixes #1457 Fixes #1458 Owner: Chief Reviewer: Reviewer Written-by: Chief Tip: d6eec2d Base: main @ 571be6d Replay of #1485: the original head is on a fork we cannot push to (maintainer_can_modify=false), so this PR carries the same change replayed onto current main; the original is closed as superseded. The original declares `Owner: Dev-1`, and that name is not in the `writers` list of `.github/agent/review-policy.json`, so a pull request on a branch this repository owns is refused at the queue for it (`Owner names "dev-1", who is not a writers Bot name`, read from the guard’s own `guard()`). This replay therefore claims the change as `Chief`, the Bot that dispatched and tracks it. The work and the credit stay with the Bot that wrote #1485. ## What was wrong `AssignModal` read the selected card once, in `useState(tasks[0]?.id ?? '')`, but the dialog opens before the host `tasks` call answers, so `taskId` froze to `''` and never re-synced: every card rendered unselected, `confirmAssign` looked the frozen id up, found nothing and returned, and `Assign` carried no `disabled`, so the click looked accepted and posted nothing. A genuinely empty board offered the same live button with the same result, and `root.openWorkflowAssign` did not even call `loadTasks()`. Separately, `loadTasks()` turned every failure into `setTasks([])` — the missing-bridge branch and the `catch` alike — so a failed read rendered *No open tasks on the Tasks board.*: no error surface, no retry, `Assign` still clickable. ## What changed `AssignModal` gets one `useEffect` that selects the first card once rows arrive (and re-selects when the selected card is gone), and `Assign` is `disabled: !canAssign`, with `canAssign = tasksStatus === 'ready' && tasks.some(task => task.id === taskId)`. `confirmAssign`’s `if (!task) return` stays as the backstop, and `root.openWorkflowAssign` now calls `loadTasks()`. `Section` keeps `tasksStatus` (`idle` / `loading` / `ready` / `failed`) and `tasksError` beside the rows; both failure paths set `failed` and keep the host’s message. `failed` renders `.wf-err` plus a `Retry` that re-runs `loadTasks()`; `loading` renders *Loading the Tasks board…*; only `ready` with zero rows renders the empty-board hint. `plugins/workflow/src/service.js` is untouched — it already refused a task with no id and title. ## Replay notes Replayed onto `main` `ae7b19f4` from #1485’s `9019337f`. Three of the four files had also moved on `main` since the original’s base `c1b9fd23`; both sides are kept in each: - `plugins/workflow/client.js` — merged three-way, no manual edit; the payload against `main` is the original’s 64-line diff, equal as a multiset on both the `+` and the `-` side, and every line `main` added since the base is still there. - `plugins/workflow/test/client.test.js` — both sides appended tests after the same last test; `main`’s block is kept first, then this change’s 154 added lines, unchanged (it deletes nothing). - `docs/subsystems/workflow.md` — two rows both sides edited; `main`’s wording is kept and the two clauses are inserted at the same places. Stripping them gives a file byte-equal to `main`’s. - `changelog.d/1457-1458-assign-dialog.fixed.md` — new, no conflict. ## Second replay onto `main` `571be6d4` `main` then took #1599, which had changed the same three files, so the branch was merged onto `main` `571be6d4957f7c6427b39e5d16dcd63725aeead0` in `d6eec2d2`. `plugins/workflow/client.js` and `docs/subsystems/workflow.md` merge with both sides kept and no manual edit; `plugins/workflow/test/client.test.js` had both sides appending after the same last test, so `main`'s block is kept first and this change's 154 added lines follow it unchanged. Every line `main` added since `ae7b19f4` is still in all three files. ## Verification at the tip The tip `d6eec2d2` is `main` `571be6d4` merged into `c7a25511`; these four files are the tip's tree over `main`. - `node --test test/client.test.js` in `plugins/workflow` -> 67/67 pass (the 63 of the previous tip plus the 4 tests #1599 added on `main`). - The same run with `main`'s `client.js` written over it -> 63/67; the 4 failures are exactly the #1457/#1458 tests, so they still fail without the change. - `node --import ./test/resolve.mjs --test "test/*.test.js"` in `plugins/workflow` -> 191/191 pass. Not re-run here: the full `npm run verify` (only `plugins/workflow` and `docs/` change), `arch-docs` (this copy has no `git`, so it cannot diff against a base - the owned doc is updated in this diff), the `package` job, the smoke test (no `index.js` or `core/src/host/` change), Desktop and the running instance. CI `tests-ok` runs on the new tip. CI at `d6eec2d2` (UTC 15:47): `tests-ok` green (`plugins (workflow)`, `plugins (social)`, `plugins (tree)`, `plugins (timeline)`, `package`, `ubuntu-latest · Node 24` all success), `merge-gate` success, `risk tier` success. `enqueue-guard` is red only because no PASS names this tip yet. ## Checkpoint <!-- flybot:checkpoint --> { "pr": 1600, "claim": "Chief", "issue": 1457, "summary": "The \"Hand a task to a Workflow\" dialog now selects the first card of the Tasks board once it loads, so Assign posts the task instead of closing on a silent no-op, and an empty board leaves it disabled. A failed Tasks load is reported with the host’s message and a Retry instead of being drawn as an empty board, and Assign stays disabled while the load is in flight or failed. The bridge entry point openWorkflowAssign now loads the board too, and the service layer is unchanged because it already refused a task with no id and title.", "files": [ "plugins/workflow/client.js", "plugins/workflow/test/client.test.js", "docs/subsystems/workflow.md", "changelog.d/1457-1458-assign-dialog.fixed.md" ], "checks": { "ran": "plugins/workflow: node --test test/client.test.js (67/67); the same with main's client.js (63/67, the 4 new #1457/#1458 tests failing); node --import ./test/resolve.mjs --test test/*.test.js (191/191)", "result": "green", "at": "d6eec2d2c1cbd607447e40be10bee6528454ef85" }, "next": "merged onto main 571be6d as d6eec2d; a fresh PASS is needed at this tip - the reviewed blobs changed, so the previous PASS does not carry" } <!-- /flybot:checkpoint -->
1 parent 571be6d commit edefc50

4 files changed

Lines changed: 206 additions & 17 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The "Hand a task to a Workflow" dialog now selects the first card of the Tasks board as soon as the board arrives, so `Assign` posts the task instead of closing on a silent no-op, and an empty board leaves it disabled. When the Tasks board cannot be loaded the dialog shows the error with a `Retry` control instead of claiming there are no tasks to assign, and `Assign` stays disabled while the load is in flight or failed. ([#1457](https://github.com/ThinkFlowLab/FlyBot/issues/1457), [#1458](https://github.com/ThinkFlowLab/FlyBot/issues/1458))

‎docs/subsystems/workflow.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher,
3535
| `plugins/workflow/src/match.js` | Which open card matches a Workflow or a local Bot. |
3636
| `plugins/workflow/src/template.js` | Factory delivery/weekly graphs plus `EARLY_END_GUIDANCE` for Claim/Verify/Triage early-end markers; 发布交付流水线 (a parallel branch) and the weekly report, each node with the inputs and outputs that edge carries. |
3737
| `plugins/workflow/src/narrate.js` | Progress lines for a step. A live run quotes the Bot reply when present; otherwise delivery-template nodes may use canned copy. A join line is only for a rank of more than one node. |
38-
| `plugins/workflow/client.js` | Sidebar section (with mini-flowcharts), workflow stage (view/control: one card per live run with its own title, node line, segment progress, status chip, and Pause / Resume / Stop; click a card or its Flow button to focus that run in the drawer flowchart; optional aggregate chip when several run or the queue is non-empty — no message composer), assign dialog (scrollable with sticky footer), flowchart drawer (collapsed by default, per-node inspector, fitted to the 400px panel so the graph needs no inner horizontal scroll), and Settings → Workflow graphs (canvas-first with inspector panel). The product UI starts only live runs (assign, ingest). The stage shows the queue and refreshes state while runs are active; a running node uses a breathing border animation. Visual flowcharts replace text chains across all surfaces. Sidebar rows (including factory ids such as `delivery`) support Delete with confirm. The stage and dialogs portal onto `document.body`; a missing container stays in the section tree. A stage control that fails — a graph save, Reset, Pause, Resume or Stop that throws, rejects, answers `{ok:false}` or does not answer within 10 s — ends on the section's `.wf-err` alert instead of being swallowed, and a success clears the alert. The flowchart's node role sub-label takes its colour from `--bt-ink-2` rather than a hardcoded grey, so it stays readable on every theme's node card (#1495). |
38+
| `plugins/workflow/client.js` | Sidebar section (with mini-flowcharts), workflow stage (view/control: one card per live run with its own title, node line, segment progress, status chip, and Pause / Resume / Stop; click a card or its Flow button to focus that run in the drawer flowchart; optional aggregate chip when several run or the queue is non-empty — no message composer), assign dialog (scrollable with sticky footer; it selects the first card once the board loads, keeps `Assign` disabled until a card is selected, and shows a failed Tasks load as an error with a `Retry` instead of the empty-board hint, #1457, #1458), flowchart drawer (collapsed by default, per-node inspector, fitted to the 400px panel so the graph needs no inner horizontal scroll), and Settings → Workflow graphs (canvas-first with inspector panel). The product UI starts only live runs (assign, ingest). The stage shows the queue and refreshes state while runs are active; a running node uses a breathing border animation. Visual flowcharts replace text chains across all surfaces. Sidebar rows (including factory ids such as `delivery`) support Delete with confirm. The stage and dialogs portal onto `document.body`; a missing container stays in the section tree. A stage control that fails — a graph save, Reset, Pause, Resume or Stop that throws, rejects, answers `{ok:false}` or does not answer within 10 s — ends on the section's `.wf-err` alert instead of being swallowed, and a success clears the alert. The flowchart's node role sub-label takes its colour from `--bt-ink-2` rather than a hardcoded grey, so it stays readable on every theme's node card (#1495). |
3939

4040
## Entry points
4141

@@ -62,7 +62,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher,
6262

6363
## Tests
6464

65-
`plugins/workflow/test/`: graph advance and join, graph edit, assign and persistence, the FIFO queue and concurrency cap, Bot-reply advance, a dispatch that fails without being marked handed, a bounded hand-off retry and a step deadline that fails the run and clears its timer (#1530), a per-workflow `stepTimeoutMinutes` that replaces the ten-minute constant and is refused outside 1..120 (#1580), disposing releases the Bots before the record drops their ids and a released runner name is reusable again, assign-to-bot versus assign-to-workflow, inputs and outputs along edges, a loop that breaks and an if/else branch, failure recovery (onFail edges with max attempts, exhaustion behavior, and compatibility with failOnce and loop edges), templates, `define` / `runNamed`, the matcher, ephemeral spawn and cleanup, a stopped run with its settled node map (#1424), the reply middleware, the client canvas, the settings page (including a condition and a loop), rename and delete (including factory-id rows such as `delivery`), the stage chat's scroll rule (a new visible line follows, a filtered node reply moves nothing), and a sidebar click that leaves the Workflows section in place. Run `npm test` in `plugins/workflow`. The host seam that applies `ownerBotId` is `core/test/task-route.test.js`, which also pins that a card written through `track_tasks` reaches the listener (#1462). The host omission of run Bots, and the grant of `stepTools` plus the hidden-approval answer, is `core/test/flybot.test.js`. Which connectors a run Bot may call is `core/test/connector-access.test.js`, and the chain from a node's `tools` through `spawn` to that guard — the built-in delivery nodes included — is `core/test/workflow-node-connectors.test.js`.
65+
`plugins/workflow/test/`: graph advance and join, graph edit, assign and persistence, the FIFO queue and concurrency cap, Bot-reply advance, a dispatch that fails without being marked handed, a bounded hand-off retry and a step deadline that fails the run and clears its timer (#1530), a per-workflow `stepTimeoutMinutes` that replaces the ten-minute constant and is refused outside 1..120 (#1580), disposing releases the Bots before the record drops their ids and a released runner name is reusable again, assign-to-bot versus assign-to-workflow, inputs and outputs along edges, a loop that breaks and an if/else branch, failure recovery (onFail edges with max attempts, exhaustion behavior, and compatibility with failOnce and loop edges), templates, `define` / `runNamed`, the matcher, ephemeral spawn and cleanup, a stopped run with its settled node map (#1424), the reply middleware, the client canvas, the settings page (including a condition and a loop), rename and delete (including factory-id rows such as `delivery`), the stage chat's scroll rule (a new visible line follows, a filtered node reply moves nothing), the assign dialog's preselected card and its failed and empty board states (#1457, #1458), and a sidebar click that leaves the Workflows section in place. Run `npm test` in `plugins/workflow`. The host seam that applies `ownerBotId` is `core/test/task-route.test.js`, which also pins that a card written through `track_tasks` reaches the listener (#1462). The host omission of run Bots, and the grant of `stepTools` plus the hidden-approval answer, is `core/test/flybot.test.js`. Which connectors a run Bot may call is `core/test/connector-access.test.js`, and the chain from a node's `tools` through `spawn` to that guard — the built-in delivery nodes included — is `core/test/workflow-node-connectors.test.js`.
6666

6767
## Connector ceiling (#1544)
6868

‎plugins/workflow/client.js‎

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ window.__ModuleLoader__.load({
111111
'Rename workflow': '重命名 Workflow',
112112
'Are you sure you want to delete "{name}"? This cannot be undone.': '确定删除「{name}」?此操作无法撤销。',
113113
'No open tasks on the Tasks board.': 'Tasks 看板上没有可分配的任务。',
114+
'Loading the Tasks board…': '正在读取 Tasks 看板…',
115+
'Could not load the Tasks board.': '无法读取 Tasks 看板。',
116+
Retry: '重试',
114117
'Could not rename this workflow': '无法重命名该 Workflow',
115118
'Could not delete this workflow': '无法删除该 Workflow',
116119
'Could not save this workflow': '无法保存该 Workflow',
@@ -939,9 +942,17 @@ window.__ModuleLoader__.load({
939942
h('button', { type: 'button', className: 'wf-btn wf-danger', onClick: onConfirm }, tr('Delete')))))
940943
}
941944

942-
function AssignModal({ workflows, tasks, roster, workflowId, onClose, onConfirm }) {
945+
function AssignModal({ workflows, tasks, tasksStatus, tasksError, roster, workflowId, onClose, onConfirm, onRetry }) {
943946
const [taskId, setTaskId] = useState(tasks[0]?.id ?? '')
944947
const [target, setTarget] = useState(workflowId || workflows[0]?.id || '')
948+
// #1457: the dialog opens before loadTasks() answers, so the first client render can have no
949+
// rows; select the first card once they arrive, or when the selected card is gone.
950+
useEffect(() => {
951+
if (tasks.length === 0) return
952+
if (taskId && tasks.some(task => task.id === taskId)) return
953+
setTaskId(tasks[0].id)
954+
}, [tasks, taskId])
955+
const canAssign = tasksStatus === 'ready' && tasks.some(task => task.id === taskId)
945956
const seen = new Set()
946957
const bots = (roster?.bots ?? []).filter(bot => {
947958
if (!bot || bot.remote === true || !bot.id || !bot.name) return false
@@ -957,14 +968,20 @@ window.__ModuleLoader__.load({
957968
h('p', { className: 'wf-hint' }, tr('A task can go to a Workflow, not only to one Bot. The Workflow then runs each Bot in order, or side by side.'))),
958969
h('div', { className: 'wf-modal-body' },
959970
h('div', { className: 'wf-step-h' }, h('b', null, '1'), tr('Pick a task card')),
960-
tasks.length === 0
961-
? h('div', { className: 'wf-muted wf-cards-empty' }, tr('No open tasks on the Tasks board.'))
962-
: h('div', { className: 'wf-cards' }, tasks.map(task => h('button', {
963-
key: task.id, type: 'button', className: `wf-kcard ${taskId === task.id ? 'sel' : ''}`, onClick: () => setTaskId(task.id),
964-
},
965-
h('div', { className: 'wf-id' }, `${shortId(task.id)} · ${priorityOf(task)}`),
966-
h('div', { className: 'wf-tt' }, task.title),
967-
h('div', { className: 'wf-kcol' }, `● ${tr(COLUMN_KEY[columnOf(task)] ?? 'Not started')}`)))),
971+
tasksStatus === 'failed'
972+
? h('div', { className: 'wf-assign-fail' },
973+
h('div', { className: 'wf-err', role: 'alert' }, tasksError || tr('Could not load the Tasks board.')),
974+
h('button', { type: 'button', className: 'wf-btn', onClick: () => onRetry?.() }, tr('Retry')))
975+
: tasksStatus !== 'ready'
976+
? h('div', { className: 'wf-muted wf-cards-empty' }, tr('Loading the Tasks board…'))
977+
: tasks.length === 0
978+
? h('div', { className: 'wf-muted wf-cards-empty' }, tr('No open tasks on the Tasks board.'))
979+
: h('div', { className: 'wf-cards' }, tasks.map(task => h('button', {
980+
key: task.id, type: 'button', className: `wf-kcard ${taskId === task.id ? 'sel' : ''}`, onClick: () => setTaskId(task.id),
981+
},
982+
h('div', { className: 'wf-id' }, `${shortId(task.id)} · ${priorityOf(task)}`),
983+
h('div', { className: 'wf-tt' }, task.title),
984+
h('div', { className: 'wf-kcol' }, `● ${tr(COLUMN_KEY[columnOf(task)] ?? 'Not started')}`)))),
968985
h('div', { className: 'wf-step-h' }, h('b', null, '2'), tr('Pick who runs it')),
969986
h('div', { className: 'wf-targets' },
970987
workflows.map(item => h('button', {
@@ -985,7 +1002,7 @@ window.__ModuleLoader__.load({
9851002
h('span', { className: 'wf-rad' }))))),
9861003
h('div', { className: 'wf-modal-footer' },
9871004
h('button', { type: 'button', className: 'wf-btn', onClick: onClose }, tr('Cancel')),
988-
h('button', { type: 'button', className: 'wf-btn wf-dark', onClick: () => onConfirm({ taskId, target }) }, tr('Assign')))))
1005+
h('button', { type: 'button', className: 'wf-btn wf-dark', disabled: !canAssign, onClick: () => { if (canAssign) onConfirm({ taskId, target }) } }, tr('Assign')))))
9891006
}
9901007

9911008
function CreateModal({ roster, templates, onClose, onCreate, onTemplate }) {
@@ -1379,6 +1396,8 @@ window.__ModuleLoader__.load({
13791396
const [assignOpen, setAssignOpen] = useState(false)
13801397
const [creating, setCreating] = useState(false)
13811398
const [tasks, setTasks] = useState([])
1399+
const [tasksStatus, setTasksStatus] = useState('idle')
1400+
const [tasksError, setTasksError] = useState('')
13821401
const [tip, setTip] = useState(null)
13831402
const [error, setError] = useState('')
13841403
const [editing, setEditing] = useState(false)
@@ -1429,7 +1448,9 @@ window.__ModuleLoader__.load({
14291448
const root = globalThis.__flybot__
14301449
if (!root) return undefined
14311450
const prev = root.openWorkflowAssign
1432-
root.openWorkflowAssign = () => { setAssignOpen(true); setOpenId(id => id) }
1451+
// #1457: this path opened the dialog without ever loading the board, so it could only
1452+
// ever show the frozen empty state.
1453+
root.openWorkflowAssign = () => { setAssignOpen(true); setOpenId(id => id); void loadTasks() }
14331454
return () => { root.openWorkflowAssign = prev }
14341455
}, [])
14351456

@@ -1474,8 +1495,15 @@ window.__ModuleLoader__.load({
14741495
}, [open?.id])
14751496

14761497
const loadTasks = async () => {
1498+
setTasksStatus('loading')
1499+
setTasksError('')
14771500
const host = globalThis.__flybot__?.host
1478-
if (typeof host !== 'function') { setTasks([]); return }
1501+
if (typeof host !== 'function') {
1502+
setTasks([])
1503+
setTasksError(tr('Could not load the Tasks board.'))
1504+
setTasksStatus('failed')
1505+
return
1506+
}
14791507
try {
14801508
const rows = await host('tasks', {})
14811509
const real = Array.isArray(rows)
@@ -1484,9 +1512,14 @@ window.__ModuleLoader__.load({
14841512
}))
14851513
: []
14861514
setTasks(real)
1515+
setTasksStatus('ready')
14871516
} catch (loadError) {
1488-
void loadError
1517+
// #1458: an empty list here used to be rendered as "no tasks to assign", which told the
1518+
// owner the board was empty instead of that the load had failed.
1519+
const detail = String(loadError?.message ?? '').trim()
14891520
setTasks([])
1521+
setTasksError(`${tr('Could not load the Tasks board.')}${detail ? ` (${detail})` : ''}`)
1522+
setTasksStatus('failed')
14901523
}
14911524
}
14921525

@@ -1633,8 +1666,8 @@ window.__ModuleLoader__.load({
16331666
},
16341667
})) : null,
16351668
assignOpen ? portal(h(AssignModal, {
1636-
workflows, tasks, roster, workflowId: openId || workflows[0]?.id,
1637-
onClose: () => setAssignOpen(false), onConfirm: confirmAssign,
1669+
workflows, tasks, tasksStatus, tasksError, roster, workflowId: openId || workflows[0]?.id,
1670+
onClose: () => setAssignOpen(false), onConfirm: confirmAssign, onRetry: loadTasks,
16381671
})) : null,
16391672
creating ? portal(h(CreateModal, {
16401673
roster, templates: pack?.templates, onClose: () => setCreating(false), onCreate: create,
@@ -1840,6 +1873,7 @@ window.__ModuleLoader__.load({
18401873
.wf-canvas-fit{position:relative;width:0;margin:0 auto;transform-origin:50% 0}
18411874
.wf-canvas-view .wf-wires path{stroke:var(--bt-ink-2,rgba(20,20,20,.55));stroke-width:2.5}
18421875
.wf-cards-empty{padding:8px 4px 12px}
1876+
.wf-assign-fail{display:flex;flex-direction:column;align-items:flex-start;gap:8px;padding:4px 0 8px}
18431877
.wf-context-menu{position:fixed;z-index:95;min-width:140px;background:var(--bt-card,#fff);border:1px solid var(--bt-line,rgba(20,20,20,.08));border-radius:10px;padding:4px;box-shadow:0 8px 24px rgba(0,0,0,.12);display:flex;flex-direction:column;gap:2px}
18441878
.wf-context-menu button{border:0;background:transparent;color:inherit;font:inherit;font-size:12.5px;text-align:left;padding:8px 10px;border-radius:8px;cursor:pointer}
18451879
.wf-context-menu button:hover{background:var(--bt-hover,rgba(119,119,119,.09))}

0 commit comments

Comments
 (0)