Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3361.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Workflow stage no longer reads the store from a window nobody is looking at: the 2 s poll kept asking the host for `workflow/state` — the whole store, including the widened held-task page — for as long as a run was live or a read error was showing, so a minimised app or a tab behind another kept the host busy every tick, and coming back showed rows up to 2 s stale. The poll now follows the page: a hidden window arms no interval at all, returning clears and re-arms it and then reads once at once, and the visible cadence stays 2000 ms ([#3361](https://github.com/ThinkFlowLab/FlyBot/issues/3361)).
2 changes: 1 addition & 1 deletion docs/subsystems/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Everything in `plugins/workflow/`: the graph rules, the run store, the matcher,
| `plugins/workflow/src/match.js` | Which open card matches a Workflow or a local Bot. |
| `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. |
| `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. |
| `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; the hand-off carries the card's own facts — the assign body sends the card's `brief` verbatim and an explicit empty one when the card holds none, so a run never starts on the title where the card had a work order and a brief an earlier call cached cannot come back (#2495); both of its choice lists draw twelve at a time and a `Show {count} more cards` / `Show {count} more Bots` row says how many they are not showing, expanding to the rest and folding back to `Show less`, so no card or local Bot is out of reach while the default view keeps its length, and a card picked past the twelfth is drawn first once the list is folded again, so the twelve rows never hide the card the button is about to send (#2257), #2244), 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. A row with live runs draws the number beside the dot and carries the count, with the word `running`, in a visually hidden `.wf-sr` span — the dot and the digit sit inside an `aria-hidden` wrap, so the number alone would be silent to a reader — and its accessible name therefore stays the name its content gives: the lane's name, the `Workflow` badge, its Project and its preview, plus the count; a row-level `aria-label` replaced all of that and made two lanes that share a name read alike (#2222, #2230). The `Workflow` badge itself is drawn through the plugin's dictionary, so a zh window reads 工作流 in the row and in the Hand a task to a Workflow target list while an English window keeps the word (#3102). Every other Chinese sentence that names the feature says 工作流 as well — the empty state, the new, rename and delete buttons and their error toasts, the Workflow graphs tab, the reading hint and the created toast — so one window never mixes the two words; the English keys and copy are unchanged (#3129). An idle row draws no dot, no count, no digit and no hidden text, so its name stays its own text. 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). The drawer's styling reuses the core `--bt-*` tokens and the Bot details drawer's patterns (title, pill tabs, soft pill buttons, bubble-surfaced node cards; accent tints mixed from `--bt-accent`, #1654). The stage lists the tasks the open workflow holds (`heldTasks`; when `heldTaskCount` exceeds that page the rest is a `Show {count} more held tasks` control — a `wf-more` button with `data-more="held"` and `aria-expanded`, whose count is what pressing it reaches past the rows drawn rather than everything the lane holds — that reads the wider page with `heldLimit: 200` and folds back to `Show less`; that page stops at 200, so an unfolded list still short of `heldTaskCount` draws a `wf-held-note` line `Showing {shown} of {count} held tasks`, and neither the count nor the button promises an id it cannot show (#2256, #2260), each with one **Re-match** action that drops that task's claim and matches it again through `workflow/ingest` with `rematch: true` — one board read to hand over the card's fields and one state read after, never a second polling loop (#1647). The drawer's Edit plane keeps one copy of the row geometry: a graph whose parallel cards still fit is the fitted plane (scaled centres, `parallelFrameStyle` frame, one-fold `wirePath`), and one that cannot is laid out in `flowLayout`'s own rows — its cards are those boxes, its dashed frame is that band's frame, and its wires are the `flowWires` routing around them, so a 3+ way step at a 364px drawer keeps its frame inside the panel and no wire crosses a card (#1693). A two-Bot parallel step the fitted plane would squeeze — the drawer's fit leaves the pair 4px apart, with each card's out-port (5px) and remove button (8px) past its right edge under the neighbour — is drawn at that row's `flowLayout` column width (154px at a 364px drawer) on its fitted centres and wires, keeping the 12px row gap and a plane whose drags still commit world coordinates; `parallelFrameStyle` adds the 20px label band above the cards and a 10px pad below them, so the fitted frame encloses every card it names (#1738). |
| `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; the hand-off carries the card's own facts — the assign body sends the card's `brief` verbatim and an explicit empty one when the card holds none, so a run never starts on the title where the card had a work order and a brief an earlier call cached cannot come back (#2495); both of its choice lists draw twelve at a time and a `Show {count} more cards` / `Show {count} more Bots` row says how many they are not showing, expanding to the rest and folding back to `Show less`, so no card or local Bot is out of reach while the default view keeps its length, and a card picked past the twelfth is drawn first once the list is folded again, so the twelve rows never hide the card the button is about to send (#2257), #2244), 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, and only while the page is visible: a hidden window arms no interval, and coming back clears and re-arms it before one read at once, so the poll neither reads in the background nor keeps the phase it had before the page was hidden (#3361); 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. A row with live runs draws the number beside the dot and carries the count, with the word `running`, in a visually hidden `.wf-sr` span — the dot and the digit sit inside an `aria-hidden` wrap, so the number alone would be silent to a reader — and its accessible name therefore stays the name its content gives: the lane's name, the `Workflow` badge, its Project and its preview, plus the count; a row-level `aria-label` replaced all of that and made two lanes that share a name read alike (#2222, #2230). The `Workflow` badge itself is drawn through the plugin's dictionary, so a zh window reads 工作流 in the row and in the Hand a task to a Workflow target list while an English window keeps the word (#3102). Every other Chinese sentence that names the feature says 工作流 as well — the empty state, the new, rename and delete buttons and their error toasts, the Workflow graphs tab, the reading hint and the created toast — so one window never mixes the two words; the English keys and copy are unchanged (#3129). An idle row draws no dot, no count, no digit and no hidden text, so its name stays its own text. 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). The drawer's styling reuses the core `--bt-*` tokens and the Bot details drawer's patterns (title, pill tabs, soft pill buttons, bubble-surfaced node cards; accent tints mixed from `--bt-accent`, #1654). The stage lists the tasks the open workflow holds (`heldTasks`; when `heldTaskCount` exceeds that page the rest is a `Show {count} more held tasks` control — a `wf-more` button with `data-more="held"` and `aria-expanded`, whose count is what pressing it reaches past the rows drawn rather than everything the lane holds — that reads the wider page with `heldLimit: 200` and folds back to `Show less`; that page stops at 200, so an unfolded list still short of `heldTaskCount` draws a `wf-held-note` line `Showing {shown} of {count} held tasks`, and neither the count nor the button promises an id it cannot show (#2256, #2260), each with one **Re-match** action that drops that task's claim and matches it again through `workflow/ingest` with `rematch: true` — one board read to hand over the card's fields and one state read after, never a second polling loop (#1647). The drawer's Edit plane keeps one copy of the row geometry: a graph whose parallel cards still fit is the fitted plane (scaled centres, `parallelFrameStyle` frame, one-fold `wirePath`), and one that cannot is laid out in `flowLayout`'s own rows — its cards are those boxes, its dashed frame is that band's frame, and its wires are the `flowWires` routing around them, so a 3+ way step at a 364px drawer keeps its frame inside the panel and no wire crosses a card (#1693). A two-Bot parallel step the fitted plane would squeeze — the drawer's fit leaves the pair 4px apart, with each card's out-port (5px) and remove button (8px) past its right edge under the neighbour — is drawn at that row's `flowLayout` column width (154px at a 364px drawer) on its fitted centres and wires, keeping the 12px row gap and a plane whose drags still commit world coordinates; `parallelFrameStyle` adds the 20px label band above the cards and a 10px pad below them, so the fitted frame encloses every card it names (#1738). |

## Entry points

Expand Down
33 changes: 30 additions & 3 deletions plugins/workflow/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,33 @@ window.__ModuleLoader__.load({
.catch((failure) => finish({ ok: false, error: callError(failure, fallback) }))
})
}
// A 2 s poll of the whole store is a host read per tick, so it follows the page: a hidden
// window keeps no interval at all instead of firing one whose read would be wasted, and
// coming back clears and re-arms it before reading once at once — an interval left armed
// through the hidden stretch carries the time it already burned, so the next read lands
// early instead of a full `ms` after the page is back.
function pollWhileVisible(fn, ms) {
const doc = globalThis.document
const hidden = () => doc?.hidden === true || doc?.visibilityState === 'hidden'
let timer
const stop = () => {
if (timer === undefined) return
globalThis.clearInterval(timer)
timer = undefined
}
const arm = () => { stop(); if (hidden()) return; timer = globalThis.setInterval(fn, ms) }
const onVisibility = () => {
if (hidden()) { stop(); return }
arm()
fn()
}
doc?.addEventListener?.('visibilitychange', onVisibility)
arm()
return () => {
stop()
doc?.removeEventListener?.('visibilitychange', onVisibility)
}
}
function fill(text, params) {
return params ? text.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) : text
}
Expand Down Expand Up @@ -2166,12 +2193,12 @@ window.__ModuleLoader__.load({
// One poll: while a run is live, for the Bot replies that advance nodes, and while a
// read error is showing, so a refused read is retried. Two effects used to test the
// same condition and both fired, so every tick read the whole store twice (#1564).
// It follows the page's visibility too: a window nobody is looking at reads nothing,
// and coming back reads at once rather than up to 2 s later.
const live = (pack?.workflows ?? []).some(item => (item.activeCount ?? 0) > 0)
useEffect(() => {
if (!live && !readError) return undefined
let gone = false
const timer = setInterval(() => { if (!gone) void refresh() }, 2000)
return () => { gone = true; clearInterval(timer) }
return pollWhileVisible(() => { void refresh() }, 2000)
}, [live, readError])

useEffect(() => {
Expand Down
52 changes: 52 additions & 0 deletions plugins/workflow/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5058,3 +5058,55 @@ test('#2581: the canvas node label is one code point', () => {
view.unmount()
}
})

// The stage's 2 s poll is a read of the whole store: a window nobody is looking at must
// not keep asking the host, and coming back must show the current state at once instead
// of up to 2 s of stale rows (#3315's shape, on this panel).
test('a hidden page stops the poll and a visible one reads again at once', async (t) => {
const graph = delivery()
graph.activeCount = 1
const reads = []
const call = async (name) => {
if (name === 'workflow/state') { reads.push(1); return { workflows: [graph] } }
return { ok: true, workflows: [graph] }
}
const timers = []
const realSet = globalThis.setInterval
const realClear = globalThis.clearInterval
globalThis.setInterval = (fn, ms) => { const id = timers.length + 1; timers.push({ id, fn, ms }); return id }
globalThis.clearInterval = (id) => {
const at = timers.findIndex(timer => timer.id === id)
if (at >= 0) timers.splice(at, 1)
}
const realDoc = globalThis.document
const listeners = []
const doc = {
...documentStub,
hidden: true,
visibilityState: 'hidden',
addEventListener(name, fn) { if (name === 'visibilitychange') listeners.push(fn) },
removeEventListener(name, fn) {
const at = listeners.indexOf(fn)
if (name === 'visibilitychange' && at >= 0) listeners.splice(at, 1)
},
}
globalThis.document = doc
try {
const view = mount(client.Section, { roster: { bots: [] }, call, actions: {} })
t.after(() => view.unmount())
await settle()
assert.equal(reads.length, 1, 'the first paint reads the store once')
for (const timer of timers.slice()) timer.fn()
await settle()
assert.equal(reads.length, 1, 'a hidden page does not read the store again')
doc.hidden = false
doc.visibilityState = 'visible'
for (const fn of listeners.slice()) fn()
await settle()
assert.equal(reads.length, 2, 'coming back reads the store at once')
} finally {
globalThis.document = realDoc
globalThis.setInterval = realSet
globalThis.clearInterval = realClear
}
})
Loading