Repeated Wakes and Prompt Layers
Learning Headroom
Why Wakes Need Layers
**Core idea**
Put byte-stable content first, then place changing wake information after it.
```mermaid
flowchart LR
A["Repeated wake"] --> B["Stable prefix"]
A --> C["Live wake digest"]
A --> D["Run-specific context"]
B --> E["Cacheable again"]
C --> F["Can change safely"]
D --> F
```
The Four Wake Layers
**Wake decomposition**
\[W_r = I \;\Vert\; T_r \;\Vert\; D_r \;\Vert\; C_r\]
**Small example**
Given \(I=\texttt{Rules:v3|}\) and \(T_1=T_2=\texttt{Task:sort|}\), the shared prefix is \(\texttt{Rules:v3|Task:sort|}\). Later digest and context fields may differ.
Fully Worked Wake Example
**Compare two wakes**
The rules, tools, and task match exactly. The digest changes from step 4 to step 5, so the shared prefix ends before the digest: \(I\;\Vert\;T\).
Detecting Drift, Not Repairing It
**Read the report**
The current prefix measures 96 bytes and has hash H two-a-seven. The previous hash was H one-nine-c, so the prefix changed. The detector reports this; the caller must move the volatile field.
```mermaid
flowchart LR
A["Assemble messages"] --> B["CacheAligner inspects"]
B --> C["Warnings and metrics"]
C --> D{"Drift detected?"}
D -- No --> E["Keep layout"]
D -- Yes --> F["Caller fixes assembly"]
F --> A
```
A Reliable Decomposition Routine
```mermaid
flowchart TD
A["Inspect a wake field"] --> B{"Does it encode rules or contracts?"}
B -- Yes --> I["Stable instruction layer"]
B -- No --> C{"Does it tell the agent the current task?"}
C -- Yes --> T["Task layer"]
C -- No --> D{"Is it a changing per-wake summary?"}
D -- Yes --> V["Volatile digest layer"]
D -- No --> R["Run-specific context layer"]
```
**One-byte boundary change**
`Task:compress log|` repeats exactly, so it can remain in the shared prefix. `Task:compress logs|` contains one extra letter, so the task field is no longer identical for that comparison.
Back to course