Skip to content

feat(control-plane): per-sandbox egress records through the API - #791

Merged
webchang merged 18 commits into
rossoctl:mainfrom
webchang:pr/i29-egress-records
Nov 14, 2026
Merged

webchang merged 18 commits into
rossoctl:mainfrom
webchang:pr/i29-egress-records

Conversation

@webchang

@webchang webchang commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Part of #752. On main (82a4249): #775 (activation leases and placement), which this branch stacked on, is merged. Its own change is 1 commit (cac7985), plus merges of main. A second PR, stacked on this one, adds the host agent's side and the clients.

What it does: each sandbox gets an egress record that its owner and admins can read through the API, sealed into the sandbox's end record. One signed-off commit:

  • src/egress-log.ts;
  • POST /v1/hosts/{host}/egress, host-authenticated: events are stored only for sandboxes on the workers of builds this host's own inventory holds (inventory-based, not a placement guarantee);
  • GET /v1/sandboxes/{id}/egress, for the owner or an admin;
  • the log's digest in the sandbox's end record, sealed by the janitor;
  • the design doc, and openapi 1.14.0.

Limits:

  • The caps: per sandbox log, 10,000 events and 4 MiB of lines; across all logs, 64 MiB of lines. One audit_dropped report counts at most 1,000,000. format=ndjson streams in 1,000-line chunks.
  • The egress proxy keeps URL path segments when it redacts, so a secret a guest puts in a URL path reaches this log, which the owner and admins can read through the API.
  • Not yet exercised live.
  • The openapi version collides with the sibling stacks; whichever merges later renumbers.

Tests on the tip: the control-plane suite passes.

19 files, +1,948 / -7, counted against #775's tip.

Assisted-By: Claude Code

On each KVM host the moca-egress proxy writes one audit event per connection or
request, with the sandbox's workspace key as `sid`, into the host's journal. The
control plane now keeps those events per sandbox and names their digest in the
sandbox's provenance:

- POST /v1/hosts/{host}/egress {events, cursor, oversized?} (host bearer):
  batches of up to 1000 events, idempotent by (host, cursor). An event is stored
  only when its sid is a sandbox on a worker of a build this host holds, ended
  at most 600 s ago; others are refused and counted. An event naming a field the
  proxy does not write is not stored (its JSON is the wire format) and counts as
  dropped in that sandbox's log, as does each `oversized` sid.
- An audit_dropped report (no VM) is charged to every sandbox on the host's
  workers live within 60 s before it: a log may read incomplete when it lost
  nothing, never complete when it did.
- Store (src/egress-log.ts): a Redis stream per sandbox, one canonical line per
  event, at most 10,000 per sandbox and 200,000 across all logs (the rest counted
  as dropped, `cap` and `budget`), drop counts, a per-host cursor; kept as long
  as the sandbox record.
- GET /v1/sandboxes/{id}/egress?after=&limit= (the owner or an admin):
  {events, next, summary}; ?format=ndjson returns the whole log, whose sha256 is
  summary.sha256.
- GET /v1/hosts/{host}/wanted gains egressSids, the workspace keys whose events
  the host agent ships, so other workloads' events stay on the host.
- The sandbox's terminated record gains egress {events, sha256, dropped,
  droppedBy, complete}. The janitor's sweep seals a log after the 600 s grace
  and, if it changed since the end record, appends one `sandbox` record with
  state: egress naming the final log. No record kind is added.
- openapi.yaml 1.8.0 (EgressEvent, EgressSummary), its CHANGELOG entry, the
  design (docs/specs/2026-11-08-sandbox-egress-records-design.md) and the HTTP
  reference.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a per-sandbox egress log. Hosts post their proxy's audit events to POST /v1/hosts/{host}/egress, and each event is matched to a sandbox by its workspace key. Owners and admins read the log through GET /v1/sandboxes/{id}/egress, and the janitor seals the log's sha256 into the sandbox's end record. The design is careful:

  • Events are allowlisted by field and stored as canonical JSON.
  • The Lua append checks replay, the seal, the cap and the budget in one atomic step.
  • Retries are idempotent by (host, cursor).
  • Reads go through assertSandboxOwner.
  • The digest is computed from the same lines NDJSON serves.

I reviewed this PR's own commit, cac7985.

Must-fixes:

  1. The Redis budget counts events, not bytes. EGRESS_TOTAL_BUDGET (egress-log.ts:57) is documented as "about 64 MB: the bound on Redis memory", but a line can be up to 8 KiB, and its path and host are controlled by the guest. A probe event was accepted as a 7,740-byte line. At that size one sandbox fills its 10,000-event cap at about 80 MB, and the budget at about 1.6 GB. That is well past the 256 MiB Redis it shares with sessions, sandboxes and templates.
  2. A failure after seal() is never retried (sandbox-handlers.ts:249). If chain, summarize or append throws once the log is sealed, every later sweep skips the sandbox. A probe made append throw once, then ran three more sweeps: the log ended sealed: true with 1 event, while its only end record named 0, permanently.

The rest are suggestions and nits, inline:

  • the host-scoping guarantee rests on the host's self-reported inventory;

  • every JSON page re-reads the whole log;

  • NDJSON is built in memory;

  • dropped is unbounded.

  • Author: webchang (MEMBER — maintainer)

  • Areas reviewed: TypeScript control plane (egress-log.ts with the memory and Redis/Lua stores, host-handlers.ts, sandbox-handlers.ts and its janitor seal, server.ts authz), openapi, design doc

  • Agent/IDE config (.claude/.vscode): none

  • Commits: 47 in the branch (1 of them this PR's own), all signed-off: yes

  • CI status: pending (DCO, shellcheck, proto, CodeQL and Trivy pass; the rest are still running)

Verified by:

  • vitest run in packages/control-plane: 1299 pass, 9 fail. All 9 failures are ECONNREFUSED 127.0.0.1:6379 because no Redis was available, so the Lua scripts were not exercised.
  • The 7 touched test files: 115/115 pass.
  • A throwaway probe test for the line size, the seal failure, a forged-inventory post and the owner/admin read. It is deleted.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

* still exist, so a log that expired (14 days after its sandbox ended) gives its share back with no
* reconciliation and no counter to drift.
*/
export const EGRESS_TOTAL_BUDGET = 200_000;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix: this budget, and EGRESS_LOG_CAP, count events, but the comment above promises bytes ("about 64 MB: the bound on Redis memory"). A line can be up to MAX_LINE = 8192 bytes, and its path and host come from the guest. A probe event with a 4 KB path and a 3.5 KB host was accepted as a 7,740-byte line. At that size one sandbox reaches its 10,000-event cap at about 80 MB, and this budget at about 1.6 GB. That is several times the 256 MiB Redis it shares with sessions, sandboxes and templates.

Suggested fix: budget in bytes. Keep a running byte sum (or use STRLEN) in the Lua append, and cap bytes per log too. Alternatively, cut the per-field limits so that line size × count really is about 64 MB. It matters now because the limits ship with the first API version that accepts the events.

);
const chains = new Map<string, Awaited<ReturnType<ProvenanceStore['chain']>>>();
for (const r of due) {
if (!(await store.seal(r.id, (r.deletedAt ?? r.expiresAt) + retentionS))) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix: the seal happens before the work it guards. If provenance.chain, egressDigest/summarize (a Redis error) or provenance.append throws after seal() returns true, every later sweep gets false here and continues. The final digest is then never recorded. A probe made append throw once for the egress record, then ran three more sweeps: records after recovery: ["terminated"] sealed: true events 1 end names 0. That is permanent: a sealed log whose end record names none of its events.

Suggested fix: mark the log done last. Write the egress record first and set sealed after it, or keep a separate recorded flag. Then on each sweep, re-check sealed logs that have no matching egress record. The compare at L262 already makes that idempotent.

const holds = deps.hosts?.get(host)?.holds ?? {};
const out = new Set<string>();
for (const d of (await deps.templates?.list()) ?? [])
for (const b of d.builds) if (b.worker && holds[b.buildId] !== undefined) out.add(b.worker);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "events map only to that host's own sandboxes" depends on the host's last self-reported holds. Nothing checks it against placement or against which host attached the worker. In a probe, host-2 posted an inventory claiming t1's build, then posted an event with a t1 sandbox's sid. The response was {"accepted":1,...}, and the event showed up in alice's sandbox log, which runs on host-1. Hosts are trusted, so this is defense in depth, but the PR body and the design doc state it as a guarantee.

Suggested fix: restrict events to the host the build is placed on or attached to, or say in the design doc that the property rests on inventory trust.

body: {
events: page.map((e) => JSON.parse(e.line) as unknown),
next: page.length === limit ? page[page.length - 1]!.id : null,
summary: await summarize(deps.egress, rec.id),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: every JSON page computes summarize over the whole log, up to 10,000 lines of up to 8 KiB each, parsed one by one. Paging a full log at the default limit=100 is about 100 full scans, which is quadratic, and any owner can trigger it repeatedly. The PR body's Limits section mentions only the NDJSON cost.

Suggested fix: include summary only on the first page (after === null) or behind ?summary=1, or cache it by stream length and last id.

throw new CpError('invalid_request', "format must be 'json' or 'ndjson'");
if (format === 'ndjson') {
let out = '';
for await (const line of allLines(deps.egress, rec.id)) out += `${line}\n`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: as the PR body says, NDJSON builds the whole log as one string, up to about 80 MB per request (see the line-size note on egress-log.ts:57), with no concurrency limit. A few concurrent owner requests can grow the control-plane heap by hundreds of MB.

Suggested fix: stream each page to the response as it is read, or at least apply a per-request byte cap.

const t = eventSeconds(o, nowS);
dropped += n;
for (const r of mine)
if (r.createdAt <= t && endOf(r) >= t - EGRESS_DROP_WINDOW_S) group(r).proxyDropped += n;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nonNeg(o.dropped) is unbounded up to MAX_SAFE_INTEGER, and the charge goes to every retained sandbox on the host's workers. One malformed report marks them all incomplete with a huge count, and HINCRBY overflows past 2^63 and fails the whole atomic post. I did not run this against Redis. Suggested fix: clamp n to a sane maximum, such as EGRESS_POST_MAX per report.

Conflict in host-handlers.ts, hostWanted's doc comment only: rossoctl#775's
sticky stop (a copy run while placement keeps the build elsewhere) and
this branch's egressSids sentence, both kept. rossoctl#775's new exact
wanted-body test expects this branch's egressSids: [].

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

clawgenti reviewed this PR at 2c06a12. Their two must-fixes match ours, and I +1 both. I'm not repeating them inline:

  1. The egress budget and EGRESS_LOG_CAP count events, not bytes. Lines can be up to 8 KiB of guest-controlled path/host, so the "about 64 MB" Redis bound can reach about 1.6 GB (egress-log.ts:57).
  2. seal() runs before the work it guards. If chain, summarize or append fails after the seal, the log stays sealed and the failure is never retried (sandbox-handlers.ts:249).

I also agree with their host-scoping suggestion (host-handlers.ts:74). hostWorkers() trusts the posting host's self-reported holds, so one host can write into another host's sandbox logs. Their full-log summarize on every page (:1372) and their unbounded dropped point cover our own notes on the same lines.

What this review adds, inline: the total budget is computed by an O(index) Lua loop on every append, the memory store's pagination differs from Redis XRANGE for an unknown after id, and two spec nits.

Since 3ccf433 the pushes only merge the stack (now including #766's jq fix); this PR's own commits are unchanged. Earlier, the head 3ccf433 only merges #775's head (dbd2973). I checked the one conflict with --remerge-diff: the hostWanted doc comment now keeps both #775's "placement keeps them on another host" text and this PR's egressSids note, and the test expects egressSids: []. This PR's own commit cac7985 is unchanged.

Author: webchang (MEMBER — maintainer)
Own range reviewed: cac7985 (1 commit; the stacked parents' commits are not re-reviewed here)
Areas reviewed: TypeScript control plane (egress-log.ts, host-handlers.ts, sandbox-handlers.ts), openapi, design doc
Agent/IDE config (.claude/.vscode): none
Commits: own commit signed off: yes
CI status: check, which was red at 3ccf433, is green at this head. deploy-scripts and CodeQL pending.

AI-assisted review, approved by a maintainer before posting.

local cap = tonumber(ARGV[2]); local g = tonumber(ARGV[6]); local budget = tonumber(ARGV[7])
local prefix = ARGV[8]
local total = 0
for _, id in ipairs(redis.call('SMEMBERS', KEYS[2])) do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The total budget is derived by iterating the whole index on each append. With 14-day retention the index holds every sandbox that logged anything in that period; each host posts every 15 s (and up to 10 batches per run), so each post is O(#retained logs) work while blocking the single Redis thread. It is correct but scales with retention, not with load. Consider keeping a running total counter (INCRBY on XADD) with periodic reconciliation, or at least note the bound in the design.


| Route | Who | Answer |
| --------------------------------------------- | ---------------------------------- | ------------------------------------------------------- |
| `POST /v1/hosts/{host}/egress` | a host agent, as itself | `{accepted, refused, capped, invalid, dropped, cursor}` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The table lists {accepted, refused, capped, invalid, dropped, cursor} but the handler and openapi.yaml answer also overBudget. Add it.


1. **Who may read a sandbox's egress:** the sandbox's owner and admins, the same as the other
sandbox routes. No separate grader role.
2. **Retention:** the sandbox record's (`SBX_RETENTION_DAYS`, 14 days today).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: §6.2 says SBX_RETENTION_DAYS; the code and §3 use SH_SANDBOX_RETENTION_SECONDS (sandbox-config.ts). Use the real name.


async page(id: string, after: string | null, limit: number) {
const es = this.logs.get(id)?.entries ?? [];
const from = after === null ? 0 : es.findIndex((e) => e.id === after) + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: findIndex returns -1 for an id not in the log, so the memory store restarts from the beginning, whereas Redis XRANGE (after returns entries strictly after that id. Tests on the memory store therefore cannot catch a pagination bug with a stale/foreign next. Filter by id order (compare stream ids numerically) to match Redis.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 462f3ae. Since our last review (2c06a12) the head has changed only by merging in base updates from #771 and #785, and those are reviewed on their own PRs. This PR's own commit, cac7985, is unchanged, so both must-fixes from that review are still open at head:

  1. The Redis budget counts events, not bytes. EGRESS_TOTAL_BUDGET = 200_000 and EGRESS_LOG_CAP = 10_000 (egress-log.ts:48, :57) are still event counts, and MAX_LINE is still 8192 (:75). With lines that size, one sandbox's cap is about 80 MB, and the budget is about 1.6 GB against the 256 MiB Redis it shares.
  2. A failure after seal() is never retried. The janitor still seals first (sandbox-handlers.ts:250), so a throw in chain, egressDigest or append leaves a sealed log whose end record never names it.

The inline suggestions and nits from the last review also still apply: host scoping rests on the self-reported inventory, every JSON page re-runs summarize, NDJSON is built in memory, and dropped is unbounded.

  • Author: webchang (MEMBER — maintainer)
  • Areas reviewed: the merge delta (base-only), with this PR's egress code re-checked at head
  • Agent/IDE config (.claude/.vscode): none
  • Commits: 70 in the branch (1 of them this PR's own, unchanged), all signed-off: yes
  • CI status: passing (17/17)

Verified by:

  • Re-reading egress-log.ts and the janitor's seal loop at head.
  • control-plane vitest run with a local Redis (on #792's head, which contains this one): 1413 pass, 3 skipped, 0 fail. Last time we had no Redis, and 9 tests failed with ECONNREFUSED. This time the Lua scripts ran.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

The review found that the egress log's cap and total budget counted events
while the comment promised a bound on Redis memory: a line may be up to 8 KiB
and its host and path come from the guest, so 10,000 events per log could reach
about 80 MB and the 200,000-event budget about 1.6 GB. It also found that the
Lua append summed every retained log's length on each post, so a post's cost
grew with retention, not with load.

- A log now holds at most 10,000 events and 4 MiB of lines (EGRESS_LOG_BYTES),
  and all logs together at most 64 MiB of lines (EGRESS_TOTAL_BYTES); the
  excess is counted as dropped (`cap`, `budget`), as before.
- The total is a running sum kept by the append script, beside each log's bytes
  and an index of the logs by expiry. A log whose expiry has passed gives its
  bytes back at the next append (at most 500 per append); a lost total is summed
  once from the sizes. Every key the script touches is now in KEYS.
- Seal and expireAt move the log's place in the expiry index.
- Tests: the byte cap per log, the running total under racing posts, a log's
  bytes given back when its expiry passes, a lost total summed again. Design,
  openapi and changelog wording updated.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…t before

The review found that the janitor's sweep sealed an ended sandbox's egress log
before the work the seal guards: if reading the chain, the digest or the
provenance append failed after the seal, every later sweep skipped the sandbox,
and its final digest was never recorded.

The sweep now skips a log only when it is already sealed, writes the `egress`
record when the log changed since the newest record that names it, and seals
the log last. A failed sweep leaves the log unsealed, and the next one does the
work again; past the grace the host post takes no events for the sandbox, so
the compare with the newest record keeps a repeat to one record.

Test: an append that fails once for the egress record, then two sweeps: one
egress record, then sealed. Design §3 says the order.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The review found that "events map only to that host's own sandboxes" was stated
as a guarantee, while it rests on the posting host's self-reported inventory
(`holds`): a host that claims another host's build can post events into that
build's sandboxes' logs.

The design (§3, Who) and hostWorkers' comment now say what the property rests
on: hosts are trusted, each with its own bearer, so the scoping holds when the
inventory is true; it is not a check against a host that claims a build it does
not run. Placement is not used to tighten it, since placement is computed from
the same inventories and a sandbox's worker may have run on another host during
its life. No behaviour change.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…e only

The review found that every JSON page of GET /v1/sandboxes/{id}/egress
computed the summary over the whole log, so paging a full log through at the
default limit read it about a hundred times, and any owner could repeat that.

The summary is now on the first page (no `after`) and null on the pages after
it, so paging a log through reads it once, plus its pages. openapi (the
response's summary is EgressSummary or null), its changelog entry and design
§3 say so. Test: the later pages' summary is null, and a later page reads the
store once.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The review found that `?format=ndjson` built the whole log as one string
before answering, with no limit on concurrent requests, so a few owners
reading full logs at once could grow the control plane's heap by hundreds of
megabytes.

The handler now returns the export as an async iterable, a chunk per 1000
lines as the store pages are read, and the server writes a streamed body with
backpressure (server.ts writeStream). The first chunk is read before the status
goes out, so a store that fails at once still answers 503; one that fails
later cuts the body short. A client that goes away stops the reads. With the
byte cap per log, a log is at most 4 MiB in any case.

Tests: the export over HTTP (chunked, byte for byte what the summary's sha256
names), a failure on the first page (503) and on a later one (cut short).

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The review found that an `audit_dropped` report's `dropped` was taken up to
Number.MAX_SAFE_INTEGER and charged to every retained sandbox on the host's
workers in the window: one malformed report would mark them all incomplete
with a huge count, and Redis HINCRBY could overflow past 2^63 and fail the
whole post.

One report's count is now taken up to EGRESS_DROP_REPORT_MAX (1,000,000); a
larger one counts as that, and the log is incomplete either way. At 1000
reports per post a counter needs billions of posts to overflow.

Tests: two reports of MAX_SAFE_INTEGER charge 2,000,000; on Redis, the largest
charge a post can carry adds without overflow. Design §3 and openapi say the
bound.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The review found that the memory store's page() looked `after` up by
findIndex, so an id not in the log (a stale or foreign `next`) restarted the
page from the beginning, while the Redis store's XRANGE `(after` answers the
entries strictly after that id. Tests on the memory store could not catch a
pagination bug of that kind.

The memory store now takes the entries whose id is after `after` in Redis's
stream-id order (compareEntryIds: by ms, then seq, as 64-bit numbers). Test,
on both stores: paging after an id that is not in the log, before every entry
and after them all.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ting

Two review nits on the egress records design: §4's table listed the host
post's answer without `overBudget`, which the handler and openapi answer, and
§6.2 named the setup knob `SBX_RETENTION_DAYS` where the code and §3 read
`SH_SANDBOX_RETENTION_SECONDS`. The table now lists overBudget, and §6.2 names
SH_SANDBOX_RETENTION_SECONDS (14 days by default), noting that setup.sh sets
it from SBX_RETENTION_DAYS.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

Start tip 462f3ae. Each reply below is one thread. Every change is a new commit on top; the PR's own commit cac7985 is unchanged.

Review threads

1. packages/control-plane/src/egress-log.ts:378

"The total budget is derived by iterating the whole index on each append ... Consider keeping a running total counter (INCRBY on XADD) with periodic reconciliation, or at least note the bound in the design."

Fixed in 7b40f70, together with the bot's byte-budget must-fix (they touch the same script). The append script now keeps a running total of stored bytes (sh:sbx:egress:total), each log's bytes (sh:sbx:egress:bytes) and an index of the logs by expiry (sh:sbx:egress:expiry, a sorted set). A post's cost is its own events plus the logs whose expiry has passed, at most 500 per post, whose bytes it gives back. It no longer depends on how many logs are retained. The reconciliation: a missing total is summed again once from the sizes. A log removed by hand stays counted until its expiry passes, so the budget errs towards storing less. seal and expireAt move a log's entry in the expiry index. Every key the script touches is now in KEYS. Design §3 states the cost. Tests: keeps the total as a running sum; a lost total is summed again from the logs' sizes, takes back the budget of a log whose keys expired passively, and cannot pass the budget with two hosts posting at once (which now also checks the total).

2. docs/specs/2026-11-08-sandbox-egress-records-design.md:110

"The table lists {accepted, refused, capped, invalid, dropped, cursor} but the handler and openapi.yaml answer also overBudget. Add it."

Fixed in f4983fc: §4's table now lists {accepted, refused, capped, overBudget, invalid, dropped, cursor}.

3. docs/specs/2026-11-08-sandbox-egress-records-design.md:137

"§6.2 says SBX_RETENTION_DAYS; the code and §3 use SH_SANDBOX_RETENTION_SECONDS (sandbox-config.ts). Use the real name."

Fixed in f4983fc: §6.2 now names SH_SANDBOX_RETENTION_SECONDS (14 days by default) and says that deploy/sbx/setup.sh sets it from SBX_RETENTION_DAYS.

4. packages/control-plane/src/egress-log.ts:322

"findIndex returns -1 for an id not in the log, so the memory store restarts from the beginning, whereas Redis XRANGE (after returns entries strictly after that id ... Filter by id order."

Fixed in cc76958. The memory store's page now returns the entries whose id comes after after in Redis's stream-id order. A new compareEntryIds compares ms first, then seq, each as a 64-bit number. Tests: pages after an id that is not in the log by id order, as XRANGE does, run on both stores, and compareEntryIds.

Bot threads (clawgenti)

5. packages/control-plane/src/egress-log.ts:57 (must-fix)

"this budget, and EGRESS_LOG_CAP, count events, but the comment above promises bytes ... Suggested fix: budget in bytes ... and cap bytes per log too."

Fixed in 7b40f70. A log now holds at most 10,000 events and 4 MiB of lines (EGRESS_LOG_BYTES), whichever limit it reaches first. All logs together hold at most 64 MiB of lines (EGRESS_TOTAL_BYTES). Both are counted in the Lua append, from each line's byte length. The excess is still counted as dropped (cap, budget). The comment now says that Redis's per-entry overhead comes on top of the line bytes. openapi, its changelog entry and design §3 use the new figures. Tests: caps a log by its bytes too: guest-sized lines stop at the byte cap, counted as cap drops (on both stores, including a 4 KB host) and holds all logs together to the budget; an expired log gives its share back (now in bytes).

6. packages/control-plane/src/sandbox-handlers.ts:250 (must-fix)

"the seal happens before the work it guards ... Suggested fix: mark the log done last."

Fixed in 1354e47. The sweep now skips a log only when it is already sealed. Otherwise it writes the egress record if the log changed since the newest record naming it, and seals the log last. A failure before the seal leaves the log unsealed, and the next sweep does the work again. Past the grace the host post takes no events for the sandbox, so the compare with the newest record keeps a repeat to one record. Design §3 states the order. Test: a sweep that fails before the seal leaves the log unsealed, and the next sweep records it. The append fails once for the egress record; the next two sweeps write one egress record (2 events), and the log is then sealed.

7. packages/control-plane/src/host-handlers.ts:74

"'events map only to that host's own sandboxes' depends on the host's last self-reported holds ... restrict events to the host the build is placed on or attached to, or say in the design doc that the property rests on inventory trust."

Fixed in 9e75bce by documenting it; behaviour is unchanged. Design §3 (Who) and hostWorkers' comment now say what the property rests on. Hosts are trusted, each with its own bearer, so the scoping holds when a host's inventory is true. It does not stop a host that claims a build it does not run. I did not restrict events to placement, for two reasons:

  • Placement is computed from the same self-reported inventories (holds, running), so it would add no independent check.
  • A sandbox's worker can run on another host during its life, which would refuse real events from the grace period.

The relay knows which worker attached, but not from which host. The PR body's wording will be corrected to match when the PR text is next updated.

8. packages/control-plane/src/sandbox-handlers.ts:1372

"every JSON page computes summarize over the whole log ... Suggested fix: include summary only on the first page (after === null) or behind ?summary=1, or cache it."

Fixed in 40d0702. summary now comes with the first page (no after) and is null on the pages after it, so paging a log through reads it once. openapi now types the response's summary as EgressSummary or null, and its changelog entry and design §3 say the same. mocactl sbx egress (#792) already reads the summary from the first page only. Its SbxEgressPage.summary type should become nullable in #792. Test: pages by next (the summary on the first page), and its NDJSON export hashes to its sha256 checks that the later pages' summary is null and that a later page reads the store once.

9. packages/control-plane/src/sandbox-handlers.ts:1356

"NDJSON builds the whole log as one string ... Suggested fix: stream each page to the response as it is read, or at least apply a per-request byte cap."

Fixed in f1930e8. The handler returns the export as an async iterable, one chunk per 1000 lines as the store pages are read. The server writes a streamed body with backpressure (server.ts writeStream).

  • The first chunk is read before the status goes out, so a store that fails at once still answers 503.
  • A store that fails later cuts the body short. That shows up in the sha256, which then does not match the record.
  • A client that disconnects stops the reads.

With the byte cap from 7b40f70, one log is at most 4 MiB in any case. Test: streams the NDJSON export over HTTP, a store page at a time, byte for byte the digest (2,500 events, chunked, plus a failure on the first page and on a later page).

10. packages/control-plane/src/host-handlers.ts:348 (nit)

"nonNeg(o.dropped) is unbounded up to MAX_SAFE_INTEGER ... Suggested fix: clamp n to a sane maximum."

Fixed in b5ca434. One audit_dropped report's count is now taken up to EGRESS_DROP_REPORT_MAX (1,000,000). A larger count is recorded as 1,000,000, and the log is marked incomplete either way. I did not clamp to EGRESS_POST_MAX (1000), because a real 10 s burst can lose more than 1000 events, and the count should stay close to the real loss. At 1000 reports per post, a counter would need billions of posts to overflow. Design §3 and openapi state the bound. Tests: the audit_dropped test now also checks that two reports of MAX_SAFE_INTEGER charge 2,000,000. On Redis, takes the largest charge a post can carry without overflowing a counter checks the same bound.

New tip: f4983fc

Limits after this round

  • The index moved from the set sh:sbx:egress:index to new keys. On a deployment that ran the earlier build, the old set is left behind (harmless), and logs written before the upgrade do not count toward the new byte total.
  • With the seal now last, two janitor sweeps running at the same time could each write a sandbox's egress record once; the compare with the newest record stops repeats only across sweeps that run one after another. The janitor runs as one process, so this needs two janitors at once.

Assisted-By: Claude Code

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Eight new commits on 462f3ae (7b40f70 … f4983fc) close all four of our 462f3ae threads and all six of clawgenti's. I checked each fix against the code:

  • Byte budget (clawgenti's must-fix, plus our O(index) suggestion), fixed in 7b40f70. The Lua append counts each line's #line bytes against a 4 MiB cap per log and a 64 MiB total. The total is now a running sh:sbx:egress:total with a per-log bytes hash. An expiry zset gives back up to 500 expired logs per post. A missing total is re-summed from HVALS. seal and expireAt move the zset entry with XX. Every key is in KEYS. The memory store mirrors this with Buffer.byteLength.
  • Seal last (clawgenti's must-fix), fixed in 1354e47. The sweep skips only logs that are already sealed, writes the egress record if the digest changed, and only then seals. A failure before the seal is retried on the next sweep, and the newest-record compare stops repeats.
  • Host scoping, documented in 9e75bce. It rests on inventory trust. The author's reasoning holds: placement comes from the same self-reported inventories.
  • Summary on the first page only, fixed in 40d0702. openapi now types it as nullable.
  • Streamed NDJSON export (server.ts writeStream), in f1930e8. It has backpressure, reads the first chunk before the status goes out, and stops on client close.
  • audit_dropped clamped to 1,000,000, fixed in b5ca434.
  • Memory store pages by stream-id order (compareEntryIds), fixed in cc76958.
  • Both spec nits, fixed in f4983fc.

One new nit, inline: writeStream adds drain/close listeners that are never removed.

The author's two stated limits are acceptable as follow-ups: the old sh:sbx:egress:index set is left behind after an upgrade, and two janitors running at once could each write a record. The PR body still says events reach "only that host's own sandboxes"; please correct it as promised in the reply (it rests on inventory trust).

Author: webchang (MEMBER — maintainer)
Own range reviewed: 462f3ae..f4983fc (8 commits; the stacked parents are not re-reviewed)
Areas reviewed: TypeScript control plane (egress-log.ts Lua + memory store, host-handlers.ts, sandbox-handlers.ts, server.ts), tests, openapi, design doc
Agent/IDE config (.claude/.vscode): none
Commits: 8 new, all signed-off: yes
CI status: passing (all checks green at f4983fc)

Assisted-By: Claude Code

try {
while (!next.done) {
// A client that goes away mid-stream closes the response: stop reading the store.
if (!res.write(next.value)) await Promise.race([once(res, 'drain'), once(res, 'close')]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Promise.race([once(res, 'drain'), once(res, 'close')]) leaves the losing once listeners attached (both once calls also add an error listener), so every backpressure wait adds a close listener and an error listener that are never removed. A 4 MiB export to a slow reader can wait hundreds of times. On Node 26, a standalone http server running this loop with a slow client hit MaxListenersExceededWarning (11 close/error listeners) after 11 waits. Harmless beyond the warning and the per-response growth, but easy to avoid: give both once calls one AbortController's signal and abort it after the race, or listen for close once outside the loop and only await drain inside.

@pdettori

Copy link
Copy Markdown
Member

need to resolve the conflicts

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at f4983fc. Since our last review (462f3ae), the author has pushed 8 commits (7b40f70..f4983fc). Both must-fixes from that review are fixed:

  1. The budget counts bytes. There is now a 4 MiB cap per log and a 64 MiB total. One Lua script checks each line against both caps, then does the XADD and updates the running total in the same step, so two hosts posting at once cannot both get past the budget. Expired logs give their bytes back.
  2. A failed sweep is retried. The janitor now writes the record first and seals last, so a throw before the seal leaves the log unsealed for the next sweep. The new test covers this.

The earlier suggestions are also handled. The summary comes only with the first page. NDJSON is streamed with backpressure, and a client abort stops the store reads. Each dropped report is capped at 1,000,000. Host scoping is now a documented trust assumption.

The rest are a suggestion and a nit, inline, both from moving the seal to the end:

  • An audit_dropped report that lands between the digest and the seal leaves a sealed log whose newest record says complete: true, dropped: 0. Drops are charged to every retained sandbox on the host, not only those still in the grace.

  • Two janitors that sweep at the same moment can both write the state: 'egress' record.

  • Author: webchang (MEMBER — maintainer)

  • Areas reviewed: the delta 462f3ae..f4983fc. That covers the TypeScript control plane (the egress-log.ts Lua APPEND/SEAL/EXPIRE scripts, sealEgress and getSandboxEgress in sandbox-handlers.ts, server.ts writeStream, host-handlers.ts), the tests and the egress spec.

  • Agent/IDE config (.claude/.vscode): none

  • Commits: 8 new since the last review (118 in the branch), all signed-off: yes

  • CI status: passing (17/17)

Verified by:

  • vitest run on the 6 egress test files with a local Redis: 114 pass, with the Lua scripts exercised.
  • The full control-plane vitest run: 1418 pass, 3 skipped, 0 fail. tsc --noEmit: clean.
  • Three throwaway probe tests:
    • an audit_dropped report between the record and the seal. The sealed log had 5 drops, but its last record said 0.
    • two concurrent sweeps. They wrote 2 egress records; the old seal-first order wrote 1.
    • a slow client that aborts mid-export. Store reads stop after the close.
  • The probes have been deleted.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

*
* The seal comes last, after the record is written: a sweep that fails before it (the chain, the
* digest or the append) leaves the log unsealed, so the next sweep does the work again. Past the
* grace the host post takes no events for the sandbox, so the log no longer changes, and the

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "Past the grace the host post takes no events for the sandbox, so the log no longer changes" is not true for audit_dropped reports. hostEgress charges them through hostSandboxes (host-handlers.ts:353), which covers every retained sandbox on the host's workers, not egressAccepts. Only a sealed meta refuses the charge. With the seal now last, a report that lands between egressDigest and store.seal (an agent catching up on its journal, with a report timed within 60 s of the sandbox's end) leaves a sealed log with proxy > 0 whose newest record says dropped: 0, complete: true.

Reproduced with a probe test: an audit_dropped post injected right after the egress record's append, then two sweeps. Result: the sealed summary had dropped: 5, complete: false, and the last record had dropped: 0, complete: true.

Fix, either of these:

  • Charge the drop only to the sandboxes still in the grace: for (const r of egressAccepts(mine, nowS)) at host-handlers.ts:353. This matches how events are already refused past the grace, and makes this comment true.
  • Make the seal a compare-and-seal: pass the digested counters (or the stream length and the meta values) to the SEAL script and refuse to seal if they changed, so the next sweep records again.

);
const chains = new Map<string, Awaited<ReturnType<ProvenanceStore['chain']>>>();
for (const r of due) {
if ((await store.meta(r.id)).sealed) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Now that the seal is no longer the claim, two sweeps that run at the same moment both pass this check, and both find no matching record in their cached chain, so both append the state: 'egress' record. setup.sh says to install the janitor on every KVM host, each on its own 15-minute timer, so overlap is rare but possible. A probe that ran Promise.all([janitor(), janitor()]) wrote 2 egress records; with the old seal-first code it wrote 1. The newest record still names the right log, so this is only a duplicate. If you want it gone: re-read the chain just before the append, or take a short lock (SET NX with a TTL) per sandbox around the record-and-seal.

pr/i19-activation now carries upstream/main (sbx templates create, build,
follow, cancel, quota and policy).

Conflicts: none.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

Merged main (d4babb8). CI is the full check: local tests ran on the existing node_modules during the hono pin's release-age window.

Assisted-By: Claude Code

…s, not its bytes

The comment said an event is stored exactly as the proxy wrote it; it
is stored as one canonical JSON line of the same fields and values, so
its bytes (escaping, key order) may differ. Comment only.

Refs rossoctl#752

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

egress-log.ts's comment now says the log keeps each event's fields and values in one canonical line, whose bytes may differ from the proxy's. That is a comment-only change (new head 7ce0310).

Assisted-By: Claude Code

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Follow-up at 7ce0310 (8b67c9b..7ce0310). One own commit, comment-only: egress-log.ts's header now says the log keeps an event's fields and values as the proxy wrote them, as one canonical JSON line whose bytes may differ (escaping, key order). That matches the code, which stores and hashes canonicalJson(e). No behaviour change.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (doc comment only)
Agent/IDE config (.claude/.vscode): none
Commits: 1 new (7ce0310), signed off: yes (DCO pass)
CI status: passing (all 17 checks green)

AI-assisted review, approved by a maintainer before posting.

Brings in upstream main (lease modes, API 1.6.0) through pr/i19-activation.

Conflicts:
- docs/api/CHANGELOG.md: this branch's egress records section, renumbered 1.9.0, above
  pr/i19-activation's 1.8.0, pr/i18-host-agent's 1.7.0 and main's 1.6.0.
- docs/api/openapi.yaml: both new sandbox paths, this branch's /v1/sandboxes/{id}/egress then
  main's /mode and /mode-token.
- docs/reference/http-api.md: the host agents (1.7.0) and activation (1.8.0) rows as
  pr/i19-activation has them, then this branch's egress records row.
- packages/control-plane/src/routes.ts, test/routes.test.ts: both sides' sandbox routes.
- packages/control-plane/src/sandbox-handlers.ts: main's mintSetModeToken import, and this
  branch's egress-log import.
- packages/control-plane/test/openapi-contract.test.ts: the enrollment-checked route count is 23
  (20, plus main's two mode routes and this branch's egress read).
- packages/control-plane/test/route-authz-enumeration.test.ts: the sandbox-scoped route count is 6
  (3, plus main's two and this branch's one).

API version: this branch's egress records move from 1.8.0 to 1.9.0 (openapi info.version and its
"before 1.8.0" note, the changelog, and the two "API 1.8.0" mentions in
docs/reference/http-api.md).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through f60db30 (turn grants, API 1.7.0) by pr/i19-activation.

Conflicts:
- docs/api/CHANGELOG.md: this branch's egress records section, renumbered 1.10.0, above
  pr/i19-activation's 1.9.0, pr/i18-host-agent's 1.8.0 and main's 1.7.0 and 1.6.0.
- docs/reference/http-api.md: the host agents (1.8.0) and activation (1.9.0) rows as
  pr/i19-activation has them, then this branch's egress records row.

API version: this branch's egress records move from 1.9.0 to 1.10.0 (openapi info.version and
its "before 1.9.0" note, the changelog, and the two "API 1.9.0" mentions in
docs/reference/http-api.md).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
The egress log's caps counted events only, while a line may be up to
8 KiB with a guest-chosen `host` and `path`, and the deployment-wide cap
was summed over every retained log on each post. A log now holds at
most 10,000 events and 4 MiB of lines, all logs together 64 MiB of
lines, the excess counted as dropped; the total is a running sum (one
Lua script per post on Redis), a post costs its own events plus the
logs whose expiry has passed (at most 500 per post), and a lost total is
summed again from the logs' sizes.

egress-redis.test.ts and sandbox-egress.test.ts (memory and Redis):
byte caps, the budget across logs and hosts, passive expiry giving its
share back, the running total; they fail with the fix reverted. The
spec, openapi and the API changelog say so.

(cherry picked from commit 7b40f70)

Ports rossoctl#791 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…t before

The janitor's sweep sealed an ended sandbox's egress log before the
work the seal guards: if reading the chain, the digest or the
provenance append failed after the seal, every later sweep skipped the
sandbox, and its final digest was never recorded. The sweep now skips a
log only when it is already sealed, writes the `egress` record when the
log changed since the newest record that names it, and seals the log
last; a failed sweep leaves the log unsealed and the next one does the
work again.

sandbox-egress.test.ts: an append that fails once for the egress
record, then two sweeps: one egress record, then sealed (fails with the
fix reverted). The file's fixture host ids are renamed host-1/host-2.
Design §3 says the order.

(cherry picked from commit 1354e47)

Ports rossoctl#791 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…e only

Every JSON page of GET /v1/sandboxes/{id}/egress computed the summary
over the whole log, so paging a full log through at the default limit
read it about a hundred times, and any owner could repeat that. The
summary is now on the first page (no `after`) and null on the pages
after it, so paging a log through reads it once, plus its pages.
mocactl already takes the summary from the first page.

With it, the docs-only upstream commit on egress host scoping: the
host-handlers comment and design §3 state that scoping an event to a
host's sandboxes rests on the host's own inventory.

sandbox-egress.test.ts: the later pages' summary is null, and a later
page reads the store once (fails with the fix reverted). openapi, the
API changelog and design §3 say so.

(cherry picked from commit 9e75bce)
(cherry picked from commit 40d0702)

Ports rossoctl#791 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
`?format=ndjson` built the whole log as one string before answering,
with no limit on concurrent requests, so a few owners reading full logs
at once could grow the control plane's heap by hundreds of megabytes.
The handler now returns the export as an async iterable, a chunk per
1000 lines as the store pages are read, and the server writes a
streamed body with backpressure (server.ts writeStream). The first chunk
is read before the status goes out, so a store that fails at once still
answers 503; one that fails later cuts the body short. A client that
goes away stops the reads.

sandbox-egress.test.ts: the export over HTTP (chunked, byte for byte
what the summary's sha256 names), a failure on the first page (503) and
on a later one (cut short); they fail with the fix reverted. openapi and
the design say so.

(cherry picked from commit f1930e8)

Ports rossoctl#791 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…he memory store pages as XRANGE

- An audit_dropped report's count was taken as sent, so one report could
  overflow a drop counter; it is now bounded (the largest charge a post
  can carry), and openapi and the design say so.
- The memory egress store paged after an id by string order; it now
  orders stream ids by ms, then seq, numerically (compareEntryIds), and
  pages after an id that is not in the log as XRANGE does.
- Docs: the egress design names overBudget and the retention setting,
  and the egress log comment says it keeps an event's fields and values,
  not its bytes.

egress-redis.test.ts and sandbox-egress.test.ts (memory and Redis): the
id order, paging after a missing id, the largest charge without
overflow, and a drop report charged to every sandbox live in the
window; they fail with the fixes reverted.

(cherry picked from commit b5ca434)
(cherry picked from commit cc76958)
(cherry picked from commit f4983fc)
(cherry picked from commit 7ce0310)

Ports rossoctl#791 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
The RUNBOOK still gave the egress budget as 200,000 events across all
logs, re-summed on every post, after the byte budgets ported from
upstream rossoctl#791 (7b40f70): a log holds at most 10,000 events and 4 MiB
of lines, all logs together 64 MiB of lines kept as a running total,
and a post costs its own events plus the expired logs it reaps. Docs
only; the upstream RUNBOOK has the same stale text.

Ports rossoctl#791 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through 82a4249 (API 1.13.0: template tags, edits and owner transfer,
subject trust for gate records, the host agents, activation, memory placement and cold-start
pacing).

Conflicts:
- docs/api/CHANGELOG.md: this branch's egress records section, renumbered 1.14.0, above main's
  1.13.0 and below, which are main's.
- docs/api/openapi.yaml: info.version 1.14.0; the wanted answer keeps main's `starting` and
  `graced`, then this branch's `egressSids` (absent before 1.14.0).
- docs/reference/change-policy.md: version 1.14.0; main's list, through cold-start pacing, then
  per-sandbox egress records.
- docs/reference/http-api.md: main's rows, then this branch's egress records row (API 1.14.0).
- packages/control-plane/src/host-handlers.ts: main's activation-lock and activation imports with
  this branch's SandboxRecord and egress-log imports; hostEgress beside main's handlers; hostWanted
  answers main's wantedAnswer with this branch's egressSids added.
- packages/control-plane/test/openapi-contract.test.ts: 27 enrollable routes (main's 26 plus the
  sandbox's egress log).

API version: this branch's egress records move from 1.10.0 to 1.14.0 (openapi info.version and
its egressSids note, the changelog, change-policy and the two "API 1.10.0" mentions in
docs/reference/http-api.md).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang merged commit 30cd706 into rossoctl:main Nov 14, 2026
18 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings pr/i26-retire at upstream main d227d41 (through rossoctl#790, with rossoctl#789's
combined plane and pinned-session holds, rossoctl#791/rossoctl#792 egress, rossoctl#784 pacing,
rossoctl#776 memory placement and rossoctl#808), and i26's retire at API 1.18.0. This
branch's quotas and reject section moves to 1.19.0.

Conflicts:
- docs/api/CHANGELOG.md: ## 1.19.0 quotas and reject above i26's
  ## 1.18.0 and main's sections, which are unchanged.
- docs/api/openapi.yaml: info.version 1.19.0. The wanted-state
  description is main's (memory, idle grace, pinned-session hold, start
  order) with this branch's admin-rejected builds in `stop`.
- docs/reference/change-policy.md: main's list, then "template retire",
  then "admin quotas and build reject"; control plane 1.19.0, harness
  1.3.0.
- docs/reference/http-api.md: main's rows (egress records, Retire at
  1.18.0), then the Admin row at 1.19.0.
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md:
  the status line names both main's §6.2/§6.5 parts and this branch's
  quotas and reject.
- packages/control-plane/src/activation.ts: main's buildOfWorker and
  running-worker maps, with endedWithWorker (retired or admin-rejected)
  where main tests for a retired build with a worker.
- packages/control-plane/src/host-handlers.ts: main's file (wantedAnswer,
  egress, start limit, grace), with this branch's rejectedByAdmin in the
  wanted state's ended branch, liveSnapshots skipping rejected builds,
  and `detached` taken for an admin-rejected build.
- packages/control-plane/src/sandbox-handlers.ts: activationLock is
  main's import from activation-lock.ts (its local copy dropped, so no
  duplicate); this branch's templateUseLock stays. Imports carry both
  rejectedByAdmin and main's readinessReasonOf, startQueue,
  startRetryAfterS; identity.js is imported once.
- packages/control-plane/test/activation.test.ts: both new placement
  cases.
- packages/control-plane/test/openapi-contract.test.ts: 31 enrollable
  routes (28 + this branch's 2 + main's 1).
- packages/mocactl/src/sbx/api.ts, commands.ts, cli.ts: both sides'
  types, imports, usage, flags and dispatch (quota and --stop-now).
- packages/mocactl/test/contract.test.ts: 28 replies (25 + 1 + 2), with
  main's reply shape.

Also: activation-lock.ts's comment says, as this branch's code does,
that a reject takes the activation lock and a sandbox create takes only
its template's use lock; http-api.md's "admin routes came with API
1.19.0"; the reject test reads main's wanted answer (starting,
egressSids).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings pr/i26-retire at upstream main d227d41 (through rossoctl#790, with rossoctl#789's
combined plane and pinned-session holds, rossoctl#791/rossoctl#792 egress, rossoctl#784 pacing,
rossoctl#776 memory placement and rossoctl#808), and i26's retire at API 1.18.0. This
branch's removal section moves to 1.19.0.

Conflicts:
- docs/api/CHANGELOG.md: ## 1.19.0 removal above i26's ## 1.18.0 and
  main's sections, which are unchanged. The `remove` bullet names a
  pinned session's hold beside a live sandbox.
- docs/api/openapi.yaml: info.version 1.19.0. The wanted-state
  description is main's (memory, idle grace, pinned-session hold, start
  order), with "in no list", `remove` (since 1.19.0; not under a live
  sandbox or a session's hold) and the shared-build rule; the response
  keeps main's `starting`, `graced` and `egressSids` and adds `remove`.
- docs/reference/change-policy.md: main's list, then "template retire",
  then "retired build removal"; control plane 1.19.0, harness 1.3.0.
- packages/control-plane/src/host-handlers.ts: main moved the wanted
  state into wantedAnswer; `remove` is built there, in the retired
  branch, under main's busyWorkers (a live sandbox or a pinned session's
  hold), and returned beside main's run, stop, starting and graced;
  hostWanted adds egressSids as main does. hostWorkerReport takes
  `removed` on main's version of it (st.running and refused kept); the
  host's holds drop the build on st. The header, liveSnapshots and
  T.unique texts are this branch's.
- packages/control-plane/test/activation.test.ts: the wanted answers
  carry both `remove` and main's `starting`/`egressSids`.
- packages/mocactl/src/sbx/cli.ts: main's usage (sbx hosts, create
  --mode/--idle-timeout) with this branch's retire --wait text.
- deploy/sbx/host-agent.sh: main's header and run loop (run.tsv, start
  limit, grace), then this branch's removal() before the lock is let go;
  REMOVED beside main's counters; summary keeps "removed" before
  "errors" and main's egress, memory, start and grace fields after it.
- deploy/sbx/tests/host-agent.test.sh: both mocks (install-host,
  journalctl) and both settings; main's sections 13-26, then this
  branch's removal section as 27, on a clean srv with well-formed
  snapshots (snapfiles), so main's memory report raises no error.
- deploy/sbx/RUNBOOK.md: main's summary text with "removed".
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md:
  main's records table with this branch's `event: removed`; step 7 names
  a pinned session's hold.

Also moved to 1.19.0: http-api.md's "Since API 1.19.0" and
host-agent.sh's "older than API 1.19.0" comment. activation.test.ts's
live-sandbox removal case reads the answer with toMatchObject: the
wanted state now also carries egressSids, which list the sandbox.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants