Skip to content

Add grid_device.py update command to switch a worker's model in place - #33

Merged
maun200 merged 1 commit into
mainfrom
feature/worker-model-switch
Nov 11, 2026
Merged

maun200 merged 1 commit into
mainfrom
feature/worker-model-switch

Conversation

@maun200

@maun200 maun200 commented Nov 11, 2026

Copy link
Copy Markdown
Owner

What does this PR change?

Adds a way to change a device's operator-approved model without reissuing its worker token.

Previously the only way to switch a device's model was remove + add, which creates a brand
new worker identity/token and means a fresh bundle has to be carried to the device again
(USB/scp/Taildrop — never chat, per AGENTS.md). That's heavy-handed for what is often just "this
device can handle a bigger/smaller model now."

  • New coordinator endpoint: POST /api/admin/workers/{id}/model (admin-only). Validates the new
    model against CAG_ALLOWED_MODELS, 404s on an unknown worker, 409s on a revoked one, otherwise
    updates the worker's model column in place. Token, trust_level and credit history are
    untouched.
  • New script command: grid_device.py update <name> --model <tag>. Looks up the device's
    worker_id from the local registry, calls the new endpoint, and updates the local
    registry.json entry to match.
  • docs/ADD_DEVICE.md: documents the new command and clarifies that the device's own
    CAG_MODEL in worker.env still has to be edited by hand and the worker restarted — this
    endpoint only changes the coordinator-side allowlist entry, there is no secret to redistribute.
  • CHANGELOG.md entry under [Unreleased].

No change to the trusted/community split, and workers still never execute remote commands.

Checklist

  • pytest -q passes locally (238 passed, 3 skipped — pre-existing Windows-only skips)
  • ruff check --select E9,F63,F7,F82 . reports no new errors
  • No secrets, tokens, databases, model weights or real prompts in the diff
  • New behaviour has a test (tests/test_worker_admin.py, tests/test_grid_device.py)
  • CHANGELOG.md updated for user-visible changes
  • The trusted/community split and "workers never run remote commands" are unchanged

How was it tested?

python -m venv .venv && .venv/bin/pip install -e '.[test]'
.venv/bin/python -m pytest -q -m "not slow"
.venv/bin/ruff check --select E9,F63,F7,F82 .
.venv/bin/python scripts/check_public_tree.py

All green locally; new tests cover the happy path (model switch changes which queued jobs the
worker can claim), identity/trust/credits staying untouched, rejecting an unapproved model, and
404/409/403 on an unknown/revoked/non-admin request.

🤖 Generated with Claude Code

Previously the only way to change a device's approved model was remove + add,
which reissued its worker token and required carrying a fresh bundle to the
device. Add a coordinator endpoint (POST /api/admin/workers/{id}/model) and a
matching `grid_device.py update <name> --model <tag>` command that change only
the model, keeping the worker's identity, token and trust/credit history intact.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T22:22:54.798720Z 404faef PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 404faefc6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/grid_device.py
Comment on lines +170 to +171
response = client.post(f"{base}/api/admin/workers/{worker_id}/model",
headers={"Authorization": f"Bearer {admin_key}"}, json={"model": args.model})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Quiesce the old worker before retagging it

When this runs while the device is still polling with its old CAG_MODEL—the documented sequence edits and restarts it only after this command returns—the coordinator immediately offers it jobs for the new model. worker.client.infer() rejects those jobs because its configured model is still old, and repeated failures can exhaust the three attempts and fail queued jobs. Keep the worker stopped until its local config matches the new model and this update has completed.

Useful? React with 👍 / 👎.

@maun200
maun200 merged commit 7198fbc into main Nov 11, 2026
14 checks passed
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.

1 participant