carlos / platform Public

region-ha p1b-2: an app's X-Carlos-Holder trailer never reaches the client

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev aa34335b087fa64efa4ac81635279bded3420e57 parent 58c9420
3 files changed, +65 −2
  • internal/edge/cookiescope.go +3 −2
  • internal/edge/forwardha.go +17 −0
  • internal/edge/forwardha_test.go +45 −0

Intent

Human

<task-notification> <task-id>a239b8399dde65d59</task-id> <tool-use-id>toolu_01JxxzUVjZbmtk2YmE1r4KpF</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a239b8399dde65d59.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2: front-door forward" 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. Task 2 is built, tested and committed. **Commit:** 84b52299 `region-ha p1b-2: the edge forwards an HA host's request at the front door` **Tests:** all 8 brief tests pass, and so does the Step 4 regression command; darwin, windows and linux builds and vet are clean. Moving the forward below the meter makes the one-owner test fail in all four parts. Go commands ran with the sandbox off, as the house rules say, because the Go build cache is read-only inside it. **Concerns:** 1. `MarkAnswered` does nothing at the insertion point: the meter attaches the request's outcome later. So the forwarding box never files its own unreachable 503 as an edge error; it only writes a throttled log line. 2. An app on the holder can set `X-Carlos-Holder` itself. Sending "none" on every answer would cost the forwarding box one `lock.json` read per request. Suggest Task 3 strips the app's value on HA routes. 3. Two choices the brief left open: - When this box refuses the hop itself (busy limits), the result is `{ForwardDone, Status 0}`, so the cached holder is kept. - An error after connecting gets the backhaul 502 with `{ForwardDone, 0}`. Only a TCP or TLS failure within 2 s counts as `ForwardUnreachable`. **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b2/.superpowers/sdd/2026-10-29-region-ha-p1b2-forwarding/task-2-report.md</result> <usage><subagent_tokens>227491</subagent_tokens><tool_uses>74</tool_uses><duration_ms>1000567</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>b7d43ddrq</task-id> <tool-use-id>toolu_019qTTih7C64F6tg5cu7iqr1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/b7d43ddrq.output</output-file> <status>completed</status> <summary>Background command "Package Task 2 and run its Astra review" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a239b8399dde65d59</task-id> <tool-use-id>toolu_01CoKMhefFffLwYK3Yt1ykkv</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a239b8399dde65d59.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2: front-door forward" 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. All three review P2s are fixed and committed. **Commits:** 84b52299 (Task 2) and 58c9420e (fixes) - **Holder header:** the hook every app proxy's responses pass through now deletes any `X-Carlos-Holder` the app sets, and so does the 1xx path. The activator's and the edge's own refusals still carry it. - **Compression:** the forward transport sets `DisableCompression: true`, so the holder meters exactly the bytes the client receives. - **HEAD:** the witness now sends a real HEAD. **Tests:** the forward set and the `Backhaul|Hop|Home|Regional|Gate` regression command pass, as do the three builds and vet. - One test rewritten: `TestForwardHAReadsHolderHeader`. A platform refusal keeps its header; an app's header never reaches the client and is reported as Holder "". - One test added: `TestForwardHAHolderMetersTheBytesDelivered`, a 68 KB compressible page fetched with compression off on the client. - Undoing either fix makes its test fail. **Concerns:** none new. The amadan ledger hook warned about a lock file after each commit; both commits landed and the tree is clean. **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b2/.superpowers/sdd/2026-10-29-region-ha-p1b2-forwarding/task-2-report.md (fix round appended)</result> <usage><subagent_tokens>251374</subagent_tokens><tool_uses>14</tool_uses><duration_ms>264455</duration_ms></usage> </task-notification>

Attributed to this commit: 39.6 g CO₂e (5,240,451 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-p1b2-forwarding, 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/internal/edge/cookiescope.go b/internal/edge/cookiescope.go
index 72af4d824..7223ec745 100644
--- a/internal/edge/cookiescope.go
+++ b/internal/edge/cookiescope.go
@@ -74,7 +74,8 @@ func appsDomainFromEnv() string {
// proxy: the Carlos-Purge channel (purgeModifier), the removal of any asset
// cache header or trailer the app set (stripAssetResponseHeaders,
// stripAssetTrailers: the edge's own are set after this, never inherited
-// from the app), the removal of any X-Carlos-Holder the app set, and the
+// from the app), the removal of any X-Carlos-Holder the app set, as a
+// header or a trailer (stripAppHolder), and the
// cookie scoping above, in that order. None depends on another.
//
// X-Carlos-Holder names the box holding an HA host's lease (forwardha.go),
@@ -89,7 +90,7 @@ func (e *Edge) responseModifier(rt registry.Route) func(*http.Response) error {
}
stripAssetResponseHeaders(resp.Header)
stripAssetTrailers(resp)
- resp.Header.Del(holderHeader)
+ stripAppHolder(resp)
e.scopeCookies(rt, resp)
return nil
}
diff --git a/internal/edge/forwardha.go b/internal/edge/forwardha.go
index ea9bd9391..fc8407ec3 100644
--- a/internal/edge/forwardha.go
+++ b/internal/edge/forwardha.go
@@ -69,6 +69,23 @@ type ForwardResult struct {
// it; an app's is removed at the tenant response boundary (responseModifier).
const holderHeader = "X-Carlos-Holder"
+// stripAppHolder removes an app's X-Carlos-Holder from resp at the tenant
+// response boundary (responseModifier): the header, the announced trailer
+// name now, and the trailer value, announced or not, when the body closes,
+// which is when httputil.ReverseProxy has filled resp.Trailer and before it
+// copies it out (stripAssetTrailers' arrangement). A 101 keeps its body: it
+// is the raw connection, and carries no trailers.
+func stripAppHolder(resp *http.Response) {
+ resp.Header.Del(holderHeader)
+ resp.Trailer.Del(holderHeader)
+ if resp.StatusCode == http.StatusSwitchingProtocols || resp.Body == nil {
+ return
+ }
+ resp.Body = &trailerCookieBody{ReadCloser: resp.Body, close: func() {
+ resp.Trailer.Del(holderHeader)
+ }}
+}
+
// forwardDialTimeout bounds connecting to the holder, TCP and TLS together.
// Shorter than backhaulDialTimeout: the holder is in this box's own region,
// and a holder that does not answer in 2 s is treated as gone (the 503 tells
diff --git a/internal/edge/forwardha_test.go b/internal/edge/forwardha_test.go
index 92c6a45bb..36526b817 100644
--- a/internal/edge/forwardha_test.go
+++ b/internal/edge/forwardha_test.go
@@ -149,6 +149,21 @@ func fwApp(t *testing.T, box string) *fwAppServer {
}
w.Header().Set("Retry-After", "1")
http.Error(w, "held", status)
+ case r.URL.Path == "/trailer-holder":
+ // X-Carlos-Holder after the body, beside an ordinary trailer:
+ // announced in a Trailer header, or not (TrailerPrefix).
+ announced := r.URL.Query().Get("announced") == "1"
+ if announced {
+ w.Header().Set("Trailer", "X-Kept, "+holderHeader)
+ }
+ io.WriteString(w, "trailed")
+ w.(http.Flusher).Flush()
+ prefix := ""
+ if !announced {
+ prefix = http.TrailerPrefix
+ }
+ w.Header().Set(prefix+"X-Kept", "1")
+ w.Header().Set(prefix+holderHeader, "carol")
case r.URL.Path == "/big":
w.Header().Set("Content-Type", "text/html; charset=utf-8")
io.WriteString(w, fwBigBody)
@@ -860,6 +875,36 @@ func TestForwardHAReadsHolderHeader(t *testing.T) {
}
}
+// An app's X-Carlos-Holder sent as a trailer, announced or not, never
+// reaches the client and never names a holder; the app's other trailers do.
+func TestForwardHAAppHolderTrailerNeverReachesTheClient(t *testing.T) {
+ x := newFwScene(t, fwOpts{})
+ for i, announced := range []string{"1", "0"} {
+ resp, body := x.fetch(t, fwHost, "/trailer-holder?announced="+announced)
+ if resp.StatusCode != http.StatusOK || body != "trailed" {
+ t.Fatalf("announced=%s: %d %q", announced, resp.StatusCode, body)
+ }
+ if _, ok := resp.Trailer[holderHeader]; ok {
+ t.Fatalf("announced=%s: the client received the %s trailer: %v", announced, holderHeader, resp.Trailer)
+ }
+ for _, v := range resp.Header.Values("Trailer") {
+ if strings.Contains(strings.ToLower(v), strings.ToLower(holderHeader)) {
+ t.Fatalf("announced=%s: the response announces %s: %q", announced, holderHeader, v)
+ }
+ }
+ if v := resp.Header.Values(holderHeader); len(v) != 0 {
+ t.Fatalf("announced=%s: the client received the %s header %q", announced, holderHeader, v)
+ }
+ if got := resp.Trailer.Get("X-Kept"); got != "1" {
+ t.Fatalf("announced=%s: X-Kept trailer = %q, want 1 (trailers %v): trailers must still cross", announced, got, resp.Trailer)
+ }
+ notes := x.aAct.noted()
+ if len(notes) != i+1 || notes[i] != (fwNote{fwHost, ForwardResult{Outcome: ForwardDone, Status: http.StatusOK}}) {
+ t.Fatalf("notes = %+v, want ForwardDone 200 with no holder", notes)
+ }
+ }
+}
+
// The forward relays the encoding the client asked for, so the bytes the
// holder meters are the bytes the client receives: a client that asks for
// no compression gets identity bytes from both boxes.