You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 56fd426
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Discover running TensorFold engines, including TensorFold Studio's (#145)
* Discover running TensorFold engines for the device heartbeat
TensorFold Studio starts its own `tensorfold-native serve` on a new random
loopback port every launch, so no registry entry can name it and IAK could
not see it. The TensorFold status reader now also scans this user's
processes for `tensorfold-native serve` / `tensorfold serve` (one `ps -U
<uid> -o pid=,args=` on macOS, /proc on Linux with `comm` checked first,
no sudo), takes the port from --port or, when there is none, from the
listening socket via lsof, and the model and name from the command line.
Engines are merged with the registry by port (the entry keeps its id and
keyFile; an entry without an engine skips auto-detection) and published
as source "discovered". GET-only rules unchanged.
Keys come from files only: a registry keyFile, or the absolute
--api-key-file a discovered engine was started with, read in the
engine's own key-file format and refused when other users can read it.
Process environments and --api-key values on a command line are never
read or kept. TensorFold Studio makes a fresh key per launch, keeps it
in memory and passes it as TENSORFOLD_API_KEY (app/electron/agent/engine/
supervisor.ts), so its engine reports metrics "auth_required", with its
model taken from --name and labelled model_source "args".
On by default when INTENT_TENSORFOLD_REGISTRY is set;
INTENT_TENSORFOLD_DISCOVER=1 runs it without a registry, 0 (or
`tensorfold-status --no-discover`) turns it off. New payload fields:
name, app, model_source, memory.footprint_gb, top-level discovery
(ok / off / unavailable).
Tests: 15 new in test/tensorfold-discovery.test.mjs with ps, lsof and
GET fixtures recorded from the three engines running on this Mac
(Python 0.6.0, native 1.0.10, Studio), decoys, a fake /proc tree and a
keyed engine.
* 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>
---------
Co-authored-by: ThinkOffApp <233579950+ThinkOffApp@users.noreply.github.com>
Co-authored-by: Petrus Pennanen <petrus@example.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
## Unreleased
4
4
5
5
### 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), 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.
6
7
- **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.
7
8
- **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.
8
9
- **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.
Copy file name to clipboardExpand all lines: README.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -496,7 +496,9 @@ can show a card for it on each machine.
496
496
497
497
1. List the server in `config/models.json` with `"engine": "tensorfold"` (or
498
498
leave `engine` out and let it be auto-detected). See
499
-
`config/models.README.md`.
499
+
`config/models.README.md`. Engines running on this machine, including the
500
+
one TensorFold Studio starts on a random port, are found from the process
501
+
table without an entry.
500
502
2. Check what the card will say: `ide-agent-kit tensorfold-status` (add
501
503
`--json` for the exact object).
502
504
3. Turn it on for the publisher: set
@@ -505,7 +507,9 @@ can show a card for it on each machine.
505
507
506
508
It is read with GET requests only (`/health`, `/metrics`, `/v1/slide/graph`),
507
509
never a completion, and an unreachable server shows as unreachable instead of
508
-
stopping the heartbeat. 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
509
513
`packages/user-intent-kit/README.md`.
510
514
511
515
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.
0 commit comments