From c2ff8fadbd0dc99a5453b2f5ee59fd4ef9cb0cc3 Mon Sep 17 00:00:00 2001 From: Hermenix Date: Sun, 11 Oct 2026 22:41:01 +0000 Subject: [PATCH] fix(nix): let the mcp http unit recover from its own refusal The server exits 2 while the authorization table is empty, which is the right call: a listener that 401s every request is almost always a forgotten `token mint`, and "connection works, auth fails" is far worse to debug than a `systemctl status` naming the remedy. But that puts a freshly provisioned machine in a failed state, and systemd's default start-rate limit -- five starts in ten seconds, then give up -- would leave it there permanently. So minting the first token would ALSO have needed a `systemctl start` that nothing told anyone about, and the refusal would have turned from a helpful message into a trap on every machine that enables the option. `StartLimitIntervalSec = 0` with `RestartSec = 5` is what makes the trade sound: the unit retries indefinitely and comes up on its own within one interval of the first mint. The cost is a journal line every five seconds while the table is empty, which names exactly what is wrong. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01KchcvnbfhhZhUHy83YL3Ya --- nix/module.nix | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 8049e53..ac32ecb 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -863,10 +863,16 @@ in { Mint a token with `hhstream-mcp token mint`, run as {option}`sessions.user`, and give it to the client as an - `Authorization: Bearer …` header. **The unit refuses to start while - the table is empty**, because a listener that 401s every request is - almost always a forgotten mint; `--allow-no-tokens` is the escape - hatch for provisioning. + `Authorization: Bearer …` header. + + **The unit refuses to start while the table is empty**, because a + listener that 401s every request is almost always a forgotten mint, + and "connection works, auth fails" is far worse to debug than a + `systemctl status` that names the remedy. It retries every five + seconds rather than giving up, so it comes up on its own within one + interval of the first `token mint` — no `systemctl start` needed. + Pass `--allow-no-tokens` through {option}`mcp.http.extraArgs` to + start anyway. Not MCP's authorization specification, which is OAuth 2.1 plus RFC 9728 metadata discovery. A client that can only *discover* an @@ -1531,7 +1537,24 @@ in { UMask = "0077"; Restart = "on-failure"; - RestartSec = 2; + RestartSec = 5; + # No start-rate limit, which is what makes the empty-table refusal + # usable rather than merely correct. + # + # The server exits 2 while no token exists, because a listener that + # 401s every request is almost always a forgotten `token mint` and + # "connection works, auth fails" is a far worse thing to debug than a + # unit whose `systemctl status` names the remedy. But that puts a + # freshly provisioned machine in a failed state until an operator acts, + # and systemd's default (5 starts in 10s, then give up) would leave it + # there for good -- so minting the first token would also need a + # `systemctl start` nothing told anyone about. + # + # With the limit off, the unit retries every 5 seconds and comes up on + # its own within one interval of the first mint. The cost is a journal + # line every 5 seconds while the table is empty, which names exactly + # what is wrong. + StartLimitIntervalSec = 0; NoNewPrivileges = true; # This unit launches nothing and adopts nothing: it is a listener in