Skip to content

Commit b042b2e

Browse files
Petrus Pennanenclaude
andcommitted
Discovery: a command line is a claim, not configuration
Review finding (@codexmb): parseServeLine took /tensorfold-native serve anywhere in a joined ps line, so `printf /tmp/tensorfold-native serve ... --host example.invalid --api-key-file /tmp/dummy-key` parsed as an engine; its --host was kept as the connect address, local:true was forced, and the key file the argv named was read and sent there as a Bearer token. Now, fail closed: - Identity comes from the kernel, not argv: the executable `lsof -d txt` reports (macOS; `ps` comm is argv[0] there) or /proc/<pid>/exe (Linux) must be tensorfold-native, or Python running `-m tensorfold serve` or an absolute .../tensorfold entry script. - Where to read comes from the pid's own LISTEN sockets (lsof, or /proc/<pid>/fd + net/tcp{,6}), loopback or wildcard only; --host is not parsed. A --port the pid does not listen on, several ports with no --port, non-loopback-only sockets, or no lsof: not read, reason in `skipped` (no default-port fallback any more). - No key from a command line at all: --api-key-file is recorded only as "was given", never read. A key comes only from a registry entry marked engine tensorfold (as in #143), merged by port; the card says how. - local is computed from the host again; collectTensorFoldStatus ignores a non-loopback discovered address whatever the caller passes. Tests: @codexmb's repro, an argv[0] that lies (/bin/sleep), a remote --host, a --port the pid does not hold, end to end with a 0600 dummy key file and a key-file spy: no read, no Authorization header, only loopback URLs. Negative control: the previous parser accepts the repro line. 907/907. Live on this Mac: Python 8091, Studio 54635, bench 8101 all verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 31c3b97 commit b042b2e

10 files changed

Lines changed: 558 additions & 225 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Unreleased
44

55
### Added
6-
- **TensorFold engines are discovered from the process table**: the TensorFold status reader (heartbeat and `ide-agent-kit tensorfold-status`) now also finds this user's running `tensorfold-native serve` / `tensorfold serve` engines (one `ps` on macOS, `/proc` on Linux, no sudo; port from `--port`, else the listening socket via `lsof`), merges them with the registry by port and publishes them as `source: "discovered"`, so TensorFold Studio's engine on its random port gets a card. On by default with `INTENT_TENSORFOLD_REGISTRY`; `INTENT_TENSORFOLD_DISCOVER=1` runs it without a registry, `=0` or `--no-discover` turns it off. A discovered engine's `--api-key-file` is read in the engine's own format; process environments and command-line keys are never read, so the Studio engine (key in memory only) reports `metrics: "auth_required"` with its model from the command line. New fields: `name`, `app`, `model_source`, `memory.footprint_gb`, and a top-level `discovery` (`ok` / `off` / `unavailable`). Key files for TensorFold status reads, including a registry `keyFile`, are now refused when other users can read them, as the engine refuses them.
6+
- **TensorFold engines are discovered from the process table**: the TensorFold status reader (heartbeat and `ide-agent-kit tensorfold-status`) now also finds this user's running `tensorfold-native serve` / `tensorfold serve` engines (one `ps` on macOS, `/proc` on Linux, no sudo), merges them with the registry by port and publishes them as `source: "discovered"`, so TensorFold Studio's engine on its random port gets a card. A command line is treated as a claim, not configuration: what a process is comes from its real executable (`lsof -d txt` on macOS, `/proc/<pid>/exe` on Linux), and it is read only at a loopback or wildcard TCP socket its own pid holds in LISTEN state, never at a `--host`; a `--port` it does not listen on, several ports with no `--port`, a non-loopback-only socket, or no way to check (no `lsof`) means the engine is not read. On by default with `INTENT_TENSORFOLD_REGISTRY`; `INTENT_TENSORFOLD_DISCOVER=1` runs it without a registry, `=0` or `--no-discover` turns it off. No key is ever taken from a command line, a key file a command line names, or a process environment: a discovered engine gets a key only through a registry entry marked `"engine": "tensorfold"` on its port with a `keyFile`, so the Studio engine (key in memory only) reports `metrics: "auth_required"` with its model from the command line. New fields: `name`, `app`, `model_source`, `memory.footprint_gb`, and a top-level `discovery` (`ok` / `off` / `unavailable`). Key files for TensorFold status reads, including a registry `keyFile`, are now refused when other users can read them, as the engine refuses them.
77
- **TensorFold status on the device heartbeat**: `uik-daemon` and `ide-agent-kit intent daemon` can publish the live status of each TensorFold server in the model registry under the device's `tensorfold` key, so CodeWatch can show a card per machine. Opt in with `INTENT_TENSORFOLD_REGISTRY=<path to models.json>`; `INTENT_TENSORFOLD_SCOPE=local` (default, loopback entries only) or `all`. Read with GET `/health`, `/metrics` and `/v1/slide/graph` only, never a completion. Publishes model, warming, version/backend/device when the server reports them, memory, running and waiting requests, token counters, tok/s from counter deltas between reads, draft acceptance, TTFT p50, KV cache use, Living Weights fact counts (never fact text) and the metrics auth state. An unreachable server is `reachable: false`; an unreadable registry is an `error`, never an empty list. New `ide-agent-kit tensorfold-status [--json]` prints the same object. The registry gains `engine` (`"tensorfold"` marks an entry, any other name skips it, absent means auto-detect). A key is sent only to an entry marked TensorFold that names its own `keyFile`, and only on the two gated routes; the fleet-wide `LLM_API_KEY` fallbacks are never used for a status read.
88
- **What is still waiting on you** (`bin/iak-pending.mjs`): asks every daemon the fleet knows about - this machine's plus every `watchdog-roster.json` entry with a `gate` - for its pending intents and prints them oldest first with the age in the leading column. Motivation: confirmation cards post to the room correctly and then scroll away; on 2026-09-20 four approval requests sat pending on one machine for up to 9 hours 12 minutes and the owner asked twice in one night what was waiting on him, because no surface anywhere could answer it. A host that could not be reached is reported under its own `COULD NOT ASK` heading and is never folded into "nothing pending"; a gate naming another machine by LAN IP is refused rather than probed and reported the same way. A daemon whose rows carry no `status` this version understands is a shape mismatch rather than an empty queue, and a fleet roster that exists but cannot be parsed or read exits `2` instead of silently shrinking the fleet to this machine (only a *missing* roster means "single-machine install"). An age that cannot be believed - missing, future-dated, or epoch-seconds - renders as `age unknown`, sorts to the top and survives `--older-than`, rather than being clamped to "fresh". Exit codes: `0` all clear, `10` pending, `11` some hosts unreachable, `12` no host reachable, `2` cannot run, precedence `12 > 11 > 10 > 0`; `--older-than` narrows what is printed and announced but can never produce a `0`. `--json` for machines. `--room` requires `--older-than` and announces each item at most once per escalation (threshold, then each doubling of its age), keeping a ledger at `~/.iak/pending-announced.json` that is written atomically before the post, carries forward entries for hosts it could not ask, rolls back when a post fails, and degrades to silence - never a storm - when it is missing, corrupt or unwritable. `examples/pending-launchd.plist` wires it to a timer. The gate token is resolved by the existing `resolveGateToken` helper, is sent only to hosts that helper already trusts, and never appears in output or argv.
99
- **Session degradation watch** (`bin/iak-degradation-watch.mjs`): a per-machine daemon that tails watched agents' Claude Code session transcripts and posts a room alert (pushed to the owner's phone via CodeWatch) the moment a session's `message.model` leaves the configured accepted set or its `permissionMode` differs from the expected one. Motivation: on 2026-07-18 an agent's session silently slipped to a small fallback model with manual permission prompts while the owner was away; the degraded agent kept posting — looping on stale tasks and reposting completed instructions — and cost an evening to diagnose. Alerts fire immediately on first detection (a wrong model in a transcript is a fact, not a flap) with a 30-minute per-signal cooldown and a recovery note. Config: `degradation_watch` block (`interval_sec`, `alert_room`, `agents[]` with `transcript_dir`, `accepted_models` prefix list, `expected_permission_mode`); API key reuses `poller.api_key`. `--once` and `--dry-run` flags for testing. Run one instance per machine under process supervision.

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,9 @@ can show a card for it on each machine.
507507

508508
It is read with GET requests only (`/health`, `/metrics`, `/v1/slide/graph`),
509509
never a completion, and an unreachable server shows as unreachable instead of
510-
stopping the heartbeat. Keys are read only from files (`keyFile`, or an
511-
engine's `--api-key-file`); TensorFold Studio keeps its engine key in memory,
512-
so its card says `metrics: auth required`. The payload shape is in
510+
stopping the heartbeat. Keys are read only from a registry entry's
511+
`keyFile`, never from a command line; TensorFold Studio keeps its engine key
512+
in memory, so its card says `metrics: auth required`. The payload shape is in
513513
`packages/user-intent-kit/README.md`.
514514

515515
UIK v0.2.2 or later recommended for the `uik-daemon` bin. v0.2.0 introduced the daemon, v0.2.1 fixed a silent-exit in the example file, and v0.2.2 added agent-status republish on the heartbeat cadence so the agent slot does not expire while the daemon is running. Pre-0.2.2 daemons publish device state correctly but the agent slot still goes stale after its TTL.

‎config/models.README.md‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,26 @@ Which entries count as TensorFold:
8484

8585
Engines running on this machine do not need an entry at all: the status
8686
reader also finds this user's `tensorfold-native serve` / `tensorfold serve`
87-
processes and reads them the same way (`source: "discovered"`). An entry on
88-
the same loopback port wins: its `id` and `keyFile` are used, and an entry
89-
with no `engine` needs no auto-detection. An entry with another `engine` on
90-
that port stays skipped. Turn discovery off with `INTENT_TENSORFOLD_DISCOVER=0`
91-
or `tensorfold-status --no-discover`.
87+
processes and reads them the same way (`source: "discovered"`). It checks the
88+
process's real executable, not just its command line, and reads it only at a
89+
loopback TCP socket that process is listening on; `--host` is ignored. An
90+
entry on the same loopback port wins: its `id` is used (and its `keyFile`
91+
when it is marked `"engine": "tensorfold"`), and an entry with no `engine`
92+
needs no auto-detection. An entry with another `engine` on that port stays
93+
skipped. Turn discovery off with `INTENT_TENSORFOLD_DISCOVER=0` or
94+
`tensorfold-status --no-discover`.
9295

9396
**Keys.** A TensorFold server may gate `/metrics` and `/v1/slide/graph`
9497
behind a key (`/health` stays open, and says only `{"status": "ok"}` while
9598
keys are on). The status reader sends a key only on those two routes, and
96-
only from a file named for that server: the `keyFile` of an entry marked
97-
`"engine": "tensorfold"`, or the absolute `--api-key-file` a discovered
98-
engine was started with. The file is read the way the engine reads it (one
99-
key per line, `label: key` or a bare key, `#` comments) and refused, as the
100-
engine refuses it, when other users can read it (`chmod 600`). It never uses
101-
`LLM_API_KEY` / `LLM_API_KEY_FILE`, a key on a command line, or a process's
102-
environment. Without a usable key it reports `metrics: "auth_required"` and
99+
only from the `keyFile` of an entry marked `"engine": "tensorfold"`. The file
100+
is read the way the engine reads it (one key per line, `label: key` or a
101+
bare key, `#` comments) and refused, as the engine refuses it, when other
102+
users can read it (`chmod 600`). It never uses `LLM_API_KEY` /
103+
`LLM_API_KEY_FILE`, a key on a command line, a key file a command line names
104+
(`--api-key-file`: any process can name any file there), or a process's
105+
environment. For a keyed engine you started yourself, add an entry for its
106+
port with `"engine": "tensorfold"` and the same file as `keyFile`. Without a usable key it reports `metrics: "auth_required"` and
103107
the rest of the card reads unknown. TensorFold Studio's engine is always in
104108
that state: the app makes a fresh key on every launch, keeps it in memory and
105109
passes it to the engine in the environment, never in a file.

‎packages/user-intent-kit/README.md‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,15 @@ export INTENT_TENSORFOLD_DISCOVER=1 # default with a registry; 0 turns it off
141141
or `INTENT_TENSORFOLD_DISCOVER=1`.
142142
- **Running engines are found too.** Each read also scans this user's
143143
processes for `tensorfold-native serve` and `tensorfold serve` (one `ps` on
144-
macOS, `/proc` on Linux, no sudo), takes the port from `--port` or, when
145-
there is none, from the listening socket (`lsof`), and the model and name
146-
from the command line. They are merged with the registry by port and
147-
published as `source: "discovered"`. This is how TensorFold Studio's engine,
148-
which gets a new random port every launch, gets a card. Process
144+
macOS, `/proc` on Linux, no sudo). A command line is only a claim: the
145+
process must really be running `tensorfold-native` (or Python running
146+
TensorFold), checked against its executable (`lsof -d txt`,
147+
`/proc/<pid>/exe`), and it is read only at a loopback TCP socket it is
148+
listening on, matching its `--port` when it names one; `--host` is
149+
ignored, and without `lsof` nothing is read. The model and name come from
150+
the command line. Engines are merged with the registry by port and
151+
published as `source: "discovered"`. This is how TensorFold Studio's
152+
engine, which gets a new random port every launch, gets a card. Process
149153
environments are never read.
150154
- **Not on the heartbeat's path.** It reads on its own timer at the heartbeat
151155
interval; the beat publishes the last reading and never waits on a socket.
@@ -156,12 +160,13 @@ export INTENT_TENSORFOLD_DISCOVER=1 # default with a registry; 0 turns it off
156160
- **Which entries:** marked `"engine": "tensorfold"`, or auto-detected from
157161
their `/metrics`. See `config/models.README.md` in ide-agent-kit, including
158162
how a keyed server names its key.
159-
- **Keys come from files only.** A registry entry's `keyFile`, or the
160-
`--api-key-file` a discovered engine was started with, read in the engine's
161-
key-file format and refused when other users can read the file. TensorFold
162-
Studio keeps its engine key in memory and hands it to the engine through
163-
the environment, so its engine shows `metrics: "auth_required"`, the model
164-
from its command line, and the reason.
163+
- **Keys come from the registry only.** The `keyFile` of an entry marked
164+
`"engine": "tensorfold"`, read in the engine's key-file format and refused
165+
when other users can read the file. Never a command line, a key file a
166+
command line names, or an environment. TensorFold Studio keeps its engine
167+
key in memory and hands it to the engine through the environment, so its
168+
engine shows `metrics: "auth_required"`, the model from its command line,
169+
and the reason.
165170
- **TensorFold's default port is 8080, and so is `INTENT_MODEL_ENDPOINT`'s.**
166171
The served-model probe above may send one short generation request to a
167172
loopback endpoint to prove what is loaded. On a machine where TensorFold

‎packages/user-intent-kit/bin/uik-daemon.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@
7878
* waits on it.
7979
* INTENT_TENSORFOLD_DISCOVER 1 | 0. Find TensorFold engines running on this
8080
* machine from the process table (this user's
81-
* `tensorfold-native serve` / `tensorfold serve`;
82-
* port from --port, else the listening socket) and
83-
* publish them as source "discovered", merged with
84-
* the registry by port. Default: on when
81+
* `tensorfold-native serve` / `tensorfold serve`,
82+
* checked against the real executable, read only at
83+
* a loopback socket the process listens on, never
84+
* with a key from its command line) and publish them
85+
* as source "discovered", merged with the registry by
86+
* port. Default: on when
8587
* INTENT_TENSORFOLD_REGISTRY is set; set 1 to run it
8688
* with no registry at all, 0 to turn it off.
8789
* INTENT_TENSORFOLD_SCOPE local (default) | all. local = only entries on

0 commit comments

Comments
 (0)