carlos / platform Public

console: journal, not audit, the throttled and unplaced session attempts (rootfs plan 6)

The coordinator's follow-up to the interactive-refused ruling:
- the rate's 429 writes no audit row: it is a flood control, not an
  access decision, and a row per throttled request would turn the limiter
  into database inserts. One journal line per throttled caller per minute.
- the person and membership 404s (no account the caller is placed in)
  cannot go in the audit table: one journal line each, with the caller,
  the account, app and host asked for and the status, at most one per
  caller per minute.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 136e7e2924e4b1a648941eb0d04db2d256ff4f5b parent 6ace84d
4 files changed, +180 −13
  • docs/superpowers/plans/2026-10-24-rootfs-apps-6-interactive.md +1 −1
  • internal/console/apiinteractive.go +81 −4
  • internal/console/apiinteractive_refused_test.go +93 −5
  • internal/console/interactivehub.go +5 −3

Intent

Human

<task-notification> <task-id>a2d94724ff7a5c39f</task-id> <tool-use-id>toolu_01HcQerCsYzs5FDyGo85hmeG</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a2d94724ff7a5c39f.output</output-file> <status>completed</status> <summary>Agent "Plan 6 Task 15: root-runner witness" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status: DONE_WITH_CONCERNS.** All three witnesses pass as root under real systemd on the arm64 root runner. Nothing in Plan 6 failed, so no template or code fix was needed. **Commit:** `6ace84d6` "witness: an interactive session is inside its instance (rootfs plan 6)". It adds two new files, both built only with the `rootrunner` tag: - `internal/host/interactive_rootrunner_linux_test.go` - `internal/activator/witness_rootrunner_linux.go` `make census-card` reports nothing to approve, so I didn't re-propose the overlay. Vet with the tag is clean. I committed only these two files; the other changes in the worktree belong to other agents. **Results** (final run `20261031T211901-0dcebc` on `i-0c7f5de65beff9d4b`, using the brief's regex): | Witness | Result | |---|---| | TestInteractiveSessionIsInsideTheInstance | PASS | | TestInteractiveSessionRefusedWhenTheAppDisallows | PASS | | TestRootfsRunIsInsideTheInstance | PASS | - **Session witness:** assertions 1–7 all pass. Your extra assertion also passes: after the stop, `instance-exit` writes the exit record for both sessions, each unit ends `inactive` with result `success`, and the journal shows no STDIN error or "Failed with result". The handoff socket is gone after the settle. So the Task 5, 7, 8 and 12 rulings hold on real systemd. - **Off witness:** the session ends refused "off", and no tty unit was ever started. - **Rootfs witness:** both probes pass for real, including `pts-private ok` on both. **Concerns:** 1. **The brief's rootfs cgroup line can't hold.** The rootfs templates set `ProtectControlGroups=strict`, which gives the unit its own cgroup namespace, so `/proc/self/cgroup` reads `0::/` inside. The template is correct (the rootfs probe checks it), so there was nothing to fix. The witness instead checks `0::/` inside, and from the box's side that the unit's cgroup under the host's slice held `/bin/witness session-payload rootfs` while it ran. You'll need to rule whether to amend the brief. 2. **The witness doesn't go through `RunCmd`.** `RunCmd` needs an awake instance, and waking one needs the hibernate bucket, which the runner can't reach. So the new `activator.StartCmdServing` passes `StartCmd` the two values `RunCmd` would set (the serving build and its launch environment). Everything from `StartCmd` on is production code. It sits behind the `rootrunner` tag, like `internal/safefile/fault_rootrunner_linux.go`. 3. **Fixture shortcuts:** - Both boxes follow the egress witnesses' pattern: templates installed with their edge and mount dependencies dropped, and the control service run in-process on the real socket. - The rootfs box also installs the three mount units verbatim and starts a stand-in `carlos-edge.service` that only runs `sleep`. Without it the probe fails `cgroup-ro: edge not loaded`. - `ensureSystemUnits` isn't used, because it never installs instance templates. 4. **A systemd log line worth checking on a dev box.** In 4 of 8 one-shot unit starts, systemd logged "Supervising process N which is not our child. We'll most likely not notice when it exits." Every time it still noticed: the unit finished and the exit status was read correctly. It's most likely from `PrivatePIDs=yes`, so it predates Plan 6. Worth a look in a dev box's journal during Step 3. 5. **Runs 2–5 failed on my own rootfs fixture**, not on Plan 6 code: the missing edge, the control service not reporting its build, the box's overlap setting, and the manifest's artifact name. **Instances:** seven runs, all tagged purpose=plan14-root-runner, all terminated by the script, and none left over before or after: - i-067490229be151242 - i-023ffa863f81c1fde - i-0a7a59dcd17a222f6 - i-0805d0bec23c3da94 - i-0c35d897af017f38e - i-0af104e10794503e7 - i-0c7f5de65beff9d4b I've deleted my scratch logs, and nothing I started is still running. The full report, with the log line for each assertion and the run table, is at `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-apps-6/.superpowers/sdd/2026-10-24-rootfs-apps-6-interactive/task-15-report.md` (not committed, since `.superpowers/` is excluded from git).</result> <usage><subagent_tokens>419705</subagent_tokens><tool_uses>149</tool_uses><duration_ms>2233633</duration_ms></usage> </task-notification>

Attributed to this commit: 17.8 g CO₂e (2,366,086 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-apps-6-interactive, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-6-interactive.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-6-interactive.md
index 01ffa76ef..7646c2086 100644
--- a/docs/superpowers/plans/2026-10-24-rootfs-apps-6-interactive.md
+++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-6-interactive.md
@@ -1292,7 +1292,7 @@ After the upgrade:
2. Read the `Open` frame within `OpenWait`. It must pass `Normalized().Check()`, else End refused RFS-6-C36. A `console` process resolves to the argv of `Processes["console"]` in the manifest of the version the record's channel serves, else End refused RFS-6-C33. (Rev 2, Astra R1 P1-2: the resolved argv is used only for this check and the audit row. `hubSession.open` keeps the `Open` exactly as received, `Process: "console"` and no argv, and that is what the box gets, so root runs the declared process with its own env and working directory.)
3. Mint the id and the token, and **reserve the session in the hub** (`s.interactive.reserve(sess)`, finding 10). From here until step 6, every failure releases the reservation (`release(id)`, deferred and disarmed by a successful `activate`), and the steps' store calls run under a context bounded by `interactive.OpenWait`, so a reservation never outlives its admission.
4. Sign the grant (Attach is `interactive.AttachURL(s.cfg.Origin, id)`) and `Put` it at `GrantKey`.
-5. Admit on the record (`Console: s.bootID`, `PickupBy: now+60s`, `Live: func(st provision.InteractiveState) bool { return s.interactive.live(st, s.bootID) }`). Because the id is already reserved, any other admission on this console that reads this marker, from the moment the CAS lands, finds it live and is refused with RFS-6-C32; a session of another console boot is dead by `Console`, as before. A refusal deletes the grant, releases the reservation and ends with its sentence. (Paul's ruling, 2026-10-31, superseding "writes no audit row": every refusal of a caller the door has placed in the account, before the upgrade or after it, writes one `interactive-refused` audit row through `s.auditActivity`, `TargetType` instance, `Target` the host, `Detail` JSON: the requested argv or process, the HTTP status before the upgrade, the refusal code and the sentence sent. It is the console's own database, so no store request is added. An unauthenticated request stays unlogged: the auth layer answers 401 before the door. So do the person and membership 404s, which have not placed the caller in an account, and a host-claim console's RFS-6-C35, where an app's SQL write is admitted through the claim's bucket objects.)
+5. Admit on the record (`Console: s.bootID`, `PickupBy: now+60s`, `Live: func(st provision.InteractiveState) bool { return s.interactive.live(st, s.bootID) }`). Because the id is already reserved, any other admission on this console that reads this marker, from the moment the CAS lands, finds it live and is refused with RFS-6-C32; a session of another console boot is dead by `Console`, as before. A refusal deletes the grant, releases the reservation and ends with its sentence. (Paul's ruling, 2026-10-31, superseding "writes no audit row": every refusal of a caller the door has placed in the account, before the upgrade or after it, writes one `interactive-refused` audit row through `s.auditActivity`, `TargetType` instance, `Target` the host, `Detail` JSON: the requested argv or process, the HTTP status before the upgrade, the refusal code and the sentence sent. It is the console's own database, so no store request is added. An unauthenticated request stays unlogged: the auth layer answers 401 before the door. So do a host-claim console's RFS-6-C35, where an app's SQL write is admitted through the claim's bucket objects, and the rate's 429, a flood control rather than an access decision. The 429, the person 404 and the membership 404 (no account the caller is placed in) each write a journal line instead (log.Printf: the caller, the account, app and host asked for, and the status), at most one per caller per minute.)
6. `activate(id)` (the hub's `afterAdmit` seam runs just before it), bump the serial, write the `interactive-start` audit row (`Detail` JSON: id, argv, process, version), and send Status `waiting`.
7. Wait for the box until `PickupBy`, else End expired, ending as below.
8. The CLI closing before the box attaches ends the session as cancelled.
diff --git a/internal/console/apiinteractive.go b/internal/console/apiinteractive.go
index 6f320691b..7dc76ef4e 100644
--- a/internal/console/apiinteractive.go
+++ b/internal/console/apiinteractive.go
@@ -27,6 +27,7 @@ import (
"log"
"net/http"
"os"
+ "sync"
"sync/atomic"
"time"
@@ -87,15 +88,21 @@ type interactiveDoor struct {
// refuseSession after it. The person and membership 404s write none: the
// door has not placed the caller in the account, and an unauthenticated
// request never reaches the door (the auth layer's 401). Nor does the
-// host-claim console's refusal (see there).
+// host-claim console's refusal (see there), nor the rate's 429, a flood
+// control rather than an access decision. The person and membership
+// refusals and the 429 each write a journal line instead, at most one per
+// caller per minute.
func (s *Server) handleAPIInteractive(w http.ResponseWriter, r *http.Request) {
p, ok := principalFrom(r.Context())
if !ok || p.Kind != PrincipalUser {
+ s.journalUnplaced(r, p, http.StatusNotFound)
http.NotFound(w, r)
return
}
- actor, acct, app, ok := s.apiAccountApp(w, r)
+ sw := &statusWriter{ResponseWriter: w}
+ actor, acct, app, ok := s.apiAccountApp(sw, r)
if !ok {
+ s.journalUnplaced(r, p, sw.status)
return
}
host := r.PathValue("host")
@@ -111,8 +118,13 @@ func (s *Server) handleAPIInteractive(w http.ResponseWriter, r *http.Request) {
jsonError(w, http.StatusConflict, claimInteractiveUnsupportedMsg)
return
}
- if !s.cli.instances.allow(hashToken(bearer(r)), time.Now()) {
- refuse(http.StatusTooManyRequests, runTooManyMsg)
+ if now := time.Now(); !s.cli.instances.allow(hashToken(bearer(r)), now) {
+ // No row: a row per throttled request would turn the limiter into
+ // database inserts.
+ if s.interactive.journal.allow("throttled "+actor, now) {
+ log.Printf("console: api interactive: throttled %s on %s/%s/%s: %d", actor, acct.Sqid, app, host, http.StatusTooManyRequests)
+ }
+ jsonError(w, http.StatusTooManyRequests, runTooManyMsg)
return
}
if s.cfg.Releases == nil {
@@ -175,6 +187,71 @@ func (s *Server) handleAPIInteractive(w http.ResponseWriter, r *http.Request) {
}).ServeHTTP(w, r)
}
+// journalUnplaced writes the journal line of a refusal the audit table
+// cannot hold (no account the caller is placed in): the caller, the
+// account, app and host asked for, and the status. At most one per caller
+// per minute.
+func (s *Server) journalUnplaced(r *http.Request, p Principal, status int) {
+ caller := "an unidentified caller"
+ switch {
+ case p.Kind == PrincipalUser && p.Address != "":
+ caller = p.Address
+ case p.Kind == PrincipalService:
+ caller = fmt.Sprintf("service %s (credential %s)", p.Name, p.CredentialID)
+ }
+ if !s.interactive.journal.allow("unplaced "+caller, time.Now()) {
+ return
+ }
+ log.Printf("console: api interactive: refused %s on %s/%s/%s: %d", caller, r.PathValue("account"), r.PathValue("app"), r.PathValue("host"), status)
+}
+
+// statusWriter keeps the status a refusal before the upgrade answered.
+type statusWriter struct {
+ http.ResponseWriter
+ status int
+}
+
+func (w *statusWriter) WriteHeader(code int) {
+ if w.status == 0 {
+ w.status = code
+ }
+ w.ResponseWriter.WriteHeader(code)
+}
+
+func (w *statusWriter) Write(b []byte) (int, error) {
+ if w.status == 0 {
+ w.status = http.StatusOK
+ }
+ return w.ResponseWriter.Write(b)
+}
+
+// journalOnce lets one journal line through per key per minute. Keys idle
+// for a minute are dropped, so it holds only the last minute's callers.
+type journalOnce struct {
+ mu sync.Mutex
+ last map[string]time.Time
+}
+
+const journalEvery = time.Minute
+
+func (j *journalOnce) allow(key string, now time.Time) bool {
+ j.mu.Lock()
+ defer j.mu.Unlock()
+ if t, ok := j.last[key]; ok && now.Sub(t) < journalEvery {
+ return false
+ }
+ if j.last == nil {
+ j.last = map[string]time.Time{}
+ }
+ for k, t := range j.last {
+ if now.Sub(t) >= journalEvery {
+ delete(j.last, k)
+ }
+ }
+ j.last[key] = now
+ return true
+}
+
// serveInteractive is the session after the upgrade, on the CLI's
// connection, until it ends.
func (s *Server) serveInteractive(rctx context.Context, ws *websocket.Conn, d interactiveDoor) {
diff --git a/internal/console/apiinteractive_refused_test.go b/internal/console/apiinteractive_refused_test.go
index da042fc75..710f362d5 100644
--- a/internal/console/apiinteractive_refused_test.go
+++ b/internal/console/apiinteractive_refused_test.go
@@ -10,7 +10,9 @@ import (
"context"
"encoding/json"
"errors"
+ "log"
"net/http"
+ "net/http/httptest"
"sort"
"strings"
"sync"
@@ -83,7 +85,7 @@ func TestEveryRefusalWritesOneRefusedRow(t *testing.T) {
host string
setup func(*testing.T, *interactiveFx)
lt bool // on the lifetimes fixture
- noRow bool // the one refusal that writes none
+ noRow bool // a refusal that writes none
open *interactive.Open // nil: refused before the upgrade
status int // before the upgrade
refused string // after it
@@ -96,10 +98,12 @@ func TestEveryRefusalWritesOneRefusedRow(t *testing.T) {
// go through the claim's bucket objects (TestClaimConsoleMutationInvariant).
{name: "host claims", setup: func(_ *testing.T, fx *interactiveFx) { fx.srv.cfg.HostClaim = true },
status: http.StatusConflict, msg: claimInteractiveUnsupportedMsg, noRow: true},
+ // Nor does the rate's, a flood control: its journal line is
+ // TestUnplacedCallersWriteNoRefusedRow's.
{name: "rate", setup: func(_ *testing.T, fx *interactiveFx) {
fx.srv.cli.instances = newRateLimiter(1, cliRateWindow)
fx.srv.cli.instances.allow(hashToken(fx.alice), time.Now())
- }, status: http.StatusTooManyRequests, msg: runTooManyMsg},
+ }, status: http.StatusTooManyRequests, msg: runTooManyMsg, noRow: true},
{name: "no bucket", setup: func(t *testing.T, fx *interactiveFx) {
rel := fx.srv.cfg.Releases
fx.srv.cfg.Releases = nil
@@ -224,12 +228,21 @@ func TestEveryRefusalWritesOneRefusedRow(t *testing.T) {
// TestUnplacedCallersWriteNoRefusedRow: the door audits only a caller it has
// placed in the account. No credential and a bad one get the auth layer's
-// 401; a service credential the mux's closed door; a stranger the
-// byte-identical 404. None of them writes a row.
+// 401, before the door; a service credential the mux's closed door; a
+// stranger the byte-identical 404; a throttled member the 429. None of them
+// writes a row. The stranger, a principal that is not a person (the
+// handler's own 404) and the throttled member each get one journal line
+// per minute however often they try.
func TestUnplacedCallersWriteNoRefusedRow(t *testing.T) {
fx := newIxFx(t, "code-ix-unplaced")
+ logs := &lockedLog{}
+ prev := log.Writer()
+ log.SetOutput(logs)
+ t.Cleanup(func() { log.SetOutput(prev) })
stranger := cliToken(t, fx.consoleFixture, "mallory@keymail.dev", "code-ix-unplaced-stranger")
svc := serviceToken(t, fx.st, fx.acctID, "ci-admin", "shop", "admin")
+ fx.srv.cli.instances = newRateLimiter(1, cliRateWindow)
+ fx.srv.cli.instances.allow(hashToken(fx.alice), time.Now())
for _, c := range []struct {
name, token string
status int
@@ -238,20 +251,95 @@ func TestUnplacedCallersWriteNoRefusedRow(t *testing.T) {
{"a bad credential", "not-a-token", http.StatusUnauthorized},
{"a service credential", svc, http.StatusForbidden},
{"a stranger", stranger, http.StatusNotFound},
+ {"a stranger again", stranger, http.StatusNotFound},
+ {"throttled", fx.alice, http.StatusTooManyRequests},
+ {"throttled again", fx.alice, http.StatusTooManyRequests},
} {
if code, _, out := ixGet(t, fx, ixHost, c.token); code != c.status {
t.Errorf("%s: %d %s, want %d", c.name, code, out, c.status)
}
}
+ // A principal that is not a person, past the mux: the handler's 404.
+ svcP, ok := fx.st.CLIPrincipal(svc, time.Now())
+ if !ok || svcP.Kind != PrincipalService {
+ t.Fatalf("the service credential resolves to %+v", svcP)
+ }
+ for range 2 {
+ req := httptest.NewRequest(http.MethodGet, fx.ixURL(ixHost), nil)
+ req.SetPathValue("account", fx.acct)
+ req.SetPathValue("app", "shop")
+ req.SetPathValue("host", ixHost)
+ req = req.WithContext(context.WithValue(req.Context(), cliRouteKey{}, svcP))
+ rec := httptest.NewRecorder()
+ fx.srv.handleAPIInteractive(rec, req)
+ if rec.Code != http.StatusNotFound {
+ t.Fatalf("not a person: %d", rec.Code)
+ }
+ }
evs, err := fx.st.Events(fx.acctID, "shop", 200)
if err != nil {
t.Fatal(err)
}
for _, e := range evs {
if strings.HasPrefix(e.Action, "interactive-") {
- t.Fatalf("an unplaced caller wrote %+v", e)
+ t.Fatalf("an unplaced or throttled caller wrote %+v", e)
+ }
+ }
+ where := fx.acct + "/shop/" + ixHost
+ for _, want := range []string{
+ "console: api interactive: refused mallory@keymail.dev on " + where + ": 404",
+ "console: api interactive: refused service ci-admin (credential " + svcP.CredentialID + ") on " + where + ": 404",
+ "console: api interactive: throttled alice@keymail.dev on " + where + ": 429",
+ } {
+ if n := strings.Count(logs.String(), want); n != 1 {
+ t.Errorf("%d journal lines %q, want 1:\n%s", n, want, logs.String())
+ }
+ }
+ if strings.Contains(logs.String(), "unidentified") {
+ t.Errorf("a 401 reached the door:\n%s", logs.String())
+ }
+}
+
+func TestTheDoorsJournalSpeaksOncePerCallerPerMinute(t *testing.T) {
+ var j journalOnce
+ t0 := time.Now()
+ for _, c := range []struct {
+ key string
+ at time.Duration
+ want bool
+ }{
+ {"a", 0, true}, {"a", 59 * time.Second, false}, {"b", 59 * time.Second, true},
+ {"a", time.Minute, true}, {"a", time.Minute + time.Second, false},
+ } {
+ if got := j.allow(c.key, t0.Add(c.at)); got != c.want {
+ t.Fatalf("%s at %v: %v, want %v", c.key, c.at, got, c.want)
}
}
+ if n := len(j.last); n != 2 {
+ t.Fatalf("%d keys held, want 2", n)
+ }
+ j.allow("c", t0.Add(3*time.Minute))
+ if n := len(j.last); n != 1 {
+ t.Fatalf("%d keys held after the others went idle, want 1", n)
+ }
+}
+
+// lockedLog is a journal a test reads while the server writes it.
+type lockedLog struct {
+ mu sync.Mutex
+ buf strings.Builder
+}
+
+func (l *lockedLog) Write(p []byte) (int, error) {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ return l.buf.Write(p)
+}
+
+func (l *lockedLog) String() string {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ return l.buf.String()
}
// TestARefusedAttemptAddsNoStoreRequest: the interactive-refused row is the
diff --git a/internal/console/interactivehub.go b/internal/console/interactivehub.go
index 08842929c..63f4a6582 100644
--- a/internal/console/interactivehub.go
+++ b/internal/console/interactivehub.go
@@ -42,9 +42,11 @@ import (
// session (activeSession), so an ended id and an unknown one get the same
// 404.
type interactiveHub struct {
- mu sync.Mutex
- byID map[string]*hubSession // reserved or active
- byHost map[string]string // host -> its active session's id
+ // journal limits the door's unaudited journal lines (apiinteractive.go).
+ journal journalOnce
+ mu sync.Mutex
+ byID map[string]*hubSession // reserved or active
+ byHost map[string]string // host -> its active session's id
// ended is each ended id and when it may be pruned: its PickupBy.
ended map[string]time.Time
// ending is every ended id whose end step's writes are in flight.