Skip to content

Gateway changes and monitoring

This is the gateway document, part of OKR 2 (the objective "AI service: performance, packaging, monitoring"). It is on Card 3 of the card list, together with the back-end document. Done on 25 Nov, with backups and a rollback: the gateway now logs tokens read, reused and written for every request, runs with --priority-idle 1, and lets everyone read /slots and /metrics (temporary, for the pilot). The gateway is ~/callbot/finetune/cloud27b/llm_gate.py at 172.25.25.17:8001, the callbot owner's file. Not done and not counted here: narrowing the monitoring access, the monitoring dashboard, and a decision on /props. Rules for every test are in the quality-gate document, last section "Before you run any test".

Each change in plain words, with an example

The language model sits behind a small program called the gateway (the doorman): the hotel back-end sends its questions to the gateway at 172.25.25.17:8001, and the gateway passes them to the model and writes a log line for each one. We wanted to see what is happening inside, without changing how guests are served. Two words: llama-server is the program that runs the model, and the idle timer cuts a request that has received no answer for 60 s. Nothing here is a model test; each change is checked by sending a request and looking at the log or at the answer code (200 means OK, 403 means refused on purpose, 503 means busy, 504 means timed out).

What this document is for, in one line. The gateway is the only place where every request to the model can be seen, so it is where we add the numbers a monitoring page needs (is a request cold or warm, how long does it wait, which lane is busy). Each change below gives us one of those numbers, and the check at the end tells us that nothing broke. How to read a log line: tok_read is new tokens the model had to read, tok_reused is tokens it took from the cache, tok_out is tokens it wrote; a request with a high tok_reused and a small tok_read is warm and fast.

Change 1. Token log: see whether a request was cold or warm

  • The problem: the log said how long a request took, but not why. A slow request could be a cold read (the server read the whole 4,600-token hotel prompt again, about 16 s) or just waiting in a queue.
  • What we added: three numbers per request: tok_read (new tokens the server had to read), tok_reused (tokens taken from the cache) and tok_out (tokens written in the answer).
  • Real example from the log after the change: a hotel request with tok_read 5, tok_reused 863 and tok_out 8 took 491 ms (25 Nov 09:30; this is the back-end's small keep-warm request of about 868 tokens, not a guest question). Only 5 new tokens were read, so it was warm. A cold request would show tok_read near 4,600 and tok_reused 0, and take about 16 s.
  • How we tested it first (on copies of the gateway): the same chat request twice: first tok_read 20, tok_reused 0; the second time tok_read 5, tok_reused 15.
  • What it gives us: a way to prove that the warm-up works and to spot cold starts.

Change 2. --priority-idle 1: make the waiting visible

  • The problem: when two requests arrived together, the second was handed to the model and waited inside it. The model sends nothing until it starts to answer, so the gateway's 60-second timer ran while the request only waited. Real example from the log before the change: a request answered 504 after 60,665 ms, of which only 629 ms were waiting at the gateway (20 Nov 22:11, part of a burst that is still unexplained).
  • What we changed: the number of requests the gateway sends to the model at once when no call is in progress, from 2 to 1, so only one request is inside the model and the next one waits at the gateway, where the wait is counted and visible (it has a 60-second budget there).
  • What it gives us: the same one-at-a-time behaviour as the lane test showed is best, with a visible queue instead of a hidden one.

Change 3. /slots and /metrics open: numbers for a monitoring page

  • The problem: a monitoring dashboard needs live numbers (is a lane busy, how many tokens per second, how many requests), and the gateway refused those two addresses for everyone.
  • What we changed: everyone on the network may read them (temporary, for the pilot, the first trial at a real hotel). /lora-adapters stays refused. We looked at what the two pages contain: for each lane an id, its size (n_ctx), whether it is busy (is_processing), token counters (n_prompt_tokens, n_prompt_tokens_cache, n_prompt_tokens_processed), next_token and params, plus counters and speeds; no prompt text and no guest text.
  • What to do later: narrow it to the address of the monitoring host (the computer that will show the dashboard) and set an end date (open item).

What the gateway does, what changed, and the proposals

What it already did. It forces every outside request onto slot 3 and denies /slots, /lora-adapters and /metrics by default. While a call is in progress it rejects outside generation requests larger than 4,096 bytes with 503; the hotel back-end (172.25.25.15) is exempt and queued instead. It drops a request whose client has gone, and cuts a request after 60 s without a byte or 180 s in all.

Changed on 25 Nov (backups in /Users/non/wall-q4/backup/; only the gateway was restarted, three times; the LLM and the callbot were not touched; hotel requests stayed 200)

Change What it does Applied
Token log Each generation request logs tok_read (new tokens read), tok_reused (from cache) and tok_out (written), so cold starts are visible 09:28
--priority-idle 1 A waiting request waits at the gateway, where its 60 s budget is visible, not inside llama-server where the idle timer runs 09:33
--monitor-ips "*" Everyone may GET /slots and /metrics; they hold ids, counters and speeds, no prompt or guest text. Temporary, for the pilot. /lora-adapters stays 403 for everyone 09:38

/props is also open to everyone: it was already in the gateway's own GET list before this change, so it is not a new exposure, but whether it is intended needs the callbot owner's answer.

Where each change is. The token log and the monitoring option are in the gateway file /Users/non/callbot/finetune/cloud27b/llm_gate.py. --priority-idle 1 and --monitor-ips "*" are on line 167 of the start script /Users/non/wall-q4/wall_mac_up_q4.sh (owned by root; edited with sudo).

Tested before applying (on copies, ports 18001 and 18002): /metrics and /slots 200 from the monitor address and 403 without the option; /lora-adapters 403 even for the monitor address; a chat request logged tok_read 20 and tok_reused 0, then tok_read 5 and tok_reused 15. Not tested: a real hotel request on the copy, the call policy with a call in progress.

Gateway proposals

# Change Status
1 Warm the real hotels' guide prompt with a long interval (for example 300 s) via ASSISTANT_GUIDE_WARM_HOTELS Open: back-end setting, test on staging first (Peach)
2 Log tokens read and reused Done
3 --priority-idle 2 to 1 Done
4 Second outside slot for the hotel Withdrawn: the lane test showed no gain (speed document)
5 /slots and /metrics only from the monitoring host Partly done: open to everyone now; narrow to the monitoring host's IP later
6 Warm the guide prompt once after every LLM restart Open

Who and when. Row 1 (guide warm-up, setting ASSISTANT_GUIDE_WARM_HOTELS in the back-end): Peach, after a staging test. Row 5 (narrow /slots and /metrics to the monitoring host): the callbot owner, when the host's address is known. Row 6 (warm after every restart): the callbot owner and Peach. Dates are to be set by Non.

How to check the gateway, and the rollback

How to check (no restart needed)

On the Mac mini only:

bash runner/lanes_swap.sh status                         # command identical to the snapshot, marker off
tail -3 ~/wall/out/wall/llm_gate.log                     # hotel requests (172.25.25.15) are 200 and show the token fields

From any machine on the network:

for p in /health /metrics /slots /props /lora-adapters; do echo -n "$p "; curl -s -o /dev/null -w '%{http_code}\n' http://172.25.25.17:8001$p; done

Expected: 200 for /health, /metrics, /slots and /props; 403 for /lora-adapters. Hotel back-end requests (172.25.25.15) are 200 in the log and show tok_read, tok_reused and tok_out. Verified on 25 Nov after the last restart (09:38:34): /metrics 200, /slots 200, /lora-adapters 403, POST /metrics 403, /health 200, /props 200.

Rollback

  • Copy llm_gate.py.orig (in serving/gateway_patch/; the same as the backup llm_gate.py.pre-tokenlog-20261125-092750) over /Users/non/callbot/finetune/cloud27b/llm_gate.py and restart only the gateway: kill the pid in ~/wall/out/wall/gate.pid; the 60-second launchd job starts it again.
  • Remove --priority-idle 1 --monitor-ips "*" from line 167 of /Users/non/wall-q4/wall_mac_up_q4.sh (root-owned, edit with sudo; backups wall_mac_up_q4.sh.root-20261125-093309 and -093803).
  • To narrow instead of remove: change "*" to the monitoring host's IP on that line and restart the gateway. The option takes * or a comma list of IPs; empty means closed.
  • Details: serving/gateway_patch/README.md, serving/gateway_patch/gateway.patch (79 lines; applies cleanly to the live file), serving/GATEWAY_PROPOSAL.md.

Does not show: a real hotel request on the patched code under a call in progress; load through the gateway with the call policy active.