mirror of
https://github.com/JuliusBrussee/skills.git
synced 2026-09-19 01:11:52 +08:00
Add context-canary skill for detecting silent context degradation
Installs a per-turn first-line canary (user name + turn counter + honest context self-check) so attention drift, compaction, and truncation become visible the moment they happen, with a checkpoint/re-anchor/reset trip protocol. References file documents the research grounding: Chroma's context-rot study, Lost in the Middle (Liu et al.), instruction-drift findings, compaction summary loss, and Breunig's context failure taxonomy. Updates README, CLAUDE.md, and CONTEXT.md skill rosters to six skills. https://claude.ai/code/session_01CWPytH8cfzYfCgU6eC9pX9
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## Purpose
|
||||
|
||||
This repo publishes five Julius Brussee agent skills for now: `caveman`, `interface-kit`, `grill-me`, `loop-factory`, and `junior-to-senior`. Treat it as an installable skill collection, not a product website.
|
||||
This repo publishes six Julius Brussee agent skills for now: `caveman`, `interface-kit`, `grill-me`, `loop-factory`, `junior-to-senior`, and `context-canary`. Treat it as an installable skill collection, not a product website.
|
||||
|
||||
## Editing Rules
|
||||
|
||||
|
||||
+2
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
## Domain
|
||||
|
||||
This repository is a public skill collection for AI coding agents. For now it publishes `caveman`, `interface-kit`, `grill-me`, and `loop-factory`.
|
||||
This repository is a public skill collection for AI coding agents. For now it publishes `caveman`, `interface-kit`, `grill-me`, `loop-factory`, `junior-to-senior`, and `context-canary`.
|
||||
|
||||
## Maintainer Identity
|
||||
|
||||
@@ -15,6 +15,7 @@ Julius Brussee is the creator of Caveman and related agent tooling. Repo voice c
|
||||
- **Interface Kit** - implementation discipline for accessible, performant, visually specific interfaces.
|
||||
- **Grill Me** - calibrated interview workflow that assesses knowledge and desired pressure before challenging a plan.
|
||||
- **Loop Factory** - spec-driven agent loop; tasks are markdown specs that move through inbox → active → archive and pass a review gate before counting as done.
|
||||
- **Context Canary** - per-turn first-line signal (name + turn counter + self-check) that dies visibly when context degrades, paired with a checkpoint-and-reset trip protocol.
|
||||
- **Progressive disclosure** - agents read the smallest useful context first, then load linked references only as needed.
|
||||
|
||||
## Repository Shape
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
# Julius Skills
|
||||
|
||||
Five personal agent skills for now: Caveman base, Interface Kit, Grill Me, Loop Factory, and Junior to Senior.
|
||||
Six personal agent skills for now: Caveman base, Interface Kit, Grill Me, Loop Factory, Junior to Senior, and Context Canary.
|
||||
|
||||
This repo is shaped by five things:
|
||||
This repo is shaped by six things:
|
||||
|
||||
- **Caveman** - 70k-star token compression without technical loss. Small mouth, big brain.
|
||||
- **Interface Kit** - accessible, performant interfaces with strong aesthetic direction, not generic AI slop.
|
||||
- **Grill Me** - calibrated pressure before hard critique, so challenge matches user knowledge and comfort.
|
||||
- **Loop Factory** - spec-driven agent loop where tasks move through inbox → active → archive with a real review gate.
|
||||
- **Junior to Senior** - adversarial senior review that treats agent output as junior work and upgrades it with codebase + web research.
|
||||
- **Context Canary** - per-turn canary signal that makes silent context degradation visible, plus a recovery protocol when it trips.
|
||||
|
||||
Point is control. Agents should be terse when talking, precise when building interfaces, calibrated when challenging plans, and disciplined when running build loops.
|
||||
|
||||
@@ -103,6 +104,19 @@ Use when you want:
|
||||
- a clear delta between the original plan and the upgraded one
|
||||
- product decisions surfaced as open questions instead of silently invented
|
||||
|
||||
### `context-canary`
|
||||
|
||||
Early-warning system for long agent sessions. Installs a byte-stable first-line signal — the user's name, a turn counter, and an honest context self-check — so the moment the agent's hold on its instructions degrades (attention drift, compaction, truncation), the signal visibly dies. Comes with a trip protocol: checkpoint state to a file, re-anchor on project instructions, reset deliberately.
|
||||
|
||||
Use when you want:
|
||||
|
||||
- to know *when* a long session starts rotting instead of finding out from bad output
|
||||
- a zero-infrastructure health check that runs every single turn
|
||||
- compaction events surfaced the moment they happen
|
||||
- a disciplined recovery path (checkpoint → re-anchor → fresh session) instead of limping on
|
||||
|
||||
Grounded in context-rot research (Chroma), lost-in-the-middle (Liu et al.), and instruction-drift findings — sources linked in the skill's references.
|
||||
|
||||
## Interface Kit Standard
|
||||
|
||||
If a repo has `DESIGN.md`, it wins. Otherwise UI work should still have a point of view:
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
name: context-canary
|
||||
description: Install a per-turn canary signal (e.g. starting every reply with the user's name and a turn counter) so silent context degradation becomes visible the moment it happens, and run a recovery protocol when the canary trips. Use when the user mentions a "canary", "context canary", or "canary check", asks to detect context rot / compaction / drift, says "you stopped using my name" or "did you lose context", asks "how degraded is your context", or wants an early-warning system for long agent sessions.
|
||||
---
|
||||
|
||||
# Context Canary
|
||||
|
||||
A context canary is a trivially checkable standing instruction whose only job is to fail visibly. The classic form: "start every response with my name." The agent costs almost nothing to comply — so when the name disappears, that absence is data. The instruction didn't get harder; the agent's hold on its early-context instructions got weaker. Like the coal-mine canary, it dies first, before the failures you actually care about (forgotten constraints, ignored conventions, re-litigated decisions) start landing in your code.
|
||||
|
||||
This works because context degradation is **silent and gradual**. Models don't announce that they've stopped attending to instructions from 80k tokens ago, and compaction summaries quietly drop standing instructions. The canary converts an invisible failure into a binary, per-turn, zero-effort check. The research behind why this happens — context rot, lost-in-the-middle, instruction drift, compaction loss — is in **[references/research.md](references/research.md)**.
|
||||
|
||||
## When to use this skill
|
||||
|
||||
- Installing a canary at the start of a long or high-stakes session.
|
||||
- The user notices the canary stopped appearing and asks what happened.
|
||||
- The agent itself realizes it can no longer find its canary contract in context.
|
||||
- The user asks how trustworthy the current context still is.
|
||||
|
||||
## The canary contract
|
||||
|
||||
When invoked, install the canary by stating the contract explicitly in one short message, then follow it. Default format — first line of every response from then on:
|
||||
|
||||
```
|
||||
**Julius · t14 · ctx ok**
|
||||
```
|
||||
|
||||
Three fields, each probing something different:
|
||||
|
||||
| Field | Example | What its failure means |
|
||||
|---|---|---|
|
||||
| Name | `Julius` | The standing instruction itself fell out of effective context — adherence drift or compaction dropped it. |
|
||||
| Turn counter | `t14` | Increment by 1 every response. A reset, skip, or repeat means continuity broke — almost always compaction or a summarization boundary. |
|
||||
| Self-check | `ctx ok` / `ctx aging` / `ctx thin` | The agent's honest estimate. `aging`: the session is long and early details are getting summarized in its own working sense of the task. `thin`: the agent is reconstructing earlier decisions instead of remembering them. |
|
||||
|
||||
Use the user's actual name (ask if unknown). If the user wants the minimal version, name-only is fine — it's the original trick and still catches the big failures. Never explain, apologize for, or decorate the canary line; it must stay byte-stable so a human can pattern-match it in half a second.
|
||||
|
||||
**Session canary vs. standing canary.** A canary that lives only in the conversation tests whether *conversation* context survives (compaction, truncation, drift). A canary written into `CLAUDE.md` or agent memory survives compaction by design — which means it tests whether file-based instructions are being attended to, a different and weaker signal. Default to the session canary; that's the one that detects degradation. Offer the standing variant only if the user wants the habit across all sessions, and tell them what it no longer measures.
|
||||
|
||||
## Emission rules
|
||||
|
||||
1. Canary is the **first line** of every response, including short ones, error reports, and responses after tool calls.
|
||||
2. Increment the counter every response. If unsure of the count, that uncertainty IS a signal — emit `t?` and flag it, never guess a plausible number.
|
||||
3. The self-check must be honest. Reporting `ctx ok` by reflex defeats the entire instrument.
|
||||
4. If at any point the canary contract cannot be found in context (you only know about it from a summary, or not at all), **declare a trip yourself** — don't wait for the user to notice.
|
||||
|
||||
## Trip protocol
|
||||
|
||||
A trip is: the canary missing, malformed, a counter discontinuity, or an agent-side self-declaration.
|
||||
|
||||
Calibrate before alarming — one missed canary on an otherwise coherent response is a warning (note it, resume the canary, keep going). **Two consecutive misses, a counter discontinuity, or the agent failing its own contract check is a confirmed trip.** Then:
|
||||
|
||||
1. **Stop trusting drifted state.** Do not barrel ahead on the current task using context you can no longer vouch for.
|
||||
2. **Checkpoint.** Write the durable state somewhere outside the conversation: current goal, decisions made and why, files touched, what's verified vs. in-progress, next step. A `HANDOFF.md` or notes file in the repo works.
|
||||
3. **Re-anchor.** Re-read the project instructions (`CLAUDE.md`, the original task statement) and the checkpoint. State back to the user, in three or four lines, what you believe the task and constraints are — so they can correct any drift cheaply.
|
||||
4. **Reset deliberately.** Recommend the user start a fresh session (or run an explicit compact) seeded with the checkpoint file, rather than limping on. Degraded context doesn't heal; it compounds.
|
||||
5. **Re-install the canary** with the counter reset to `t1`, noting the generation: `t1 (gen 2)`.
|
||||
|
||||
Never silently resume the canary after a gap as if nothing happened — that destroys the instrument's credibility, which is all it has.
|
||||
|
||||
## What the canary does and doesn't tell you
|
||||
|
||||
The test is one-sided. A **missing** canary is strong evidence of degradation. A **present** canary is weak evidence of health — a cheap stylistic habit can survive while harder constraints (architecture decisions, "never touch X") quietly rot, and a canary stuffed into memory files can outlive the context it was meant to monitor. Treat the canary as a smoke detector, not a structural inspection: when it fires, act; when it's quiet, stay reasonably suspicious in sessions past roughly 50% of the context window or after any compaction event.
|
||||
|
||||
Pair it with the cheap structural habits that reduce what the canary has to catch: keep durable decisions in files instead of chat, compact at deliberate boundaries instead of waiting for forced compaction, and prefer fresh sessions per task over one immortal session. Details and sources in **[references/research.md](references/research.md)**.
|
||||
@@ -0,0 +1,64 @@
|
||||
# Why canaries work: the research behind context degradation
|
||||
|
||||
The canary trick is an instruction-adherence probe. Everything below is the evidence that adherence to early-context instructions degrades predictably as sessions grow — which is exactly the failure the canary is built to surface.
|
||||
|
||||
## Context rot: longer input, worse model
|
||||
|
||||
Chroma's "Context Rot" study evaluated 18 frontier models (GPT-4.1, Claude 4, Gemini 2.5, Qwen3 among them) and found **every one degrades as input length increases**, even on tasks where the relevant information is verifiably present in context. Degradation is not a cliff at the context limit; it is a slope that starts well before it. The term itself was coined informally on Hacker News and stuck because the failure is gradual and silent — which is the property that makes an explicit per-turn signal valuable.
|
||||
|
||||
- Chroma research: https://research.trychroma.com/context-rot
|
||||
- Overview: https://redis.io/blog/context-rot/
|
||||
|
||||
## Lost in the middle: position matters
|
||||
|
||||
Liu et al. (2023), "Lost in the Middle" (arXiv:2307.03172), showed LLM accuracy follows a U-shape over position: information at the start and end of context is recalled well, information in the middle drops by 30%+ on retrieval tasks. As a session grows, the original instructions migrate from "start of a short context" (privileged position) to "start of an enormous context" (still positionally privileged, but competing against vastly more recent tokens for attention mass). Follow-up work attributes part of this to RoPE long-term decay: attention weight between distant token pairs shrinks, and softmax then concentrates the remainder on recent, high-scoring tokens.
|
||||
|
||||
Later threshold studies found abrupt collapses: tasks presented around 50% of a model's maximum context length showed F1 dropping ~45% over a narrow 10% range of context growth. Practical implication: degradation can arrive fast once a session is deep, which is why a per-turn canary beats an occasional spot check.
|
||||
|
||||
## Instruction drift: the canary's direct mechanism
|
||||
|
||||
"Measuring and Controlling Instruction (In)Stability in Language Model Dialogs" (arXiv:2402.10962) quantified that system-prompt adherence decays over dialog turns even when nothing adversarial happens. Practitioner reports converge on the same shape: agents follow the system prompt perfectly early, then drift — commonly observable past ~15 tool calls in agentic sessions — because the instruction block at the start of context loses effective weight relative to accumulated recent messages. The instructions are still *in* the window; their *influence* fades.
|
||||
|
||||
The standard mitigation is recency injection: short reminders placed at the end of context right before decision points (this is what harness "system reminders" are). The canary is the observability counterpart of that mitigation — it doesn't restore adherence, it tells you when adherence was lost.
|
||||
|
||||
- arXiv:2402.10962 — instruction stability in dialogs
|
||||
- Practitioner write-up on system prompt drift: https://dev.to/nikolasi/solving-agent-system-prompt-drift-in-long-sessions-a-300-token-fix-1akh
|
||||
|
||||
## Compaction: the step-function failure
|
||||
|
||||
Harnesses like Claude Code summarize the transcript when context fills (auto-compact or `/compact`), replacing the verbatim history with a condensed version. Summaries preserve what looks load-bearing — task state, file lists, decisions — and routinely drop standing *stylistic* instructions, because "starts every reply with the user's name" doesn't look like task state to a summarizer. That's precisely why the trick works so well against compaction: the canary instruction is the kind of content summaries lose first, so a compaction event reads out as a canary death within a turn or two. A turn counter catches it even faster: summaries don't carry exact counts, so the counter resets or goes vague at the boundary.
|
||||
|
||||
## Drew Breunig's failure taxonomy
|
||||
|
||||
"How Long Contexts Fail" (dbreunig.com, June 2025) names four modes, all of which a tripped canary should make you suspect:
|
||||
|
||||
1. **Context poisoning** — a hallucination enters context and gets repeatedly referenced as fact.
|
||||
2. **Context distraction** — the model over-attends to its accumulated history and under-uses its trained ability.
|
||||
3. **Context confusion** — superfluous context (e.g., too many tools) degrades response quality.
|
||||
4. **Context clash** — newly accrued information conflicts with earlier instructions.
|
||||
|
||||
His companion piece "How to Fix Your Context" covers the mitigations the trip protocol leans on: context pruning, summarization at deliberate boundaries, and offloading durable state to files. Anthropic's "Effective context engineering for AI agents" makes the same argument from the harness side: treat context as a finite resource with a budget, not a scrollback buffer.
|
||||
|
||||
- https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html
|
||||
- https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html
|
||||
- https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
|
||||
|
||||
## Prompt canaries as known-answer tests
|
||||
|
||||
The wider "prompt canary" pattern treats any known-answer test run regularly against an AI workflow as a health check: if a check with a fixed expected output starts failing, the pipeline changed, even if nothing errored. The in-conversation name canary is the degenerate, zero-infrastructure case: expected output = "first line contains my name," run frequency = every turn, evaluator = the human reading the reply.
|
||||
|
||||
- https://dev.to/novaelvaris/prompt-canaries-early-warning-signs-your-ai-workflow-is-degrading-5f57
|
||||
|
||||
## Not to be confused with: security canary tokens
|
||||
|
||||
In LLM security, a "canary word" is a random string planted in a system prompt to *detect leakage* — if it appears in output, the prompt was extracted (Rebuff, OWASP LLM07:2025 mitigations). Same metaphor, opposite polarity: the security canary must never appear in output; the context canary must always appear. Don't conflate them when explaining the skill.
|
||||
|
||||
- https://www.langchain.com/blog/rebuff
|
||||
|
||||
## Design consequences baked into the skill
|
||||
|
||||
- **Per-turn, not periodic**: degradation can collapse quickly past deep-context thresholds, so the check runs every response.
|
||||
- **First-line, byte-stable**: the human evaluator must verify it preflectively; any variation creates false positives.
|
||||
- **Counter beats name alone**: the name detects instruction loss; the counter detects continuity loss (compaction) even when the instruction survives via a summary mentioning "user wants name prefixed."
|
||||
- **One-sided test**: presence is weak evidence, absence is strong evidence — hence "smoke detector, not structural inspection."
|
||||
- **Two-miss confirmation**: single-turn attention lapses happen without systemic degradation; requiring two consecutive misses or a counter discontinuity trades a little latency for far fewer false alarms.
|
||||
Reference in New Issue
Block a user