Skip to content

fix(round-trip-tracker): detect hook_success brain context#7

Open
bunny-bot-openclaw wants to merge 5 commits into
mainfrom
fix/hook-success-brain-detection
Open

fix(round-trip-tracker): detect hook_success brain context#7
bunny-bot-openclaw wants to merge 5 commits into
mainfrom
fix/hook-success-brain-detection

Conversation

@bunny-bot-openclaw

Copy link
Copy Markdown
Collaborator

Summary

  • JSONL parser was silently skipping hook_success attachment entries because they carry content under attachment.content, not under message. Added a dedicated branch that extracts this content as a user-role message so has_brain_context() can see it.
  • has_brain_context() is called per-chain starting from the first user message, but startup brain context arrives before any user message. After all chains are built, a single session-level pass over all messages propagates brain_used=True to every chain in the session if any brain signal is found.

Test plan

  • python3 round-trip-tracker.py --report exits cleanly (no errors)
  • Run against a JSONL that has a hook_success entry with "GRAPH OVERVIEW" in content; verify the resulting chain shows brain_used=True
  • Sessions with no brain context are unaffected (still brain_used=False)

🤖 Generated with Claude Code

bunny-bot-openclaw and others added 5 commits March 4, 2026 21:13
Scrapes Anthropic's public docs for latest model versions and compares
against OpenClaw config. No API keys needed.

- Auto-detects ~/.openclaw/ and ~/.clawdbot/ config paths
- --discord flag for formatted output
- Exit code 1 if stale models found (cron-friendly)
- Errors explicitly on empty scrape results
- Points at ~/.claude/projects/*/*.jsonl recursively (no more ~/.openclaw paths)
- Claude Code does not write a pre-computed cost block, so we price tokens
  ourselves using current Anthropic rates (input / output / cache write / cache read)
- Model-aware pricing table: opus-4, sonnet-4, haiku-4 (+ 3.x fallbacks)
- Added MAX_10X tier ($150) alongside MAX_5X and MAX_20X
- Recommendation logic walks tiers by rank so downgrades and upgrades are symmetric
Claude Code writes one growing .jsonl per session (vs openclaw's
per-session files). The session-extract cron was re-reading the same tail
each run, so extraction was non-incremental and ate the same turns over
and over.

session-delta.py walks every .jsonl under the project dir, filters
user/assistant entries by timestamp > watermark, emits plain-text turns,
then advances a watermark at ~/.cashew/extract-watermark.json. First run
seeds watermark to now-48h so we don't replay the entire backlog.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
`extract_text` only checked for OpenClaw-style `toolCall`/`toolResult`
types, so tool calls and results in Claude Code sessions (which use
`tool_use`/`tool_result`) were silently skipped. Brain signal detection
returned 0 hits on every Claude Code session because cashew Bash calls
appeared in `tool_use` blocks that were never read.

Fix: check both type names in each branch. For `tool_use`, read args
from `input` (falling back to `arguments`). Also handle `attachment`
entries in `load_from_jsonl` so startup hook results, which carry brain
context, are included as user messages.
Two fixes for the 0% brain usage bug:

1. JSONL parser: add a branch for attachment entries where
   attachment.type == "hook_success", extracting content from
   attachment.content instead of the missing message key.

2. extract_task_chains: after building all chains, do one
   session-level has_brain_context(messages, 0, len(messages)) pass.
   Startup hook_success entries land before the first user message so
   per-chain checks always miss them; session-level propagation fixes this.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant