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 22cd258
Browse filesBrowse the repository at this point in the historyBrowse files
feat(gateway): relayed bodies travel on byte channels (#570)
Closes#558
### Status
Implement: done (1198 green) Review: round 2, clean; 2 text fixes
unreviewed Hardware: n/a Gate: waiting for the stack
## Done when
- [x] Every Tests line passes (`src/daemon`, `src/gateway`, `src/link`,
`src/contract` unit files green on the head; CI checked).
## Assumptions
- Assumption: where the spec says the startup tests are "modelled on
`server.test.ts:1241`", they live in `src/daemon/server.test.ts` as a
new `describe`, using the existing `createHarness` (given a
`relayTargets` option) with a link pair on the uplink, and the fake
clock of the link pair for the 60 s wait — the smallest change that
reuses the harness.
- Assumption: the protocol bump is tested as 34 (33 plus one) in the
existing protocol-range tests, with 33 added to the list of previous
versions the daemon refuses.
- Assumption: `relayChannelSchema` is a placeholder (`z.string()`) in
`src/contract/relay.ts` so the red tests compile; green gives it the
1–32 `[A-Za-z0-9-]` bound.
- Assumption: a request that reaches an uplink before `start()` has
claimed its socket parks on a gate that follows convergence — the
startup tests send a relay in that window, and the conservative option
is to park every non-`status.get` call there, as it already does after
the claim.
- Assumption: `src/daemon/relay.test.ts` (not named in F17) only changes
how it builds its arguments: `relay.request` takes the accepted channel
and the push has no `chunk`.
- Assumption: the daemon test helpers `settle` and `readAll` are renamed
`settleWithin` and `readParts`, so they do not repeat the link's exports
(Fallow `duplicate-export`).
## Review
Spec review: 7 blocking, 7 fixed, 0 notes. Code review: 5 blocking, 5
fixed, 0 notes. Claims review: 3 blocking, 3 fixed, 0 notes.
Rounds: 2. Tokens: 9.6M.
Fixed unreviewed: server.test.ts:1516 channel-before-parking assertion;
COMPONENTS.md:45 Relay targets row.
*Written by an agent.*
Copy file name to clipboardExpand all lines: docs/internal/COMPONENTS.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,8 +41,8 @@ rule 14); a single-file component's surface is what the file exports.
41
41
|`DaemonEndpointHost`|`src/daemon/connection-host.ts`| Claiming the socket, recovering a stale entry, the listener lifecycle. | Anything after a connection is accepted. |
42
42
|`AdminSecretManager`, session resolver |`src/daemon/admin-secret.ts`, `src/daemon/session.ts`| The per-start admin secret, its hash and persistence; turning a credential into `{ principal, role }`. | Decide what a role may do. |
43
43
|`GatewayUplink`|`src/daemon/gateway-uplink.ts`| When a worker dials its gateway: one outbound connection, redialled with backoff, handed to `DaemonServer`. | What travels over the link. |
44
-
| Link module |`src/link/` (surface: `index.ts`) | Wrapping one uplink transport connection (ADR 0028 §1-3): text messages passed through unchanged and ahead of bulk bytes, byte channels with credit, the envelope, the two-lane scheduler and the channel rules, the 64 channel limit and the waits it bounds (30 s accept, 60 s credit). Nothing uses it yet; #558 wraps the uplink with it. | Know what a channel carries, or touch a socket (the transport port does). |
45
-
| Relay targets |`src/daemon/relay.ts`| A worker's `relayTargets` (capability name to a function that takes a `Request`, a tenant and a lease id and answers a `Response`), and per uplink connection the relays it carries: the request body fed by `relay.body`, the response sent as `relay-head` and `relay-chunk` pushes, cancel and abort on close. Nothing registers a target yet. | Name a target: the core knows none; modules register through the option. |
44
+
| Link module |`src/link/` (surface: `index.ts`) | Wrapping one uplink transport connection (ADR 0028 §1-3): text messages passed through unchanged and ahead of bulk bytes, byte channels with credit, the envelope, the two-lane scheduler and the channel rules, the 64 channel limit and the waits it bounds (30 s accept, 60 s credit). Both uplink ends (the worker's and the gateway's) wrap their connection with it. | Know what a channel carries, or touch a socket (the transport port does). |
45
+
| Relay targets |`src/daemon/relay.ts`| A worker's `relayTargets` (capability name to a function that takes a `Request`, a tenant and a lease id and answers a `Response`), and per uplink connection the relays it carries: the request body read from the relay's byte channel, the head sent as a `relay-head`push and the response body written to the channel, cancel and abort on close. `src/daemon/main.ts` registers the `agent-device`target through the option. | Name a target: the core knows none; modules register through the option. |
46
46
|`OwnerRoutedFactBus`|`src/daemon/owner-routed-facts.ts`| Re-emitting lease-scoped facts with the lease's owner attached, for pushes and HTTP notices. | Emit a business fact of its own. |
47
47
48
48
## Core: device management
@@ -156,7 +156,7 @@ typed against and catalog matching (ARCHITECTURE.md, "Boundaries").
156
156
| Routing |`src/gateway/routing.ts`, `src/gateway/routing/` (surface: `index.ts`) | The pure routing policy: an ordered list of stages (`takes-requests`, `can-serve`, `healthy`, `idle-queue`, `warm-hit`, `free-slot`, `ram-budget`, `free-capacity`) over worker views, selected by `gateway.routing`; a physical request skips the stages whose `appliesToPhysical` is `false` (`idle-queue`, `free-slot`, `ram-budget`, `free-capacity`) and matches the enrolled physical devices in each worker's view (`physicalMatch`). | Read anything but views; order stages from config. |
157
157
|`GatewayDispatcher`|`src/gateway/dispatcher.ts`| The second implementation of the contract's handlers (ADR 0005 §32): answered from the fleet, forwarded to one worker, or fanned out to all. | Define a second contract or role check. |
158
158
| Aggregate, component relay |`src/gateway/aggregate.ts`, `src/gateway/component-relay.ts`| The fleet expressed in one machine's shapes, as pure functions over views; asking every worker to install a component and collecting one outcome each. | Decide anything a worker decides. |
159
-
|`GatewayRelay`|`src/gateway/relay.ts`| Handing one HTTP exchange to a relay target on a worker over its uplink (ADR 0026): `relay.request`, the request body as `relay.body` calls (4 unanswered at most), the response from `relay-head`and `relay-chunk` pushes; the deadline, 8 relays per worker, 64 MiB of unread response, cancel and `WORKER_UNREACHABLE` on a lost uplink. | Route to a worker or know which module a target is. |
159
+
|`GatewayRelay`|`src/gateway/relay.ts`| Handing one HTTP exchange to a relay target on a worker over its uplink (ADR 0026): `relay.request`, the request body and the response body on a byte channel opened on the uplink's link, the head from a `relay-head`push; the deadline over the channel wait and the exchange, cancel and `WORKER_UNREACHABLE` on a lost uplink. | Route to a worker or know which module a target is. |
160
160
|`GatewayOwnerRoutedFacts`|`src/gateway/owner-routed-facts.ts`| The gateway's owner-attributed lease facts, from relayed worker events. | Emit a fact of its own. |
Copy file name to clipboardExpand all lines: docs/internal/adr/0028-the-uplink-carries-byte-channels-and-small-messages-go-first.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# 0028. The uplink carries byte channels beside its messages, and small messages go first
2
2
3
-
-**Status:** Accepted — partly implemented: §1–3 (the link module and the transport port, #556); §4–6 (relays on channels, the download cap, the protocol bump) follow
3
+
-**Status:** Accepted — partly implemented: §1–3 (the link module and the transport port, #556); §4 and §6 (relays on channels, the protocol bump, #558); §5 (the download cap, #557) follows
// why: the worker's redial delay doubles with each restart in a row (1 s, 2 s, 4 s ... up to its jitter), so one test that restarts four times waits up to 8 s.
2002
-
awaitadvance(rig,8_000,500);
2002
+
// why: the worker's redial delay doubles with each restart in a row and carries jitter, so the clock moves on until the worker is back instead of by a sum that a fourth restart can outrun.
it("accepts a channel of 1 to 32 characters of [A-Za-z0-9-] and refuses an empty, a 33-character and a bad-character one, and a request without one",()=>{
0 commit comments