Skip to content

examples: share a local model, refused then granted by name, with a recorded demo - #922

Merged
aojea merged 2 commits into
google:mainfrom
HosniBelfeki:examples/share-local-model
Nov 22, 2026
Merged

aojea merged 2 commits into
google:mainfrom
HosniBelfeki:examples/share-local-model

Conversation

@HosniBelfeki

Copy link
Copy Markdown
Contributor

This demo shows deny by default with a local model: node B cannot use the
model node A serves until the operator grants that one service by name.

What's added

  • development/examples/share-local-model/: record.sh records the demo
    with VHS and tmux; SCRIPT.md describes each scene.
  • site/static/demo-share-local-model.mp4: the video (1:51).
  • site/content/docs/use-cases/share-local-model.md: a use-case page.
  • A card in the landing page's demo section.

What the video shows

  1. Node A publishes a local Ollama model as inference://laptop-llm.
  2. Node B asks for it and is refused: node A logs DENY.
  3. The operator grants the service by name, with no restart.
  4. The same request is allowed: node A logs ALLOW and the model answers.
  5. Antigravity CLI and OpenCode find the model through node B's MCP server.

Tested

  • AGENTS=0 ./record.sh records steps 1 to 8 end to end with agentmesh
    v0.2.0 and Ollama gemma3:1b: DENY before the grant, ALLOW after it.
  • The site builds with Hugo 0.147.5, the version in CI, and the new page and
    card render.

Node A publishes a local Ollama model as inference://laptop-llm. Node B
is refused by default, the operator grants the service to
mesh:role:node through POST /policies, and the same chat completion is
allowed. Antigravity CLI and OpenCode then find the model through node
B's MCP server.

record.sh records it with VHS and tmux. Every Agent Mesh command is
typed on camera, audit.py reduces each node's log to its authorization
decisions, and a caption pane narrates. AGENTS=0 records the first
eight steps without the agent CLIs, and PUBLISH=0 leaves site/static
untouched. SCRIPT.md lists the scenes and the recording recipe.
The recording from development/examples/share-local-model (1:51,
3.3 MB) goes to site/static, with a use-case page that explains it and
a card in the landing page's demo section. The grid has three columns,
so the fourth card starts a second row.
@HosniBelfeki
HosniBelfeki requested a review from aojea as a code owner November 22, 2026 15:16

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new 'Share a Local Model' use-case example, including a complete demo recording setup using VHS, documentation, and helper scripts. The feedback highlights several robustness improvements: in grant.sh, registering the EXIT trap before calling mktemp to avoid uncleaned temporary files on early failure, and checking that the token file is non-empty; in audit.py, handling potential None values in parsed JSON fields to prevent runtime crashes, and explicitly specifying file encoding; and in record.sh, adding a safety check for the duration value extracted by ffprobe before performing arithmetic in awk.

Comment on lines +35 to +38
hdr=$(mktemp)
cur=$(mktemp)
new=$(mktemp)
trap 'rm -f "$hdr" "$cur" "$new"' EXIT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Registering the EXIT trap after creating the temporary files with mktemp creates a race condition. If the script exits or fails (e.g., due to set -o errexit) during the second or third mktemp call, the previously created temporary files will not be cleaned up. Initializing the variables and registering the trap beforehand ensures robust cleanup under all failure scenarios.

Suggested change
hdr=$(mktemp)
cur=$(mktemp)
new=$(mktemp)
trap 'rm -f "$hdr" "$cur" "$new"' EXIT
hdr=""
cur=""
new=""
trap 'rm -f "$hdr" "$cur" "$new"' EXIT
hdr=$(mktemp)
cur=$(mktemp)
new=$(mktemp)


fail() { echo "grant: $*" >&2; exit 1; }

[[ -r "$TOKEN_FILE" ]] || fail "admin token not readable at $TOKEN_FILE; is agentmesh-one running?"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using [[ -r ... ]] only checks if the file is readable. If the token file exists but is empty, the script will proceed and send an empty authorization header, resulting in an auth failure. Using [[ -s ... ]] ensures the file is both readable and non-empty.

Suggested change
[[ -r "$TOKEN_FILE" ]] || fail "admin token not readable at $TOKEN_FILE; is agentmesh-one running?"
[[ -s "$TOKEN_FILE" ]] || fail "admin token not readable or empty at $TOKEN_FILE; is agentmesh-one running?"

Comment on lines +56 to +63
target = d.get("target", "")
if target.startswith("system://"):
return None
who = f"{d.get('role') or '-'} {d.get('peer_id', '')[:12]}…"
what = " ".join(x for x in (d.get("method"), d.get("path")) if x) or d.get("protocol", "")
decision = d.get("decision", "?").upper()
word = paint(decision, f"{decision:<5}") if decision in COLOR else f"{decision:<5}"
return f"{word} {who:<28} {what:<26} {target}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Several fields extracted from the parsed JSON (such as target, peer_id, and decision) can potentially be null (None in Python) or of unexpected types. Directly calling string methods like .startswith(), .upper(), or slicing ([:12]) on None will raise AttributeError or TypeError and crash the log filtering script. Providing robust fallback defaults ensures the script handles any malformed or incomplete audit log entries gracefully.

Suggested change
target = d.get("target", "")
if target.startswith("system://"):
return None
who = f"{d.get('role') or '-'} {d.get('peer_id', '')[:12]}…"
what = " ".join(x for x in (d.get("method"), d.get("path")) if x) or d.get("protocol", "")
decision = d.get("decision", "?").upper()
word = paint(decision, f"{decision:<5}") if decision in COLOR else f"{decision:<5}"
return f"{word} {who:<28} {what:<26} {target}"
target = d.get("target")
if not isinstance(target, str):
target = ""
if target.startswith("system://"):
return None
role = d.get("role") or "-"
peer_id = d.get("peer_id") or ""
who = f"{role} {peer_id[:12]}…"
method = d.get("method") or ""
path = d.get("path") or ""
protocol = d.get("protocol") or ""
what = " ".join(x for x in (method, path) if x) or protocol
decision = (d.get("decision") or "?").upper()
word = paint(decision, f"{decision:<5}") if decision in COLOR else f"{decision:<5}"
return f"{word} {who:<28} {what:<26} {target}"



raw_path = os.environ.get("AUDIT_RAW")
with (open(raw_path, "a") if raw_path else nullcontext()) as raw:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When opening files in Python 3, it is a best practice to explicitly specify the encoding parameter (e.g., encoding="utf-8") to prevent platform-dependent encoding issues, especially when running on environments with different default locales.

Suggested change
with (open(raw_path, "a") if raw_path else nullcontext()) as raw:
with (open(raw_path, "a", encoding="utf-8") if raw_path else nullcontext()) as raw:


[[ -s "$OUT/raw.mp4" ]] || fail "vhs wrote no video"
dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$OUT/raw.mp4")
fade_out=$(awk -v d="$dur" 'BEGIN { printf "%.2f", d - 1.0 }')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If ffprobe fails or returns an empty/non-numeric duration, dur will be empty or invalid, causing awk to produce a negative or invalid fade_out value. This will subsequently cause the ffmpeg command to fail. Adding a safety check in awk to ensure the duration is valid and greater than 1.0 before subtracting prevents such failures.

Suggested change
fade_out=$(awk -v d="$dur" 'BEGIN { printf "%.2f", d - 1.0 }')
fade_out=$(awk -v d="$dur" 'BEGIN { if (d+0 > 1.0) printf "%.2f", d - 1.0; else print "0.00" }')

@aojea

aojea commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks

@aojea
aojea merged commit c2f725d into google:main Nov 22, 2026
21 checks passed
@HosniBelfeki
HosniBelfeki deleted the examples/share-local-model branch November 26, 2026 20:08
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