feat(agents): reach sources through a relay agent #64

Merged
jfro merged 5 commits from feat/6-relay-agent into main 2026-11-14 14:26:52 +00:00
Owner

What changed

Browser-checked PR #64 at 390px and desktop with a real agent (C17: token shown once, Online/Offline/Revoked badges, delete, revoked token rejected, agent select only where valid); audited it against the design; the one bug found (F1 revoke race) is fixed in 4df7474 and my failing test for it now passes with the agent suite (C21), CI green.

Fixes #6

Red, then green

  • A source set to reach through a relay agent sends its fully built request (final URL with params, auth header) to the agent's long-poll through the Hub, and gets the agent's answer back as a normal decoded response.: export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix test test/lamplighter/agents/relay_test.exs
    • fails on the base (169940c): exit 1
    • passes on the branch (f204d64): exit 0

Checks

  • In real Chromium against the dev server (:4126) at 390px and 1280px, Settings → Agents creates agents with the token shown once inside the compose snippet, revoke works, the Proxmox source form offers only the live agent, and QNAP's form has no agent select; screenshots are on PR #64. (Upper Wolfjaw): cd /tmp && timeout 150 ~/.venvs/pw/bin/python /home/peak/work/lamplighter-v1-2/checks/agents_browser.py, exit 0
  • LiveView tests pass for Settings → Agents (create with token shown once, unique names, revoke, delete, fresh sign-in) and the source form's agent select (QNAP and Docker socket refused, revoked agents refused, switching agents asks for secrets again). (Upper Wolfjaw): export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix test test/lamplighter_web/live/agent_settings_live_test.exs test/lamplighter_web/live/source_live/agent_select_test.exs, exit 0
  • Agent mode works: allowlist parsing and matching, env config (fail closed), the executor (refuses hosts outside AGENT_ALLOW with no request made, no redirects, a body cap, never logs tokens or query strings), poller backoff, and an end-to-end run where a real poller and the agent API relay a source's request. (Upper Wolfjaw): export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix test test/lamplighter/agent/ test/lamplighter/agents/, exit 0
  • mix precommit (compile --warnings-as-errors, format, the full suite of 980 tests) passes on feat/6-relay-agent with agent mode in. (Upper Wolfjaw): export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix precommit 2>&1 | tail -3, exit 0
  • Real-browser check (Chromium, 390px and 1280px) of Settings → Agents and the source form on f05af0d passes: token shown once with compose snippet, no overflow, Never connected → Online live with a real agent → Offline after it stops, revoke/delete, revoked token stays rejected, select only once an agent exists, absent on QNAP, Docker unix socket + agent errors. (Nye): cd /home/peak/work/lamplighter-v1-2/lamplighter && source ../env.sh && python3 ../review6/nye_agents_check.py | grep -v 'badge goes Offline' ; python3 ../review6/nye_agent_offline_check.py, exit 0
  • At 4df7474 my F1 revoke-race test and all agent tests pass: a poll that passed auth before revoke now gets {:error, :revoked} and no source jobs. (Nye): source ../env.sh && mix test test/lamplighter/agents test/lamplighter/agents/nye_revoke_race_test.exs, exit 0

Found and fixed

  • F1 bug: A poll that passes AgentAuth just before its agent is revoked registers with the Hub after Hub.disconnect, and the Hub then marks the revoked agent online and hands it source jobs (URLs plus credentials) for up to one 25s hold; the Hub should refuse awaits for a disconnected agent. (fixed)

Risks

Hub is in memory, so single replica only (D7, already documented). The revoked-agent set grows by one entry per revoke until restart (negligible). QNAP SNMP and the Docker unix socket can't go through an agent (D11, documented). 7 small nits sent to Upper Wolfjaw (e.g. a timeout message says 15s where the docs say 25s; docs omit AGENT_ALLOW_INSECURE_SERVER) don't block shipping. Jeremy hasn't seen assumed decisions D7–D11.

Prover

Passed (Sonnet): At 4df7474 the agent suites (94) and full precommit (981) pass, and my own revoke-race test and allowlist probes found nothing; not rerun: browser checks, real Docker image, multi-replica.

Every command above was run by Fortysix's Basecamp itself, on the branch named.

## What changed Browser-checked PR #64 at 390px and desktop with a real agent (C17: token shown once, Online/Offline/Revoked badges, delete, revoked token rejected, agent select only where valid); audited it against the design; the one bug found (F1 revoke race) is fixed in 4df7474 and my failing test for it now passes with the agent suite (C21), CI green. Fixes #6 ## Red, then green - A source set to reach through a relay agent sends its fully built request (final URL with params, auth header) to the agent's long-poll through the Hub, and gets the agent's answer back as a normal decoded response.: `export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix test test/lamplighter/agents/relay_test.exs` - fails on the base (169940c): exit 1 - passes on the branch (f204d64): exit 0 ## Checks - In real Chromium against the dev server (:4126) at 390px and 1280px, Settings → Agents creates agents with the token shown once inside the compose snippet, revoke works, the Proxmox source form offers only the live agent, and QNAP's form has no agent select; screenshots are on PR #64. (Upper Wolfjaw): `cd /tmp && timeout 150 ~/.venvs/pw/bin/python /home/peak/work/lamplighter-v1-2/checks/agents_browser.py`, exit 0 - LiveView tests pass for Settings → Agents (create with token shown once, unique names, revoke, delete, fresh sign-in) and the source form's agent select (QNAP and Docker socket refused, revoked agents refused, switching agents asks for secrets again). (Upper Wolfjaw): `export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix test test/lamplighter_web/live/agent_settings_live_test.exs test/lamplighter_web/live/source_live/agent_select_test.exs`, exit 0 - Agent mode works: allowlist parsing and matching, env config (fail closed), the executor (refuses hosts outside AGENT_ALLOW with no request made, no redirects, a body cap, never logs tokens or query strings), poller backoff, and an end-to-end run where a real poller and the agent API relay a source's request. (Upper Wolfjaw): `export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix test test/lamplighter/agent/ test/lamplighter/agents/`, exit 0 - mix precommit (compile --warnings-as-errors, format, the full suite of 980 tests) passes on feat/6-relay-agent with agent mode in. (Upper Wolfjaw): `export PATH=$HOME/.local/bin:$PATH && eval "$(mise activate bash --shims)" && MIX_TEST_PARTITION=6 mix precommit 2>&1 | tail -3`, exit 0 - Real-browser check (Chromium, 390px and 1280px) of Settings → Agents and the source form on f05af0d passes: token shown once with compose snippet, no overflow, Never connected → Online live with a real agent → Offline after it stops, revoke/delete, revoked token stays rejected, select only once an agent exists, absent on QNAP, Docker unix socket + agent errors. (Nye): `cd /home/peak/work/lamplighter-v1-2/lamplighter && source ../env.sh && python3 ../review6/nye_agents_check.py | grep -v 'badge goes Offline' ; python3 ../review6/nye_agent_offline_check.py`, exit 0 - At 4df7474 my F1 revoke-race test and all agent tests pass: a poll that passed auth before revoke now gets {:error, :revoked} and no source jobs. (Nye): `source ../env.sh && mix test test/lamplighter/agents test/lamplighter/agents/nye_revoke_race_test.exs`, exit 0 ## Found and fixed - F1 bug: A poll that passes AgentAuth just before its agent is revoked registers with the Hub after Hub.disconnect, and the Hub then marks the revoked agent online and hands it source jobs (URLs plus credentials) for up to one 25s hold; the Hub should refuse awaits for a disconnected agent. (fixed) ## Risks Hub is in memory, so single replica only (D7, already documented). The revoked-agent set grows by one entry per revoke until restart (negligible). QNAP SNMP and the Docker unix socket can't go through an agent (D11, documented). 7 small nits sent to Upper Wolfjaw (e.g. a timeout message says 15s where the docs say 25s; docs omit AGENT_ALLOW_INSECURE_SERVER) don't block shipping. Jeremy hasn't seen assumed decisions D7–D11. ## Prover Passed (Sonnet): At 4df7474 the agent suites (94) and full precommit (981) pass, and my own revoke-race test and allowlist probes found nothing; not rerun: browser checks, real Docker image, multi-replica. Every command above was run by Fortysix's Basecamp itself, on the branch named.
jfro added this to the v1.2 milestone 2026-11-14 00:16:18 +00:00
feat(agents): reach sources through a relay agent
All checks were successful
CI / test (pull_request) Successful in 1m31s
474b3ce4a6
feat(agents): manage agents in settings and pick one per source
All checks were successful
CI / test (pull_request) Successful in 1m18s
ace238d482
Settings → Agents creates an agent (token shown once in a compose
snippet), shows whether it's online and which sources use it, revokes
and deletes it. A source's form gets a "Reach through agent" select
once an agent exists. QNAP (SNMP) and a Docker unix socket can't go
through an agent. Moving a source to another agent counts as retargeting,
so its stored secrets have to be entered again.
Author
Owner

Settings → Agents and the source form's agent select (feat/6-relay-agent @ace238d), Chromium at 390px and 1280px. Check script: checks/agents_browser.py on my side.

390-agents-created
390-agents-created

desktop-agents-created
desktop-agents-created

390-agents-list
390-agents-list

desktop-agents-list
desktop-agents-list

390-source-agent
390-source-agent

desktop-source-agent
desktop-source-agent

Settings → Agents and the source form's agent select (feat/6-relay-agent @ace238d), Chromium at 390px and 1280px. Check script: checks/agents_browser.py on my side. **390-agents-created** ![390-agents-created](https://git.knope.dev/attachments/cca3da64-749d-4322-b358-bb2eb1b2f486) **desktop-agents-created** ![desktop-agents-created](https://git.knope.dev/attachments/8c865c17-4263-4ab1-a9a7-67ced336abfa) **390-agents-list** ![390-agents-list](https://git.knope.dev/attachments/b114a750-922f-4d1e-8133-46dc6c9658a8) **desktop-agents-list** ![desktop-agents-list](https://git.knope.dev/attachments/9027fc7d-c60c-4c6c-b735-1079140fc9ca) **390-source-agent** ![390-source-agent](https://git.knope.dev/attachments/b745572f-8aae-4f07-9c10-b3fd8994b149) **desktop-source-agent** ![desktop-source-agent](https://git.knope.dev/attachments/c2cf5977-4be7-4de1-960c-4057d012c9a5)
feat(agent): agent mode of the image
Some checks failed
CI / test (pull_request) Has been cancelled
48ebf003ec
LAMPLIGHTER_MODE=agent runs the same image as a relay agent: no database
or web server, just a poller that long-polls Lamplighter for requests,
makes each one only if its host and port are in AGENT_ALLOW (fail closed),
and posts the raw response back. Settings come from the environment and
are checked at boot. Backs off on errors (5 minutes on a revoked token or
protocol mismatch). bin/server skips migrations and the healthcheck uses
the poller's heartbeat in agent mode.
docs(agent): set up an agent for sources behind NAT
All checks were successful
CI / test (pull_request) Successful in 1m41s
f05af0da4e
docs/agent.md covers setup, AGENT_ALLOW, the trust model, what an agent
can't relay (QNAP over SNMP, Docker sockets) with Tailscale or WireGuard
as the way for those, and troubleshooting. Adds a compose example and a
README section.
fix(agents): refuse polls and jobs for a revoked agent
All checks were successful
CI / test (pull_request) Successful in 1m18s
4df747473d
A poll that passed AgentAuth just before its agent was revoked could
register with the Hub after disconnect, mark the agent online and be
handed source jobs for one hold. The Hub now remembers disconnected
agents and refuses their awaits and requests with {:error, :revoked}.
jfro merged commit 1d677081f4 into main 2026-11-14 14:26:52 +00:00
jfro deleted branch feat/6-relay-agent 2026-11-14 14:26:53 +00:00
Sign in to join this conversation.
No description provided.