Skip to content

Hosted chats P0: run a chat on the organization's server (sessionhost, codeaf chat --org, model door) - #2896

Closed
AbirAbbas wants to merge 30 commits into
devfrom
w24/sessionhost
Closed

AbirAbbas wants to merge 30 commits into
devfrom
w24/sessionhost

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

DRAFT. Do not merge. Stacks on #2894 (w24/org-compose, head fb344e9ec): the first commits in this PR's list are that PR's, the commits after them are this one. Rebase onto dev once #2894 lands.

What this does

P0 of the hosted-chat design: one full codeaf chat (model, shell, git, a worktree) runs on a machine the organization keeps, and a person attaches to it from a thin client, codeaf chat --org <url>. It runs in a new sessionhost Compose service, behind the organization server. Everything is opt-in: with CODEAF_HOSTED_URL unset the organization server, codeaf chat, --host and --at behave as they did.

  • sessionhost (new, internal/sessionhost, codeaf sessionhost serve|probe|health): one Linux user and one 0700 folder per chat, commands fenced and refused (never run open) when no fence can be applied, five capabilities, no organization secret and no model key, per-person and per-host limits, stop/delete leave no process, state survives a restart.
  • Organization server (internal/factory/serve): /v1/hosted/sessions[...] proxies to the sessionhost with the shared secret and the verified person only (client identity headers are stripped); the wire is a reverse proxy that parses no frames. /v1/model/ is a model door: a chat reaches its model only with a bearer the server minted for that chat (twelve hours, ended on stop or delete), and the server adds the organization's key itself.
  • Client (cmd/codeaf/chatv3_org.go): the same surface as --at over a WebSocket, the bearer only in a header, plain-words refusals, no client tools advertised, nothing a frame says can make this computer write, run or open anything.
  • Deploy (deploy/org): the service, a hosted network shared only with codeaf, the local-binary build argument, setup.sh secret, SMOKE_HOSTED=1 ./smoke.sh, README "Hosted chats".
  • Manual page organization-hosted-sessions with probes.

Validation contract (written before the code) and where it stands

Live = SMOKE_HOSTED=1 ./smoke.sh on Docker Desktop (three services in their own Compose project: the organization server, the sessionhost on a different host, the scripted model stub; a Linux user per chat, Landlock fence). Go = the contract-named tests (TestC<n>_...) in internal/sessionhost, internal/factory/serve, internal/executor, internal/enginehost, cmd/codeaf.

Item Result Evidence
C1 run PASS Live: codeaf chat --org opens a chat; a scripted bash call runs git and a worktree there (?? f); the hostname is another container's than the organization server's; the chat's folder is /chats/people/<person>/<chat>/work and its user is 200000 or above; nothing was written where the client ran; a later message reaches the same chat and its files. Go: TestC1_*.
C2 isolation of what chats share PASS, one named gap Live (smoke.sh, uid+fence, Landlock ABI 7): another chat's file cannot be read, its folder written to or listed, its home read, it cannot be signalled, /proc/<pid>/fd is refused; the same person's other chat is refused too; the organization server's data folder is empty on the chats' machine; nothing planted reached a chat and its own file was intact (read as the chat's own user). Found open and closed here: before the fix a file one chat left in /dev/shm or /tmp was readable by another chat (umask 022), and another chat connected to an abstract Unix socket the first was listening on (both checked live on the previous build). Now: chats start with umask 077 (the file is refused), and a required fence scopes abstract sockets in Landlock (the connect is refused with EPERM, while a command's own abstract socket still works). Another chat's engine socket is refused (EACCES; the first chat connects to its own). Asked as the other chat's user by a plain script, not the engine's wording check: /proc/<pid>/environ EACCES, /proc/<pid>/mem EACCES, ptrace attach EPERM; the chat's own user can read its own environment, which is the control. Named gaps: for mem and ptrace this kernel's Yama setting refuses the same user too, so that answer is Yama's and the user rule's together (a different user needs CAP_SYS_PTRACE, which no chat has); /tmp and /dev/shm file names are listable by other chats (the contents are not); a chat can still open its own files up on purpose; on a kernel older than Linux 6.12 (Landlock ABI below 6) the machine starts no chats unless the operator chose CODEAF_SESSIONHOST_REQUIRE=uid. Go: TestC2_*.
C3 secrets PASS Live, read from the machine's side as each chat's user: the shared secret is in none of 276 files in the chats' folders, in no chat process's environment, and the processes a chat's shell started hold none of the organization's names and no OPENAI_API_KEY (the minted bearer is in the engine's environment only). Go: TestC3_* (environment is exactly an allow-list, credentials never touch disk, bearer lifecycle: revoked on stop).
C3b network PASS Live, from inside a chat: AgentField, the nodes, the model stub and the metadata address are closed; the sessionhost API answers 401 with no secret, the organization server 401 with no sign-in, the model door 401 with no bearer. (The organization server's port itself is open to a chat: it is the model door.)
C4 fail closed PASS Live: the probe measures uid+fence with Landlock; a container started without SETUID is not ok and starts no chat. Go: TestC4_* (forced probe failure answers a sentence and starts nothing; a required fence refuses when none can be applied; uid mode needs an explicit opt-in and warns).
C5 detach and resume PASS (after a fix found here) The first live run showed the turn dying with its client. Cause: the data folder /sessions put a chat's engine socket path at 104 bytes, one over the 103-byte ceiling, so the engine silently ran inside the connection's process. Fixed: the default folder is /chats and the sessionhost refuses to start with a folder that leaves no room (TestC5_*). Live: the client is killed 5 s into a 10 s command; 14 s later a reconnect shows the result and no cut-off tool call.
C6 restart PASS (cut-down) Live: after restarting the sessionhost no chat process is left, the volume survived, the owner's chats are still listed, files are intact and the person is back in the chat. The first attach after a restart can answer "This chat has no model access yet." and the next works (bearers are in memory; see limits). The in-flight turn across a restart is not resumed (P3, as the contract said). Go: TestC6_*.
C7 limits and cleanup PASS Live: a third chat can be made but cannot be started while two run ("You already have 2 chats running; stop one first."); stopping one frees the slot; stop leaves no process of that user, including one started with setsid, and does not touch the other chats; delete answers 404 afterwards. Go: TestC7_* (host-wide limit sentence, state derived from processes, kill reaches setsid descendants, the idle window). The idle window was watched live once, see Known limits.
C8 no change by default PASS TestC8_*: hosted is off when CODEAF_HOSTED_URL is empty and refused when half set; the fence is unchanged unless required; the existing tests in the touched packages pass untouched.
C9 plain words PASS Live: no banned word in any sentence a person read; Go: TestC9_*.
C10 attach authorisation PASS Live: another person's get, stop, delete and attach answer the same 404 as an unknown chat; a person-name header sent by a client changes nothing; no sign-in is refused. Go: TestC10_*.
C11 untrusted frames PASS Go: TestC11_* (a hostile frame makes the client write, run and open nothing; the surface has no banner raiser).

Approval path (driven live with tmux and the built client attached to a hosted chat). A fresh interactive hosted chat starts in the product's own default posture, YOLO (the engine's welcome says so and the status line shows it), so its first command runs without a card, inside the fence; that is the same default as a local chat. alt+a switches the chat to "asks" from the client. Then: a command shows the card "needs your ok to run bash" with allow once, always, deny; before approving, the file the command writes did not exist; approving ran it as the chat's user in its folder; denying left the file absent and the transcript reads "denied by the person". An interactive attach right after a --once run was NOT refused (the suspected execution-mode refusal did not occur): the conversation resumed and a command ran in it. Frames are kept with the lane notes. Not done: an operator setting that makes "asks" the default for every hosted chat (follow-up). In the first interactive run the client also drew a "calls are not being sealed ... Permission denied" notice that cleared by itself; it is not diagnosed.

CI gates run locally before the push: make test-quick (exit 0: build, vet, fmt, packed manual, change entries, manual gates, laws, help and belt-page tests), the light packages' tests, the named cmd/codeaf tests, and the windows and darwin builds of ./cmd/codeaf. Live: SMOKE_HOSTED_ONLY=1 ./smoke.sh end to end from a fresh stack with images built from the fixed code: 74 checks pass, 0 fail (SMOKE PASSED); then the hosted sections with the new C2 checks: 72 pass, 0 fail.

Deviations from the design (each deliberate)

  1. Five capabilities, not four: SETPCAP is needed to empty a chat's capability bounding set. The supervisor also narrows itself to the five at start.
  2. Kill-by-uid scans /proc and signals through pidfds (stop, re-check the uid, kill), instead of a real-uid-0 trick.
  3. A hosted engine ignores jail.allow: off: a chat's shell can write its own settings file, so honouring it would let one command remove the fence.
  4. A hosted Compose network, so a chat cannot reach AgentField, the nodes, the runner or the model stub. On Railway the private network is open, so the shared secret and the bearer are what protect.
  5. CODEAF_FENCE_REQUIRE and CODEAF_ENGINE_IDLE are new, read by the engine door only and only when set.
  6. The data folder is /chats, short on purpose (see C5): a socket path has a 103-byte ceiling and a chat's engine socket lives in its own home.
  7. Chats start with umask 077 and the fence scopes abstract Unix sockets (kernel 6.12 or newer; see C2).
  8. The image can take a locally built binary (CODEAF_BINARY_FROM=local) because the pinned release has no sessionhost yet; the default build is unchanged.

Known limits (not hidden)

  • Minted bearers are in the server's memory: a restart of the organization server (or a chat older than twelve hours) loses model access until the next attach mints a new one.
  • A chat's own shell can read its own engine's environment (its own scoped bearer).
  • A turn started by --once has nobody at a keyboard to approve a command, so under the default policy its first command is refused, as for a local codeaf chat --once. The smoke seeds one settings row for its test chats; an operator knob for unattended hosted chats is a follow-up.
  • Idle engines do exit (watched live: the engine of a quiet chat was gone about 30 s after its last use with a 20 s window), but a chat whose engine started a furrow serve storage helper keeps that helper running as the chat's user, reparented to init, after the engine is gone; the sessionhost counts a chat as running while it has any process, so such a chat holds one of its person's slots until it is stopped (stop kills it; the smoke's stop-frees-the-slot check passes). Whether the helper should exit with the engine is a follow-up for whoever owns furrow's lifecycle.
  • Egress is unrestricted; the volume is not encrypted; root on the host reads every chat. The manual page says so.

Not run here

make pr-ready and the full cmd/codeaf, tui3, session suites were not run on the laptop (CI's legs carry them). No Railway deployment was made: the Railway step was optional and was not reached; the sessionhost service for it is described in deploy/org/README.md, and codeaf sessionhost probe in that service is what says whether the fence works there.

🤖 Generated with Claude Code

AbirAbbas and others added 30 commits November 24, 2026 00:00
…WE-AF and PR-AF

Each image runs a pinned artifact: codeaf from a published dev release checked against its
sha256, the AgentField control plane from its published image (built with sqlite_fts5) pinned
by digest, SWE-AF and PR-AF built from pinned commits of their public repositories. The
containers start as root only long enough to give a platform volume to the service's user,
then run as that user. The runner is the engine host that registers the factory on AgentField.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Railway's builder rejects a cache mount that has no id, and an id has to be
spelled with the service it belongs to, which no portable Dockerfile can know.
The two Go reasoners build in about a minute without the cache, so they build
the same way under Compose and on Railway.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
One `docker compose up` runs the organization server, the AgentField control plane, the factory
runner, SWE-AF and PR-AF, each with a volume for its state, a health check, and a published port only
where a person has to reach it (on 127.0.0.1 unless the operator opens it). The scripted stub model is
an optional profile for a keyless smoke test. setup.sh writes .env with fresh random secrets and never
overwrites one; .env, the model keys and the organization token never enter an image.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The control plane's health check used a glibc busybox that the distroless base is too old to run, so it
is now the static musl one. The reasoner images now name the user they run as, so a platform volume is
handed to the right user and git finds its home (PR-AF was looking in SWE-AF's). The node entrypoint can
make a throwaway repository for the keyless smoke test to plan against.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
smoke.sh starts the stack against the scripted stub model and checks, section by section, that the nodes
are registered, the operator link claims the organization, a second person joins by invite, a factory
job reaches SWE-AF through AgentField with strict run-owner proofs and its plan question is answered by
the owner, and that a restart of every service keeps the people, the runs and the registrations.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…point and never uses a fixed password

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…away, then runs unprivileged

The published image is distroless and runs as uid 65532, so a root-owned platform volume left it unable to
write its database, and the only way round was to run it as root. It now gets the same hand-off as the other
images, done with the one busybox binary it already carries for its health check.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…nt the Railway services

A link is only accepted with exactly the address the server names itself by, so rewriting the host in
the printed link broke it. The README now says what that address is on a laptop, and lists the variables
each Railway service takes.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ontainer stub, not a send path

deploy/org/modelstub answers /chat/completions on purpose so the keyless smoke test spends nothing; like test/remote/stub
it is built into its own image and the product never runs it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…f running open

A fence that can apply nothing used to let the command run as it was. A Require fence
returns ErrFenceRequired instead, in a sentence with none of the machine's words, so a
hosted chat's commands are confined or not run, never run open. Without Require nothing
changes, and the helper's spec is byte-identical.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…LE shortens the idle windows

Both are read only by the engine door and only when set, so an engine started without them
is what it was. A hosted engine builds its own fence, which ignores jail.allow: off, because
a chat's own shell can write that file.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…folder per chat

codeaf sessionhost serve|probe|health, plus the hidden helpers it re-executes as the chat's
user. The supervisor keeps five capabilities, fails closed when it cannot switch users or
confine commands, and answers its API only to the organization server's shared secret and a
named person.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…door a chat reaches its model through

/v1/hosted/sessions[/...] proxies to the sessionhost with the shared secret and the verified
person only; the wire is a reverse proxy that parses no frames. /v1/model/ takes a bearer the
server minted for one chat (twelve hours, ended on stop or delete) and adds the organization's
key itself. With CODEAF_HOSTED_URL unset neither exists and every path answers as before.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The thin client: the same surface as --at over a WebSocket to the organization server, the
bearer only in a header, a chat picked or made for the person, plain sentences for every
refusal. It advertises no client tools and drops the automation banner raiser, so nothing an
engine sends makes this computer write a file, run a program or open an address.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… people ask them

Where the chat runs, what stays on a person's computer, who can see a hosted chat, what the
operator of the machine can see, what happens when the person disconnects, the limits and the
refusal sentences, and how an operator turns it on. Probes in chat_hosted_test.go keep the
questions reaching the page.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A supervisor that chooses the folders other people's homes live in needs to know,
before it makes one, whether an engine host can listen there. The helper returns the
longest path a host socket can have under a codeaf home, and a test pins it to the
length of the socket a real host listens on.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…t (C5)

The first live run showed a chat's turn dying with its client. The engine keeps working
after a disconnect only as a host behind a unix socket in the chat's own home, and with
the data folder at /sessions that socket's path was 104 bytes, one over the 103-byte
ceiling, so the engine quietly ran inside the connection's process instead and nothing
said so. The default folder is now /chats, and the supervisor refuses to start with a
folder that leaves no room, naming how many characters there are.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ke test needs no key

A user message starting "bash:" makes the stub ask for one bash tool call with the rest of the
message, and the tool's answer comes back quoted as "STUB ran: <output>". Any other message is
answered "STUB noted: <message>" as before, so the existing smoke test is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ke test that proves them

A `hosted` Compose profile adds the sessionhost (five capabilities, a volume at /chats, a network shared only with
the organization server, a healthcheck), the local-binary build argument for an image that has `codeaf sessionhost`
before a release does, the shared secret in setup.sh, and README "Hosted chats". `SMOKE_HOSTED=1 ./smoke.sh` drives
real `codeaf chat --org` clients against the scripted model stub and checks, by contract item: a chat runs on another
machine in a folder of its own, other chats cannot read, write, list or signal it, no secret reaches a chat, a
machine that cannot isolate refuses, a turn finishes after its client is killed, the host restarts without orphans
or lost files, limits and cleanup, and that another person's chat cannot be told from one that never existed.

The checks of what a chat's user can see are made as that user (the machine's root holds no right to look inside a
chat), and what a chat's shell holds in its environment is read from the machine's side, because the engine rightly
refuses a command that searches for secrets.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… the fit check

The test asked SocketPath for the real path, and SocketPath refuses a state root that is too
long for a socket, which a CI runner's temporary folder is. The test passed on a short /tmp and
failed there. It now measures the same path through the unexported where and socketName.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…where the kernel cannot

Abstract Unix sockets have no owner and no file mode, so every process in one network
namespace can connect to every other's, and the hosted chats on one machine share that
namespace. A live check showed one chat connecting to a socket another chat was listening on.
A required fence (the hosted engine's) now asks Landlock to scope them, so a command cannot
connect to an abstract socket made outside its own fence, and where the kernel is older than
Landlock ABI 6 the command is refused instead of run with the gap. A fence nobody required
keeps the ruleset it always had.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…pe local sockets starts none

/tmp and /dev/shm are one folder for every chat on the machine, and a file made there with the
usual umask 022 was readable by every other chat (checked live). Chat processes now start with
077. The probe also refuses fenced mode where Landlock is older than ABI 6, because abstract
Unix sockets belong to no user and only the fence can keep chats from each other's; an
operator who accepts that says so with CODEAF_SESSIONHOST_REQUIRE=uid.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…folders and local sockets

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ct sockets, the engine socket, process internals)

Each is checked with a control that shows the check can pass: a chat's own abstract socket and its
own engine socket work from inside the chat, and the chat's own user can read its own process's
environment. The kernel answers for another chat's user are asked by a plain script running as that
user, so the engine's own wording check is not what refuses. README says what the fence now needs
(Linux 6.12 or newer) and that chats start with umask 077.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@AbirAbbas

Copy link
Copy Markdown
Collaborator Author

Consolidated into #2903, the org/main feature line. This PR's commits are all on that branch. Closing it here so there is one place to review. Follow-ups go against org/main.

@AbirAbbas AbirAbbas closed this Nov 24, 2026
AbirAbbas added a commit that referenced this pull request Nov 25, 2026
…ack (#2903)

The hosted organisation line: a team-mode org server deciding every request through one access model (verbs, roles, grants and policy in SQLite), hosted chats run by the sessionhost under a per-chat uid inside a Landlock fence with minted model bearers, sealed keys and a git helper, shared chats acting through verbs, bots owned by their creator, the Hosting and chats policy settings, and a self-hosting stack (deploy/org Docker Compose, published images behind a leak gate, a Railway path).

Consolidates #2894 #2895 #2896 #2898 #2899 #2900 and the follow-ups #2904 #2905 #2907 #2908 #2910 #2911 #2912 #2913 #2915 #2916 #2918 #2927 #2936 #2944. Proven by the full suite, a keyless Compose smoke, a hostile wire client, sandbox escape probes, a real-model run and a production-style install from the published images.

Co-Authored-By: Santosh kumar <[email protected]>
Co-Authored-By: ZeroPoint95 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant