# Two-Turn Context Shedding and Zero-Port RFC 9110 Edge Architecture

*2026-12-04*

## Executive Summary

Autonomous CLI and Electron coding agents re-bill 200,000-plus token contexts on every loop while combining local credentials, host filesystem privileges, and untrusted inputs in one process. A two-turn browser-sandboxed workflow primes conversational KV-cache with `283,007` architectural index tokens on Turn 1 and sheds `85.7%` (`242,410` narrative tokens) on Turn 2, focusing active `softmax` attention on `~55,000` tokens of live code with zero host-execution risk. Across four AST-verified Git commits (`601829d`, `5bb2cc0`, `d4c2525`, `2197cc1`), this discipline shipped bimodal `RFC 9110` HTML/Markdown content negotiation, `RFC 9111` cache-safe headers, mobile `MediaSession` controls, and zero-PII telemetry without inbound write ports or stream downtime.

## Architecture & Protocol Mechanics

* **Two-Turn KV-Cache Partitioning:** Turn 1 loads a plain-text Table of Contents, keyword index, and architectural history (`283,007` tokens / `901,555` bytes) with code edits locked out, resolving "lost in the middle" attention decay by distilling system topology into conversational KV-cache. Turn 2 drops those `242,410` narrative tokens and isolates `~55,000` tokens of target source inside a browser renderer sandbox, pairing before-and-after CLI probes with small, reversible Git commits instead of ephemeral IDE checkpoints.
* **RFC 9110 Negotiation & RFC 9111 Cache Hygiene:** Shared Nginx `$new_uri` redirect maps shadowed `/stories/` with unintended `HTTP 301` hops. Explicit `= /stories` canonicalization and `^~ /stories/` prefix blocks in declarative NixOS Nginx configuration bypass global redirect maps ahead of `try_files`. Requests presenting `Accept: text/markdown` serve native Markdown alongside `Vary: Accept`, ensuring `RFC 9111` caches partition HTML and Markdown variants cleanly while `nixos-rebuild switch` reloads `nginx.service` in place.
* **Zero-Port Telemetry & MediaSession Controls:** Instead of exposing public write APIs or cookies, an outbound LAN poller ingests live chat commands, hashes channel IDs locally with a `0600` secret salt via `BLAKE2s` (12-hex digest), and syncs compact JSON state over warm `ControlMaster` SSH for `O(1)` `st_mtime_ns` polling. Raw Nginx access logs and SQLite correlation detect OpenAI, Anthropic, and unbadged AI retrieval bots in real time, while static `<audio>` tags bind W3C `navigator.mediaSession` lock-screen controls.

## Verifiable Wire Audit

Session telemetry (`2026-12-04`) verified an `85.7%` prompt reduction (`283,007` to `~55,000` active tokens) across four commits (`50` to `136` replacement lines each) with `PII_LEAK: False` and unbroken 30-minute stream continuity. Live `curl` checks on `sunpug.io` confirm bimodal `RFC 9110` delivery and `RFC 9111` `Vary` headers:

~~~bash
# Canonical slash redirect -> HTTP/2 301, location: https://sunpug.io/stories/
curl -sSI https://sunpug.io/stories | grep -iE '^(http/|location:)'

# Default browser fetch -> HTTP/2 200, content-type: text/html, vary: Accept
curl -sSI https://sunpug.io/stories/ | grep -iE '^(http/|content-type:|vary:)'

# Negotiated Markdown fetch -> HTTP/2 200, content-type: text/markdown, vary: Accept
curl -sSI -H "Accept: text/markdown" https://sunpug.io/stories/ | grep -iE '^(http/|content-type:|vary:)'
~~~

## Decision Criteria

* **Enforce Two-Turn Sandbox Airlocks:** Replace host-privileged agent loops by priming architectural indexes on Turn 1 in a browser sandbox, shedding narrative history on Turn 2, and gating changes behind human-applied, AST-verified Git commits under 150 lines.
* **Serve Bimodal `RFC 9110` Markdown at the Edge:** Audit Nginx and CDN prefix precedence (`^~`) so global redirect maps cannot shadow content hubs, serving `text/markdown` with `RFC 9111` `Vary: Accept` headers to cut AI retrieval overhead.
* **Adopt Zero-Port Sidecar Telemetry:** Eliminate inbound write surfaces and client-side JS trackers by combining outbound API polling, locally salted `BLAKE2s` hashing, and HTTP access-log correlation to audit declared and unbadged AI crawlers with zero PII liability.
* **Decouple Routing Deploys from Stateful Streams:** Ship web-tier changes via declarative OS switches verified by identical before-and-after `curl` probes so edge updates land without dropping active sessions.

---

[← Isolating Headless Crawler /null Floods via RFC 9110 Wire Telemetry](/briefs/metas-headless-crawler-null-404-logs/) · [All Briefs](/briefs/)
