Skip to content

Organization server follow-ups: private chats, paged remote read, loopback trust and bots - #2895

Closed
AbirAbbas wants to merge 11 commits into
devfrom
w24/org-follow
Closed

AbirAbbas wants to merge 11 commits into
devfrom
w24/org-follow

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups to #2890 from the 2026-11-24 calls on the organization server. Draft; do not merge.

  1. Chats are private by default, through the one decider. The policy already registered new chats private. What did not honour it was the list: every person who could see a workstream was shown every other person's chat title, owner, state and last-activity time. GET /v1/workstreams/{id}/chats now asks can(viewer, chat, view) for each chat, so a private chat is hidden from the workstream and from the operator, and a chat shared with someone is listed to its owner and the people it is shared with alone. Writing the contract test found a hole in the decider: a private chat's first grant un-privated it, after which it inherited the workstream's shares, the workstream's grants and the operator. It is now a closed private item (acl.Item.Closed): only the grants on the chat itself reach it. The audience of its events names the same people.
  2. The chunk-paged remote chats.read {cell, before?, limit?} is back, additively and under its own hello word chats.read.paged. Dev's chats.read word keeps its meaning (agents.entries follows a saved remote head) and its tests are unchanged. The answer carries sealed_at_ms and fetched_bytes; a page fetches only the transcript's own objects and the chunks under it; a read takes no lease and runs no agent. The furrow pin moves to v0.3.7 for the verbs the read needs.
  3. No implicit machine owner, and bots.
    • New host-config key loopback_trust. Unset: on for a solo factory, off for a team factory, where a credential-free request from the server's own computer is now a 401 like one from any other machine. The forwarded-header rule holds whatever the key says (tests: unlisted and listed proxy with a remote client, Forwarded only, X-Real-Ip alone, garbage headers, both IPv6 loopback forms).
    • A person can make a bot (a name, optionally a narrower role) and gets its cbt_ token once; the store keeps only its sha256. A bot acts with its creator's rights right now (nothing cached), intersected with the policy's scope for bot:<id> and its own role, through the existing on-behalf-of evaluator with the creator as sponsor. What it creates is owned by its creator and recorded as created by the bot. Revoking a token, removing a bot, or removing the creator from the organization ends it on the next request. Bots are default-deny with a route allowlist and cannot start an agent run, make bots, mint tokens or use operator routes.
    • Registering a runner follows the same setting. With loopback_trust off (a team factory by default) a runner needs a runner credential even from the server's own computer: the host's access token or a signed-in person's session, the ones a remote runner already uses. The factory's own person no longer stands in for a runner that names no handle. Solo, and a team factory that sets loopback_trust: true, are unchanged; a bot token is still refused there.
    • Wire: factory.org_bots, factory.org_bot_new, factory.org_bot_token_new, factory.org_bot_token_revoke, factory.org_bot_remove, hello word org_bots; PROTOCOL.md names them.
  4. Manual pages (organization-sharing.md, factory.md, my-space.md, workstream-chats-and-tools.md) and probes for bots and the loopback setting.

Validation Contract

  • A. A chat that person P keeps in a shared workstream is private: another member, and the operator, get others: [] for it (no title, owner, state or time); P's own list is unchanged; a grant on the chat lists it to that person alone and removing or lapsing the grant takes it away; a chat in My space is never listed to anyone else; the policy default for chats can be changed and applies to chats made after the change only; creating a private chat emits no resource.changed; a chat folder with no registry row is never listed; a private chat moved from My space into a workstream stays private.
  • B. chats.read hello word unchanged; chats.read.paged advertised only by an engine that can read one file of a relayed snapshot; a page is newest first with a cursor, sealed_at_ms and fetched_bytes; later pages and a later take do not refetch; a read takes no lease; without the capability the call is refused in words.
  • C. Team mode with no setting refuses a credential-free request from the server's own computer on every person route, runner registration included (it takes the host's access token or a signed-in person's session, and a handle); solo mode and loopback_trust: true do not; a forwarding header never makes a request local unless a trusted proxy names a loopback client. A bot's verbs on an item are at most its creator's current verbs; the creator losing a share takes it from the bot on the next request; a deleted scope role means no verbs; tokens are shown once and never listed; revoke, removal and the creator's removal end the bot with words; an unresolved cbt_ token never falls through to loopback; a bot cannot reach a route that is not on the allowlist.

Contract changes against #2890's tests

Each is a stated behaviour change, not a reshaped test, and carries a comment saying so: the operator's chat list, the chat-move event audience and the lapse-event audience no longer include the operator or the destination's people for a chat shared with one person (A); the others-list assertions in myspace_test.go and access_move_chat_test.go (A); ten test fixtures that acted as the host's person on a team-mode handler with no credential now set LoopbackTrust explicitly, and one sends the discovery token (C). Two worker test fixtures that attached a runner to a team-mode handler with no credential also opt in explicitly, and the factory command test now checks that a credential-free attach is 401 and attaches with the discovery token (C12).

Test evidence

  • make test-quick: clean, including GOOS=windows go vet ./... and the manual gates; windows/amd64 and darwin/arm64 builds of the touched packages.
  • Whole internal/factory/... tree, including serve (271 s) and factorytest (384 s); internal/appwire, internal/manual; cmd/codeaf run for the Factory and Runner tests and the config and loopback tests; item B's cellstore, cellsync and syncsetup with furrow embedded through make.
  • Hand smoke of the built bin/codeaf factory serve in team mode with a second person in a throwaway home: loopback and X-Forwarded-For requests with no credential are 401; the second person lists 0 other chats until the owner shares one, then 1; a bot token acts within its creator's rights, is cut when the creator's share is removed, a chat it makes is its creator's and private; revoking a token and removing the creator end the bots; loopback_trust: true opens the local door and a forwarded request is still refused.
  • Not run on the laptop, on purpose: make pr-ready, full internal/tui3, internal/session and cmd/codeaf. CI covers them. One local failure is environmental and in a package this branch does not touch: internal/factory/agentfield TestTheClientRefusesAWrongKeyInWords (an unreachable local port answers "did not answer in time").

Open decisions

  1. Settled: the paged method keeps the name chats.read, as the reader Organization server: access model phase 2, run-owner proof, one chats.read #2890 removed, because the desk calls it by that name. Dev's hello word of that name means something else, and chats.read.paged is the word that says the paged reader exists; PROTOCOL.md says in one sentence that the method and the older word are different things.
  2. A bot cannot start an agent run: a run takes the creator's rights narrowed by Afi's scope and would drop the bot's own narrowing. Carrying two scopes into a run is a follow-up.
  3. Settled: worker attach follows loopback_trust (no implicit machine owner). The runner credential is the one a remote runner already uses, so nothing new was invented. A runner that is joined to a team server from the server's own computer now has to send the host's access token (codeaf runner join <url> --token ...) or a person's session, or the host sets loopback_trust: true.
  4. The desk (Agent-Field/codeaf-desk) is not edited. Its callers that must change to use the paged read, gated on chats.read.paged, are listed in the lane notes (Rust: relay.rs, lib.rs; TypeScript: backend.ts, remoteChats.ts, RemoteChats.tsx, RemoteTranscript.tsx, engineModel.ts, remoteChatsModel.ts, the mount tests and backend.settingsWrites.test.ts).

🤖 Generated with Claude Code

AbirAbbas and others added 11 commits November 23, 2026 23:59
A chat is private by default (the policy's default for the kind, and what
backfill registered), but GET /v1/workstreams/{id}/chats listed every other
person's chat title, owner, state and last activity to anyone who could see the
workstream (v2 ruling C10), whatever the chat's own visibility. Abir's call of
2026-11-24: chats are private by default, and a private chat is hidden from
shared lists. The list now asks the one decider whether the viewer may view each
chat, so only the owner and the people it is shared with see a private one; the
operator sees nothing private; a chat with no registry row is hidden.

An organization that wants the old listing sets the policy's default for chats
to owner or org; it applies to chats made after the change.

CONTRACT CHANGE: two tests asserted the old listing (the C10 block of
TestMySpaceChatsRunOnTheServerAndStayPrivate and
TestContractI9SharedWorkstreamChatListKeepsOnlyMetadata); they now assert that
the chat is hidden until shared, then listed with metadata only. The new
TestContractA* tests are derived from the lane's validation contract.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#2890 dropped santosh/work's chats.read method (#2650) because dev's
agents.entries already follows a saved remote head under the chats.read hello
word. Abir's call of 2026-11-24: nothing Santosh added is dropped. The two are
different abilities: dev's reader fetches the whole saved transcript, this one
fetches only the transcript's own objects and the chunks under one page, into
the store a later agents.take uses.

Restored from the parent of cc9ca26 (the chunk-paged reader in cellsync and
cellstore, the furrow path verbs, syncsetup.ReadChatPage, the engine method and
its tests), additively: the method is advertised under a NEW hello word,
chats.read.paged, and the chats.read word keeps exactly the meaning it has on
dev, so a client can tell which ability an engine has. agents.entries and its
tests are untouched. The embedded furrow is v0.3.7 again (it adds the path
verbs; its checksums match the release's SHA256SUMS); without them the word is
absent from hello, not present and failing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…it was shared with

Sharing a private chat with one person used to un-private it, after which it
inherited the workstream's shares and grants, the workstream owner's share and
the operator. So sharing a chat with one person showed it, title and all, to
everyone who could see the workstream. A private registration with a live grant
on itself is now a closed private item: shares, organization visibility, inherited
grants and the operator (unless the policy lets it see private things) stay out,
and only its owner and the people its own grants name reach it. The grants list
shows those grants and the audience of its events names the same people.

Three older tests encoded the wider audience (the operator's chat list, the move
event's audience, the sweep's lapse audience) and are changed to the contract,
each with a comment saying so.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A request from 127.0.0.1 with no credential used to act as the factory's owner on
every factory, so on a team server any program on the same machine, or any
same-machine proxy that did not add a forwarding header, was the owner. The host
config now has a `loopback_trust` key (true or false). Unset, it is on for a solo
factory, which is one person at one computer, and off for a team factory: a
credential-free local request is refused like one from any other machine, and one
with a token or a session acts as that identity. A team factory used by one
person at one computer can set it to true and gets the old behaviour back.

The forwarded-header rule holds whatever the key says: a request carrying
X-Forwarded-For, Forwarded, X-Real-Ip or X-Forwarded-Proto (even with an empty
value) is not local unless a listed proxy names a loopback client in
X-Forwarded-For. Tests cover an unlisted and a listed proxy with a remote client,
a Forwarded-only request, X-Real-Ip alone, garbage forwarding headers, and both
IPv6 loopback forms.

Worker attach keeps its own local door (as it had), so a runner on this machine
can still attach before its person signs in. Test fixtures that act as the host's
person on a team-mode handler now say so with an explicit LoopbackTrust.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… their creator

A person can make a bot (a name and, optionally, a narrower role) and gets its
`cbt_` token once, in that answer. The store keeps the sha256 of the token with
an eight-character hint and a last-used time, at most three live tokens per bot
and twenty bots per person. A request with a bot token acts as the bot: the
creator's verbs on the item right now, intersected with the organization policy's
scope for `bot:<id>` and with the role the person gave the bot, through the same
on-behalf-of evaluator Afi uses, with the creator as sponsor. Nothing is cached,
so a creator who loses a share takes it from the bot on its next request, and a
role that is later deleted means no verbs.

What a bot creates is owned by its creator and recorded as created by the bot
(kind `bot`, its id, the creator as sponsor); a chat it makes is private like any
other chat. Revoking a token, removing a bot, or the operator removing the creator
from the organization ends the credential on the next request with words that say
which; an unrecognised `cbt_` token is a 401 and never falls through to loopback
or the host's identity, and a bot token beside a session cookie is refused.

Bots are default-deny. A bot reaches workstreams and what is under them (except
the agent door, requests, drivers, jobs and imports), canvases, resources, My
space, and the policy, member, team and about reads. Everything else answers "a
bot cannot use this yet", and a bot cannot start an agent run. A bot cannot make
bots, mint or revoke tokens, or use the operator's routes. A person lists, mints
for, revokes and removes only their own bots; the operator lists every bot and may
remove any, but cannot mint a token for another person's bot.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
factory.org_bots, factory.org_bot_new, factory.org_bot_token_new,
factory.org_bot_token_revoke and factory.org_bot_remove follow the org_access
pattern: one fixed request each, with checked path segments, advertised only by an
engine that can reach an organization server. The minting answers carry the secret
once; nothing logs a request or reply body on this path. PROTOCOL.md names every
method and says the secret is shown once.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…isted to a workstream

The chat manual now says what bots are and are not (a token shown once, never more
than the person who made it, default-deny routes, no agent runs, ended with the
creator), what loopback_trust does and why a forwarded request is never local, and
adds probes in people's own words for both.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Five tests drove a team-mode factory with no credential from the same computer and
relied on the old rule that such a request is the owner. They now say it with an
explicit loopback trust (a plan-revision handler, a team publish and a worker
fixture, the worker reply fixture), or, where the point is how a local client
reaches its factory, send the token from the discovery file as every client does
(the factory command test).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Says what was true and what is true now for private chats, the shared-chat audience,
the paged remote read, loopback trust on a team server and bots, including the
sentence in the #2890 entry that is no longer true.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A team factory with loopback_trust off (its default) no longer lets a process
on the server's own computer attach a runner with no credential. A runner
presents what a remote runner already uses: the host's access token, or a
signed-in person's session. It names its handle unless its session does, and
the factory's own person no longer stands in for one that names none. A solo
factory and a team factory that sets loopback_trust are unchanged, and the
app's private listener keeps its host token as the credential.

Contract item C12 and its table test, the manual line, the PROTOCOL.md
paragraph and the change entry go in the same commit. Three fixtures that
attached with no credential to a team handler now say so (two opt in, the
factory command test checks the 401 and attaches with the discovery token).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The paged remote reader keeps the method name chats.read, which the desk
calls it by, and advertises itself under the hello word chats.read.paged.
Dev's older chats.read word only says agents.entries follows a saved remote
head. One sentence in PROTOCOL.md says so.

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