Monitor session context usage and apply a cascading relief protocol before context exhaustion silently degrades response quality.
| Output | Meaning |
|---|---|
| ----------------- | -------------------------------------------------------------------------- |
| STATUS_OK | prompt_count < 15 — session is healthy, continue normally |
| COMPACT_NOW | prompt_count 15–25 — approaching limit, invoke strategic-compact |
| HANDOFF_NOW | prompt_count > 25 — near ceiling, invoke handoff + willow_task_submit |
| POSTGRES_DOWN | session_anchor.json reports postgres as down — fix infra before proceeding |
bash {baseDir}/scripts/check_context.sh
The script reads two Willow state files:
~/.willow/anchor_state.json — prompt_count field (context proxy)~/.willow/session_anchor.json — postgres status fieldRun the script and act on the single-line output:
No action needed. Session is healthy.
STATUS_OK
Continue with the current task. Optionally note the prompt_count in a heartbeat log entry.
COMPACT_NOW
Context is filling. Invoke the strategic-compact skill immediately before proceeding:
/strategic-compact
After compact completes, re-run the sentinel. If it still reports COMPACT_NOW or escalates to HANDOFF_NOW, proceed to the handoff protocol below.
HANDOFF_NOW
Session is near the context ceiling. Invoke the handoff skill and submit the next task to Willow:
/handoff to produce a structured handoff documentwillow_task_submit with the next bite as the task bodyPOSTGRES_DOWN
Willow's backing store is unreachable. KB reads and writes will fail silently. Do not proceed with memory-dependent tasks. Check the Willow server status:
willow status
# or
systemctl status willow-postgres
Resolve the infra issue before resuming work.
Add a sentinel call to your heartbeat template so it runs automatically. Minimal example:
## Heartbeat — {timestamp}
**Sentinel:** `bash ~/.openclaw/skills/willow-context-sentinel/scripts/check_context.sh`
| Check | Result |
| -------- | --------- |
| Context | STATUS_OK |
| Postgres | up |
Next bite: {next_task}
If the sentinel output is anything other than STATUS_OK, record the output and the action taken before moving on.
Claude Sonnet 4.6
│
├─ prompt_count ≥ 15 → COMPACT_NOW → /strategic-compact
│ │
│ └─ still ≥ 15 after compact
│ │
└─ prompt_count > 25 → HANDOFF_NOW → /handoff + willow_task_submit
Relief valves are applied in order. Skip to HANDOFF_NOW if compact has already been run in this session and context remains high.
prompt_count is a proxy, not a direct token count. Actual context consumption varies by response length. Treat thresholds as conservative triggers, not hard limits.anchor_state.json, session_anchor.json) are written by the Willow server. If either file is missing, the script outputs STATUS_OK and logs a warning to stderr — it fails open, not closed.共 1 个版本