Skip to content
Back to skills

Glue Task Manager

ASecurity

TaskManager's task-scheduling model — priority tiers, not FIFO, and why AddOrMoveToEnd coalescing can silently miss. Triggers: TaskExecutionPreference, AddOrMoveToEnd, TaskManager.Self.Add/AddAsync, GenerateElementCode, AddOrRunIfTasked, EffectiveId, out-of-order regeneration.

  • 583 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 7, 2026
toolsgoreact

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add vchelaru/FlatRedBall --skill glue-task-manager --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Glue Task Manager?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Glue Task Manager
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vchelaru-glue-task-manager/badge)](https://www.skillsdirectory.com/skills/vchelaru-glue-task-manager)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: glue-task-manager
description: TaskManager's task-scheduling model — priority tiers, not FIFO, and why AddOrMoveToEnd coalescing can silently miss. Triggers: TaskExecutionPreference, AddOrMoveToEnd, TaskManager.Self.Add/AddAsync, GenerateElementCode, AddOrRunIfTasked, EffectiveId, out-of-order regeneration.
---

# Glue TaskManager Scheduling

`FRBDK/Glue/Glue/Tasks/TaskManager.cs` runs almost all project-mutating work through one dedicated
thread and a priority queue (`taskQueue`), not a FIFO queue. `glue-unit-test-bootstrap`'s "Sibling seams"
section covers the `SynchronousMode` test seam that collapses this to inline sequential execution —
which is why ordering bugs here are invisible under that mode and need a real (non-synchronous) queue
to pin.

## Only project-file work has to be serial

Every plugin reads and writes the same project files: the `.gluj`/`.glej` files, the `.csproj`, and the
`.gumx` and its element files. The single queue thread is what stops one plugin's change to those files
from wiping out another's, so anything that reads or modifies them runs as a queued task. Work that
touches none of them (generating Gum fonts, writing other files to disk, running an external tool) can
run off the queue and in parallel, then queue a short follow-up task that registers the result, such as
adding the files to the `.csproj` or reloading the Gum project. Keeping a task slot for the whole of such
work stalls every plugin for nothing (see "An awaited task holds the whole queue" below).

A task can also split its own read-only work across threads with `TaskManager.RunInParallel`: the
workers count as inside the task (`IsInTask` and `AddOrRunIfTasked` behave as on the task thread) and
inherit `FileManager.RelativeDirectory`. `GenerateAllCodeSync` uses it to generate elements in parallel,
then saves files and adds them to the `.csproj` back on the task thread. Code that runs on those workers
must not use a static as per-element scratch space; such fields are `[ThreadStatic]`.

## Tiers beat enqueue order

`TaskExecutionPreference` (`Asap` / `Fifo` / `AddOrMoveToEnd`) are fixed numeric tiers far apart
(`0`, `ulong.MaxValue/3`, `2*ulong.MaxValue/3`); `taskoffset` only breaks ties *within* a tier. A `Fifo`
task queued after an `AddOrMoveToEnd` task still runs first, unconditionally. `GenerateElementCode`
(`GenerateCodeCommands.cs`) deliberately queues its file-write + `.csproj`-registration work at
`AddOrMoveToEnd` to keep the UI responsive — so any operation that depends on that codegen having
already landed (moving or deleting the files it wrote) must also be `AddOrMoveToEnd`, or a default-`Fifo`
call queued later can still run first.

## Coalescing keys off DisplayInfo, which can be stale

`AddOrMoveToEnd`'s de-dup cancels an older pending task sharing the same `EffectiveId`
(`CustomId ?? DisplayInfo`). A `DisplayInfo` built from mutable state (e.g. `element.ToString()` →
`Name`) gives two logically-identical requests different ids across a mutation, so they never coalesce.
Also: `AddOrRunIfTasked`'s "already in a task, run inline" fast path explicitly excludes
`AddOrMoveToEnd` — it always goes through the real queue.

## A same-tier task queued early can still surface last

`GenerateElementCode` on a screen with N derived screens synchronously enqueues one `AddOrMoveToEnd`
task per derived screen the moment it runs - so any other `AddOrMoveToEnd` call made around the same
time (e.g. a plugin's own error-refresh reacting to the same property change) ends up dequeued after
all N of them, even though it was queued just as early. This is "tiers beat enqueue order" above,
just easy to miss because the delay looks like *your* call ran late, not like a same-tier burst beat
it. `RefreshCommands.RefreshErrorsFor` (`RefreshCommands.cs`) takes an optional `executionPreference`
for exactly this: pass `Fifo` (or anything but `AddOrMoveToEnd`) from a reaction that must show up
promptly, and - since `AddOrRunIfTasked`'s inline fast path excludes only `AddOrMoveToEnd` - if you're
already inside a task, it runs immediately instead of queueing at all. Conversely, a reaction that
must wait until codegen has actually landed still wants `AddOrMoveToEnd` (see above).

## The nested-task fast path checks `TaskManager.Self`, not the calling instance

`AddOrRunIfTasked`'s `IsInTask()` gate is hardcoded to `TaskManager.Self.SyncTaskThreadId`, not
`this.SyncTaskThreadId` — so a `TaskManager.Self.AddAsync(...)` call made from inside an already-running
task's callback (any preference except `AddOrMoveToEnd`) runs inline via `RunTask(...).Wait()` instead of
re-entering the priority queue, meaning its own `TaskExecutionPreference` argument is inert. In production
this is safe because `StartDoTaskManagerLoop` wraps the dedicated task thread in Nito.AsyncEx's
`AsyncContext.Run`, which pins every `await` continuation started within it back to that same thread — so
`IsInTask()` still sees the same thread ID after any number of nested `await`s. This can't be observed
under `GlueUnitTests`: `GlueTestBootstrap` forces `SynchronousMode = true` before `TaskManager.Self` is
ever constructed, which permanently fixes that one singleton instance's `SyncTaskThreadId` to whatever
thread first touched it — no later toggle of `TaskManager.SynchronousMode` (e.g. in
`TaskManagerSynchronousModeTests`) un-fixes it, so nested calls always look "in task" there regardless of
what the real threaded model would do.

## An awaited task holds the whole queue

`DoTaskManagerLoop` awaits `RunTask(...)` before its next `taskQueue.TryTake`, so a task keeps its slot
across every `await` inside it and nothing else is dequeued until it completes. I/O awaited from inside
a task — `GameCommunicationPlugin`'s socket round trips, each with a 10-second ceiling — stalls all
queued project work for its full duration.

## Synchronous mode must run without a SynchronizationContext

`TaskManager.RunSynchronously` blocks the calling thread until the task finishes, so it clears `SynchronizationContext.Current` while it waits. An `[StaFact]` test thread has a context, and without clearing it every await that doesn't finish synchronously posts its continuation back to the blocked thread, which hangs the test. `TaskManagerSynchronousModeTests` pins this.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.