Skip to content

Latest commit

 

History

History
195 lines (153 loc) · 10.1 KB

app-server-protocol.md

File metadata and controls

195 lines (153 loc) · 10.1 KB

App Server Protocol

Concept

Technical depth: Protocol contract, records and limits.

The experimental session protocol lets a program in any language drive a Loopex session over a byte stream: create or resume a session, attach at a durable cursor, submit prompts and other commands, answer a host policy's questions, select project skills, read artifacts back in verified chunks, and receive committed events and transient progress. It is one JSON object per line, spoken by two servers:

  • The app server (loopex_app_server) is a foreground process that serves one connection over its standard input and output and speaks generation loopex.experimental/3.
  • The daemon (loopex_daemon) is a long-lived host that serves many connections over a Unix-domain socket and speaks generation loopex.experimental/4: the foreground methods plus session listing, daemon status, and controller leases. See the daemon.

This pair documents the protocol both servers speak in the current source (v0.4.0); accepted ADRs govern its contracts. The founding decision is accepted ADR 0023; the daemon's additions rest on ADR 0032 and ADR 0033. The current generation replacement is owned by ADR 0044, with closed creation options, compaction activity, creation cancellation and owned artifact opening. An independent consumer written in plain JavaScript lives in clients/node, and the operator's view is in App server operations.

One Contract, Not a Second Loop

The non-negotiable is session before surface. The runtime is headless; the command, IDE, daemon, web, and embedded callers are peers over one semantic contract, and no surface owns an alternate loop or an alternate durable truth.

So a server maps wire requests onto the same runtime operations a host already calls. The app server's Loopex.AppServer.Mapping and the daemon's connection process translate and validate; they do not decide, do not hold session state the coordinator owns, and do not reach a coordinator or a Store directly. A method that needed to would be a design error, not a mapping problem.

A client can author session creation options and change supported session configuration between settled runs. The host still chooses runtime composition, provider routes, credentials, available tool definitions, policy and maintenance settings. A frame cannot replace those launch inputs or turn an identity into a grant. Configuration commits its effective public view, while raw instructions and private provider data stay outside public records.

The foreground generation has eighteen methods after initialization; the daemon generation has twenty-two. Both include configure, standalone compact and the closed choice/text/declined answer union. An admission reply means a command was accepted and journaled, never that the run has completed; completion arrives as committed events.

Technical depth: The methods.

Experimental Is in the Name on Purpose

The word experimental is part of each generation string. A client cannot read it as a released contract and no version comparison can round it up to one.

Generation selection is exact. A client offers an ordered list, the server picks one it knows, and there is no partial match and no nearest neighbour. A client offering only an unknown generation is refused rather than served something close. The initialized reply reports the selected generation and a digest of the exact schema, so a client verifies the contract it is about to speak rather than assuming it.

Public compatibility in this repository is behavioural and requires schemas, vectors, independent consumers, migrations, and upgrade evidence. The current source pins each complete payload manifest and its independent consumer. Before 1.0, clients and servers move together to the current contract; old-only and wrong-server offers refuse, with no compatibility fallback. Serving changes only with the complete coordinated generation. See Compatibility surfaces.

Technical depth: Generation and negotiation.

Strictness Is the Feature

Framing and decoding refuse where a lenient parser would repair:

  • one JSON object per line, LF only — a carriage return is a protocol error, not something to strip;
  • duplicate object members are refused, not collapsed to the last;
  • a float where an integer belongs is refused, not rounded;
  • trailing bytes after a complete value are refused; and
  • control characters inside strings are refused.

A client that is lenient about framing will not notice a server that is. The refusals are what an independent implementation checks itself against, and the conformance vectors assert that their reasons are distinct — an implementation collapsing a duplicate member, an unrepresentable integer, a trailing byte, and a lone surrogate into one error fails.

The decoder is written without a JSON library, because the contract application that holds it carries no dependency at all, and because a general decoder does not refuse duplicates, bound depth while parsing, or keep keys from being interned.

Technical depth: Framing and decoding.

Two Delivery Planes, Bounded Separately

A client receives two kinds of unsolicited record, and conflating them would be a correctness bug rather than a cosmetic one.

Durable events are history. They advance a client's cursor, and losing one silently would leave that client's view permanently wrong. When the queue overflows, the client is detached at its cursor, so it can reattach and replay.

Progress is a rendering aid. It advances nothing, and when its queue overflows it is dropped, because losing it costs only smoothness.

That difference is why the two have separate, differently sized queues rather than one shared budget.

Technical depth: Exact limits.

Verified artifacts and truthful cleanup

An artifact open names the literal use locator retained by a real tool result. The connection's actual attachment supplies the session binding. The server verifies the use and complete object before adopting a bounded snapshot reader; a client cannot select a path, inject provenance or nominate an object instead.

Opening and cleanup have separate clocks. An admitted opening refusal reports its reason and whether original custody cleanup was proved. An unproved result keeps capacity occupied until actual original proof permits reclamation. Late cleanup never rewrites the earlier refusal into timely success. Payload work, metadata work and later reads all count against the actual connection's budget; private receipts and work records stay off the wire.

Technical depth: Artifact requests, refusal branches and custody.

Foreground, Not a Daemon

The app server owns no session residency. Its loss is an ordinary host loss: the durable session stays where it was. There is no socket, no background lifetime, and no takeover between clients. A connection holds at most one attachment: a second session.attach on it is refused attachment_conflict unless it sets replace, which replaces the connection's own attachment.

Ending input is not cancelling. Clean EOF and abrupt death both leave a pending interaction pending; session.abort is the explicit session cancellation command. Connection cleanup retires its own holders and artifact readers without inventing a durable session cancellation. The input owner remains responsive while one request worker calls the runtime and an independent output writer owns physical stdout completion.

Technical depth: The transport process.

What the Daemon's Generation Adds

The daemon generation keeps the foreground framing, records, codes and limits, and adds what several clients sharing one daemon need. A client can list the sessions a root holds and ask for the daemon's status. Any number of connections may observe a session, but only the connection holding the session's controller lease may change it: a client acquires control, receives a writer epoch, presents that epoch on every mutation of an existing session, including configure and compact, and renews the lease before its term lapses. Takeover waits for the holder to release or for the lease to lapse; nothing forces a live holder off. The daemon can also tell every client it is stopping, and why.

Technical depth: The daemon's generation.

Related

Back to the developer index.