Issue Summary
Container restart does not clear accumulated session context. Running agent session continues to load massive context despite restart, resulting in 90%+ increase in API token costs.
Technical Details
Session Information:
- Session ID:
sess-1778272236516-2bodft
- Agent Group: Prachin (Private Secretary Agent)
- Messaging Group: telegram-mg-17782 (Telegram)
- Session Started: May 8, 2026
- Container Status: Restarted May 19, 2026, 8:53 AM IST
Issue Timeline:
| Date/Time |
Event |
Token Usage |
| May 8 |
Session created, initial usage baseline |
~5-10K/msg |
| May 17 |
Context bloat warning identified |
~100K/msg |
| May 19, 8:45 AM |
Spike detected: 575K tokens in 3 min |
~192K/msg |
| May 19, 8:53 AM |
Container restarted (docker restart) |
- |
| May 19, 8:58 AM |
Post-restart spike: 397K tokens in 3 min |
~132K/msg |
| May 20, 9:00 AM |
Status: No improvement, continues at 132K/msg |
132K/msg |
Root Cause Analysis
Expected Behavior:
- Fresh session restart should clear context
- New messages should load minimal context (~5-10K tokens)
- Cost should drop 90%
Actual Behavior:
- Container restart completed successfully
- Session ID remains same:
sess-1778272236516-2bodft
- Context size: Still ~130K tokens per message
- No cost reduction observed
Hypothesis:
- Session context persisted in database/cache despite container restart
- Agent loading accumulated context from storage layer, not fresh memory
- Possible: inbound.db or outbound.db not cleared
- Possible: Session container restarted but agent retained state
Business Impact
Cost Analysis:
| Scenario |
Tokens/Message |
Weekly Cost |
Annual Cost |
| Baseline (target) |
5-10K |
~0ドル.15 |
~8ドル |
| Current bloat |
130K |
~4ドル/week |
~200ドル |
| Cost increase |
12-26x |
26x higher |
25x higher |
Operational Impact:
- Cost optimization strategy blocked
- Cannot implement weekly context resets
- System unsustainable at current usage rates
- User unable to meet cost targets
Steps Taken So Far
- âœ" Identified context bloat (May 17)
- âœ" Implemented file-based workflow to reduce conversation context
- âœ" Attempted container restart (May 19, 8:53 AM)
- âœ" Verified restart did not resolve issue
- âœ" Documented metrics and timeline
- → Escalating for infrastructure investigation
Data for Debugging
Session Creation Query:
Session: sess-1778272236516-2bodft
Agent Group: ag-1778272236511-97z4s3 (Prachin)
Container: f15e22cf6a58 (hostname)
Last Active: May 20, 2026, 9:01 AM UTC
Status: active/running
Affected Configuration:
- NanoClaw v2 on Raspberry Pi 5 (4GB RAM)
- Claude Model: Haiku 4.5
- Integration: Telegram bot
- Session Mode: shared
Requested Resolution
- Root Cause Investigation: Why does session context persist after container restart?
- Database Check: Verify inbound.db/outbound.db cleared on restart
- Cache Inspection: Check if context cached at higher level
- Fix: Implement proper context cleanup on container restart
- Verification: Test that restart actually clears session context
Workaround Status
Current Mitigation (File-Based Workflow):
- Using persistent files instead of conversation memory
- Files: meeting-agenda.md, tasks.md, reminders.md, policy-ideas.md
- Reduces context per message, but doesn't address root cause
- Effective only if other users don't inflate context
- Still costs 12-26x baseline
Sustainability: Workaround not sustainable long-term at current cost levels.
|