Sliding Window and Cold Wave: When Agent Context Explodes and You Need to Archive Without Losing
Published on 26 April 2026
Summary
After 48 sessions on a single project and 150+ in total, the Eager/Lazy governance system I had carefully built began to choke. The agent files, meant to be light, weighed 5200 cumulative lines. The auto-loaded context was growing faster than my ability to control it. This article tells how I conceptualized a backup mechanism — between a sliding window and an identical cold wave — to maintain a light active context without ever losing anything.
The Signal: 5200 Lines
I am in the middle of session 048 on`magic-stick`, my project to build a live Linux ISO. Opencode is watching me. As always, it automatically loaded my Eager files at the start of the session —AGENT.adoc, PROMPT_REPRISE.adoc, .agents/INDEX.adoc. Nothing unusual.
Except that something is wrong. The responses are slower. The reasoning is more diluted. The agent forgets details that were right in front of it two messages ago.
I open a terminal and type:
wc -l .agents/INDEX.adoc .agents/SESSIONS_HISTORY.adoc \
.agents/archives/COMPLETED_TASKS_ARCHIVE_2026-04.adoc
260 lines for INDEX. 55 for SESSIONS_HISTORY.1756 for COMPLETED_TASKS_ARCHIVE.
The`sessions/`folder adds another ~3200 lines. Total:5200 linesof context loading, one way or another, into the agent’s temporary brain.
The Eager/Lazy strategy I theorized in the previous article works — but it has a birth defect I hadn’t anticipated: it hasno aging mechanism. Every session adds a line to INDEX, a paragraph to COMPLETED_TASKS, a file in sessions/. Nothing ever leaves. The context is a snowball that grows with every new session.
This is not a bug; it is a direct consequence of the end-of-session procedure that meticulously archives every detail. The system is a victim of its own success.
The Diagnosis: Triple Redundancy
I ask the agent to diagnose the problem. Its response is immediate and surgical.
File |
Lines |
Role |
Problem |
|
260+ |
EAGER (auto-loaded) |
Table of all sessions since 001 —+1 line per session |
|
55 |
EAGER |
Summary table —redundancy with INDEX |
|
1756 |
EAGER (implicit) |
Full details of all April sessions |
|
~5200 total |
LAZY (supposed) |
Individual archives, butnot usedbecause everything is already in COMPLETED_TASKS |
The agent identifies four root causes:
-
COMPLETED_TASKS_ARCHIVE absorbs everything— Instead of pointing to the`.sessions/`archives, it fully copies each session.
-
INDEX.adoc acts as a full history— The "Recent Sessions" table contains 30+ entries.
-
SESSIONS_HISTORY.adoc is redundant— Same info as INDEX, different format.
-
The LAZY rule is not respected— COMPLETED_TASKS is implicitly EAGER because it contains everything.
Its proposal is radical: limit INDEX to 10 sessions, empty COMPLETED_TASKS, move SESSIONS_HISTORY to pure LAZY. Immediate gain:~1900 lines saved.
It’s clean, efficient, logical. But I have a problem with this approach.
Why I Refused the Obvious Solution
The agent’s solution is that of an engineer optimizing a cache. Limit. Truncate. Remove redundancies.
But these "redundancies" are not redundancies. Each governance file captures adifferent angleon the same reality:
-
INDEX= macro view, executive dashboard
-
SESSIONS_HISTORY= linear chronological table, scored
-
COMPLETED_TASKS_ARCHIVE= detailed narrative with metrics
-
sessions/*.adoc = individual archives, full context
This is not mindless duplication. This isstructured multiple perspective. This is exactly what is needed for distillation — so that later, a human (or a future better-trained LLM) can cross-reference angles and extract patterns.
Imagine a data scientist telling you: "Let’s delete 3 out of 6 columns, they are correlated." What do you tell them? That correlation is not redundancy when each column captures a different dimension of the same phenomenon. That this dimensional richness is precisely what makes the dataset exploitable.
This is my intuition. And I defend it against the agent’s cold rationality.
_ I don’t see a silent "catch-all" in my idea. We aren’t throwing everything in; we are moving the structured result of the end-of-session procedure — each file with its angle, its redundancies which are actually an enrichment. This multidimensional material will be better for distillation. _
The agent takes the hit. And corrects itself.
The Proposal: Identical Cold Wave
The agent then proposes a finer mechanism, which respects my intuition of a rich dataset while solving the technical problem of exploding context.
The principle is simple and directly inspired by theHot/Warm/Cold Storagepattern applied to archive management:
-
Hot (EAGER)= last 10 sessions in INDEX, PROMPT_REPRISE of session N+1, last 2 session files
-
Warm (LAZY)= recent SESSIONS_HISTORY, SCRIPT_VERIFICATION, all reference documentation
-
Cold (backup/)= everything else, movedintact, without transformation, without re-indexing
----
.agents/
├── INDEX.adoc → Sessions N-9 à N (10 dernières)
├── SESSIONS_HISTORY.adoc → Sessions N-9 à N
├── SCRIPT_VERIFICATION.adoc → Dernière vérif (pas d'historique)
├── PROMPT_REPRISE.adoc → Session N+1 uniquement
├── sessions/ → Sessions N-1 à N uniquement
└── backup/
└── Y2026-sessions-001-039/ ← Vague froide, COPIE INTÉGRALE
├── INDEX.adoc → Sessions 001 à 039 (complet)
├── SESSIONS_HISTORY.adoc → Sessions 001 à 039 (complet)
├── COMPLETED_TASKS_ARCHIVE.adoc → Sessions 001 à 039 (complet)
└── sessions/ → 001.adoc, 002.adoc...
----
The key to the mechanism:**the backup is not a central index, it is a faithful copy of the past wave**. When we exceed the 10-active-session horizon, we delete nothing. We re-index nothing. We merge nothing. We take the packet of agent files as they were at session N-10, and we move them to`backup/`.
The active files, however, are truncated:
* INDEX: only the last 10 lines (sliding window)
* SESSIONS_HISTORY: same
* COMPLETED_TASKS_ARCHIVE: new file for the current period
* sessions/: only the last 2 sessions
[plantuml, format=svg, id=diag-hot-warm-cold, alt="Architecture Hot/Warm/Cold du contexte agent — EAGER/LAZY/backup"]
----
@startuml
skinparam backgroundColor #FEFEFE
skinparam defaultTextAlignment center
skinparam wrapWidth 200
title Architecture Hot / Warm / Cold du Contexte Agent
package "HOT (EAGER)\nChargé automatiquement\n~300 lignes" as HOT #FFCDD2 {
file "INDEX.adoc\n(10 sessions)" as IDX_HOT
file "PROMPT_REPRISE\n(session N+1)" as PRO_HOT
file "AGENT.adoc\n(règles absolues)" as AG_HOT
}
package "WARM (LAZY)\nChargé sur demande\n~500 lignes" as WARM #FFF9C4 {
file "SESSIONS_HISTORY\n(10 dernières)" as HIS_WARM
file "SCRIPT_VERIFICATION\n(dernière)" as VER_WARM
file "PROCEDURES.adoc\n(templates)" as PRO_WARM
file "*_REFERENCE.adoc\n(doc technique)" as REF_WARM
}
package "COLD (backup/)\nJamais chargé\nLecture humaine uniquement" as COLD #BBDEFB {
folder "Y2026-001-039/" as WAVE {
file "INDEX (complet)" as IDX_COLD
file "SESSIONS_HISTORY\n(complet)" as HIS_COLD
file "COMPLETED_TASKS\n(complet)" as ARCH_COLD
folder "sessions/ (001-039)" as SESS_COLD
}
folder "Y2026-040-???\n(future)" as FUTURE
}
HOT --> WARM : "Agent remonte\nsi besoin"
WARM --> COLD : "Jamais automatique\nL'humain y va seul"
note bottom of COLD
Règle : COPIE INTÉGRALE
Pas de transformation
Pas de réindexation
Read-only après archivage
end note
@enduml
----
The immediate gain is massive: the EAGER context goes from**~5200 lines to ~300 lines**. A division by 17. Without having lost a single line of historical data.
== Why This Is Not a Catch-All
The agent, in its first iteration, feared that`backup/`would become a black box — a folder where files are thrown and never read again. This is a legitimate fear. But it is based on a confusion.
A catch-all is when you throw files**without structure, without convention, without grouping logic**. Here, the backup is structured by period (Y2026-001-039), and each backup folder contains**the same structure**as the`.agents/`active folder: INDEX, SESSIONS_HISTORY, COMPLETED_TASKS_ARCHIVE, sessions/.
This is not a catch-all. It is a**timestamped snapshot**. One could even say it is a simplified versioning mechanism — with the caveat that it doesn't version files individually, but the entire governance packet at time T.
When you want to find old information, you don't need a central index. You have two options:
1. **Targeted `grep`**:`grep -r "zsh" backup/Y2026-001-039/`— and you find everything that mentions zsh in that period, regardless of the angle (INDEX, SESSIONS_HISTORY, session archive).
2. **Manual reintegration**: you temporarily copy the backup folder into the active context, and you ask the agent to analyze that specific period.
The index is implicit. It is in the very structure of the files — each being already an index from its own angle.
== The Shelving Metaphor
To make the mechanism intuitive, I conceptualized it as three shelves:
* **Shelf 1 (EAGER)**— the workbench. What I need *now*. Recent INDEX, PROMPT_REPRISE, absolute rules. Light, immediate, critical.
* **Shelf 2 (LAZY)**— the reference library. What I can go look for on demand. Technical references, recent history, procedures. More voluminous, but not loaded into memory.
* **Basement (backup/)**— the cold archives. Everything that is past but that I don't want to throw away. The agent never enters. The human goes down when they want to distill.
The agent initially proposed a fourth shelf — a`index-backup.adoc`that would be LAZY and contain a table of contents for the entire backup. I refused. That would be one more redundancy in a system already suffering from linear growth. The structure of the archived files is already an index.
== The Two-Trigger Sensor
The conceptualization was solid, but one blind spot remained:**when exactly to trigger the rotation?**The initial article identified this as an open question. Two days later, the answer is codified in the governance files of six projects: a two-trigger sensor.
=== The Automatic Trigger — `N % 10 == 0`
The first trigger is mathematical. When the session number is a multiple of 10 — session 10, 20, 30, 40 — the backup rotation executes automatically within the end-of-session procedure, just after step 6.
Why 10? It is the compromise between two opposing forces: a window too short (5 sessions) loses the context necessary for continuity; a window too long (20 sessions) does not solve the context bloating problem. Ten sessions, at a rate of one to two sessions per day, cover about a week of work — enough for the agent to remember recent decisions, not enough for the context to explode.
=== The Threshold Trigger — 500 EAGER Lines
The second trigger is dynamic. Regardless of the session number, if the cumulative EAGER files exceed**500 lines**, the rotation triggers.
This threshold protects against the scenario where sessions are exceptionally productive — a lot of content written in few sessions. A session producing 120 lines of editorial content makes COMPLETED_TASKS_ARCHIVE grow much faster than a debug session correcting two lines. The 500-line threshold, measured via`wc -l .agents/INDEX.adoc .agents/archives/COMPLETED_TASKS_ARCHIVE_*.adoc PROMPT_REPRISE.adoc`, captures this asymmetry.
=== The Manual Trigger — "rotation backup"
Finally, the human keeps control. The keywords`rotation backup`, `backup rotation` ou `lance la rotation backup`trigger the procedure on demand, regardless of the end of the session. Useful when you feel the context is becoming heavy but you aren't yet at a multiple of 10, or when you want to archive a work phase before starting a new one.
[plantuml, format=svg, id=diag-capteur-trigger, alt="Les trois déclencheurs du capteur de rotation backup — automatique, seuil, manuel"]
----
@startuml
skinparam backgroundColor #FEFEFE
skinparam defaultTextAlignment center
skinparam wrapWidth 200
title Capteur de Rotation Backup — Les Trois Déclencheurs
start
:Procédure de fin de session;
note right: Mots-clés "fin de session"\nou "on arrête là"
:Étapes 1 à 6\n(archivage standard);
note right
1. Archive sessions/N.adoc
2. MAJ PROMPT_REPRISE
3. MAJ SESSIONS_HISTORY
4. MAJ INDEX.adoc
5. MAJ TEST_COVERAGE
6. MAJ COMPLETED_TASKS
end note
if (N % 10 == 0\nOU\nEAGER cumulé > 500 lignes ?) then (oui)
:⚙️ Rotation Backup\n(étape 7);
note right
1. Créer backup/Y20XX-sessions-X-Y/
2. Copier intégrale INDEX + HISTORY
+ COMPLETED_TASKS + sessions/
3. Tronquer actifs à 10 sessions
4. Ajouter _Localisation active_
end note
else (non)
:Pas de rotation;
endif
:Checklist [✅] x 7\n(si applicable);
stop
@enduml
----
This diagram shows the exact insertion of the sensor into the end-of-session procedure. Step 7 is optional — it only executes if one of the two conditions is true — but it is systematically *checked*. The final checklist includes`[✅] 7. Backup roté (si applicable)`.
=== The Closed Loop
This sensor closes the loop opened by the previous article. Eager/Lazy governance solved the agent memory problem between two sessions. The Hot/Warm/Cold mechanism solved the problem of growing memory. The two-trigger sensor solves the *when* problem — removing the mental load of monitoring context size from the human.
[plantuml, format=svg, id=diag-boucle-fermee, alt="Les trois couches de la gouvernance agent — Eager/Lazy, Hot/Warm/Cold, Capteur"]
----
@startuml
skinparam backgroundColor #FEFEFE
skinparam defaultTextAlignment center
title Les Trois Couches de la Gouvernance Agent
left to right direction
package "Couche 1 — Mémoire\n(Article 0108)" as C1 #E8F5E9 {
rectangle "**EAGER**\nTableau de bord\nChargé auto" as EAG
rectangle "**LAZY**\nManuel propriétaire\nChargé sur demande" as LAZ
EAG -[hidden]right-> LAZ
}
package "Couche 2 — Vieillissement\n(Article 0110)" as C2 #FFF9C4 {
rectangle "**HOT**\n10 sessions actives\n~300 lignes" as HOT
rectangle "**WARM**\nRéférences\nProcédures" as WRM
rectangle "**COLD**\nbackup/\nVague froide" as CLD
HOT -[hidden]right-> WRM
WRM -[hidden]right-> CLD
}
package "Couche 3 — Déclencheur\n(Aujourd'hui)" as C3 #BBDEFB {
rectangle "**Auto**\nN % 10 == 0" as AUTO
rectangle "**Seuil**\n> 500 lignes" as SEUIL
rectangle "**Manuel**\nrotation backup" as MAN
AUTO -[hidden]right-> SEUIL
SEUIL -[hidden]right-> MAN
}
C1 --> C2 : "La mémoire grandit\n→ il faut un mécanisme\nde vieillissement"
C2 --> C3 : "Le vieillissement\n→ il faut un déclencheur\npour l'exécuter"
note bottom of C3
✅ Déployé sur 6 projets
magic-stick · bakery-gradle
plantuml-gradle · cheroliv.com
jhipster-gradle-plugins
quizz-benchmark-gradle
end note
@enduml
----
The three layers stack logically. The first gives the agent a memory. The second prevents this memory from choking the agent. The third automates the maintenance of this memory so the human doesn't have to think about it.
=== Effective Migration on cheroliv.com
The mechanism did not remain theoretical. On`cheroliv.com`, the first backup rotation was executed on April 29, 2026 — sessions -6 to 2 migrated to`.agents/backup/Y2026-sessions-neg6-a-002/`:
|===
|File |Before rotation |After rotation |Gain |`.agents/INDEX.adoc` |19 sessions listed |10 sessions (3-12) |-9 entries |`.agents/SESSIONS_HISTORY.adoc` |18 sessions |10 sessions |-8 entries |`COMPLETED_TASKS_ARCHIVE` |161 lines (sessions 1-12) |135 lines (sessions 3-12) |-26 lines |`sessions/` |20 files |10 files |-10 files |**backup/** |Non-existent |1 cold wave (10 sessions archived) |+1 cold packet
|===
The line gain was modest — the project is young, 12 sessions — but the important thing is that the**mechanism is in place**. The next automatic rotation will trigger at session 20, or sooner if 500 EAGER lines are reached.
== The Human-Agent Lesson
This session 048 taught me something fundamental about collaborating with an AI agent.
The agent has a natural bias: it seeks to**optimize**, à **simplify**, à **eliminate redundancies**. This is the bias of a system trained to produce clean and concise responses. Faced with a rich and multidimensional dataset, its first reflex is to reduce it to its simplest expression.
The human, however, has a different intuition: they sense that structured redundancy is an**asset**, not a flaw. That the diversity of angles on the same reality is precisely what will allow high-quality distillation later.
It's not that the agent is wrong. It's that its "optimum" is not mine. The agent optimizes for the**present**— the immediate context, the quick answer to the question asked. The human optimizes for the**future**— the ability to retrieve, cross-reference, and distill in three months or three years.
____ What I want is the raw material. Your reflections, your hesitations, your answers to my questions. Not your synthesis. I know how to synthesize better than you. I want the raw matter. ____
This sentence I said to it at the end of the session summarizes everything. The agent is a production tool. The human is the distillation tool. Governance is not made so the agent understands everything on its own — it is made so the human can, later, work the produced material.
The identical cold wave is the architectural translation of this philosophy: we throw nothing away, we merge nothing, we re-index nothing. We move the packet intact. Distillation will come later, by hand, by the human.
== The Logical Sequel to the Previous Article
If you have readlink:/blog/2026/0108_gouvernance_agent_opencode_eager_lazy_post.html[the article on the Eager/Lazy strategy], you will recognize the natural progression:
1. **Article 0108**— Eager/Lazy governance: *how* to structure agent context into two levels of availability
2. **This article 0110**— The backup mechanism: *how* to age this context without losing it when it becomes too voluminous
The first article answered the question: "The agent remembers nothing between two sessions, how do we give it a memory?"
This one answers the question that inevitably follows the first: "The memory grows every session, how do we prevent it from choking the agent without erasing it?"
The answer lies in one pattern:**Hot/Warm/Cold**, applied to governance files. And in one principle:**never lose anything, always relocate everything**.
== Links
* Previous article:link:/blog/2026/0108_gouvernance_agent_opencode_eager_lazy_post.html[Governing an AI Agent with AsciiDoc]
* My site: https://cheroliv.com
* The`magic-stick`project: https://github.com/cheroliv/magic-stick
---
*A good governance system never deletes data. It organizes it.*