Skip to content

feat: scope worker names to stack slug and add --name-template#68

Merged
kaiitunnz merged 4 commits into
mainfrom
kaiitunnz/feat/worker-naming
Jun 9, 2026
Merged

feat: scope worker names to stack slug and add --name-template#68
kaiitunnz merged 4 commits into
mainfrom
kaiitunnz/feat/worker-naming

Conversation

@kaiitunnz

@kaiitunnz kaiitunnz commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Purpose

flowmesh stack worker up cpu|gpu generated preset worker aliases from hardcoded, non-namespaced names (worker_cpu_0, worker_gpu_0, …). The server's DockerWorkerFactory uses the alias verbatim as the worker name and as the basis for the container name, but worker containers spawned by every stack share the host docker daemon namespace. Unlike the server / redis / volume names, which all carry the stack slug (flowmesh_node[_<suffix>]_*), these worker names were not stack-scoped, so two stacks differentiated by FLOWMESH_STACK_SUFFIX on the same host produced colliding worker containers.

This scopes preset worker names to the stack slug by default and adds a --name-template for custom naming.

Changes

  • Alias constructionsdk/stack/src/flowmesh_stack/workers.py: create_workers / _payloads_for_worker_create gain name_template and slug params (both default None, so direct SDK callers and the --config paths keep today's behavior). New _worker_alias helper builds {slug}_worker_{kind}_{idx|gpu} by default, or renders a template over {slug} / {kind} / {idx} / {gpu} via a strict format dict that raises a clear FlowMeshError on an unknown placeholder. Generated aliases are deduped within one invocation.
  • CLI wiringcli/stack/src/flowmesh_cli_stack/worker.py: worker up gains --name-template, resolves the stack slug from env (reusing stack_resource_env_overrides / STACK_SLUG_ENV, which read the already-loaded FLOWMESH_STACK_SUFFIX), and passes both down. An invalid suffix exits cleanly.
  • Docsdocs/CLI.md: document the slug-prefixed default naming and --name-template with its placeholders.
  • Teststests/sdk/test_workers.py: cover slug-prefixed defaults, legacy bare names, template rendering, the unknown-placeholder error, the duplicate-name guard, and GPU single/multi cases.

Design

The default name is not expressed as a template string; it is the existing per-kind logic with a slug prefix, so GPU workers keep their informative _gpu_<id> / _gpu_all suffix. --name-template is a full override; when present it alone determines the alias. To prevent the obvious foot-gun (a template without {idx}/{gpu} for count > 1), all generated aliases are checked for uniqueness within a single up invocation and a missing-disambiguator template fails fast. The default prefix is the full stack slug (flowmesh_node + optional suffix), matching the convention every other stack-managed object already follows.

Test Plan

uv run pytest tests/sdk/test_workers.py tests/cli/test_stack_utils.py tests/server/test_command_listener.py
uv run pre-commit run --files sdk/stack/src/flowmesh_stack/workers.py cli/stack/src/flowmesh_cli_stack/worker.py tests/sdk/test_workers.py docs/CLI.md

End-to-end (flowmesh stack worker up / list / down): default and suffix-scoped naming, cross-stack isolation (two stacks, no collision), --name-template rendering, fail-fast on bad templates, and GPU naming (single / per-GPU / --targets all / template).

Test Result

$ uv run pytest tests/sdk/test_workers.py            # 9 passed
$ uv run pytest tests/cli/test_stack_utils.py \
                tests/server/test_command_listener.py # 39 passed (server alias path unaffected)
$ uv run pre-commit run --files ...                  # isort/black/ruff/mypy/codespell passed

End-to-end scenarios above all passed, including GPU workers on a 2-GPU host — every worker came up healthy with a correctly slug-prefixed name and no collisions.


Pre-submission Checklist
  • I have read the contribution guidelines.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added or updated tests covering my changes (if applicable).
  • I have verified that uv run pytest tests/ passes locally.
  • If I changed shared schemas or proto definitions, I have checked downstream compatibility across Server and Worker. (No schema/proto changes.)
  • If I changed the SDK or CLI, I have verified the affected packages work (uv sync --all-packages --group ci --frozen).
  • If this is a breaking change, I have prefixed the PR title with [BREAKING] and described migration steps above.
  • I have updated documentation or config examples if user-facing behavior changed.

kaiitunnz added 4 commits June 8, 2026 23:28
Preset cpu/gpu worker aliases were hardcoded (worker_cpu_0, ...) and
not stack-scoped, so worker containers spawned by different stacks
sharing a host docker daemon collided — unlike the server/redis/volume
names, which all carry the stack slug. Default preset names are now
prefixed with the stack slug (flowmesh_node[_<suffix>]_worker_*), and
worker up gains --name-template ({slug}/{kind}/{idx}/{gpu}) for custom
naming, with a duplicate-name guard within a single invocation.

Signed-off-by: Noppanat Wadlom <noppanat.wad@gmail.com>
Catch ValueError from format_map so a malformed --name-template (e.g.
unbalanced braces) surfaces a clean FlowMeshError instead of an uncaught
traceback. Remove the unreachable "No GPUs detected" check — both GPU
branches always append at least one spec.

Signed-off-by: Noppanat Wadlom <noppanat.wad@gmail.com>
Route the default cpu/gpu naming through the same format_map path as a
user-supplied --name-template by synthesizing the default template, so
there is a single rendering site. Output is unchanged.

Signed-off-by: Noppanat Wadlom <noppanat.wad@gmail.com>
…g6j-4rv6-33pg

pip-audit's strict server scan flagged aiohttp 3.13.5 for two upstream
advisories, both fixed in 3.14.0. Raise the floor, re-lock (resolves
3.14.1), and regenerate the worker requirements files.

Signed-off-by: Noppanat Wadlom <noppanat.wad@gmail.com>
@kaiitunnz kaiitunnz marked this pull request as ready for review June 9, 2026 10:53
@kaiitunnz kaiitunnz requested a review from timzsu as a code owner June 9, 2026 10:53

@timzsu timzsu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kaiitunnz kaiitunnz merged commit 430dba1 into main Jun 9, 2026
11 checks passed
@kaiitunnz kaiitunnz deleted the kaiitunnz/feat/worker-naming branch June 9, 2026 12:25
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