feat: add pre-prompt context size diagnostic logging#8930
feat: add pre-prompt context size diagnostic logging#8930Takhoffman merged 4 commits intoopenclaw:mainfrom
Conversation
| // Diagnostic: log context sizes before prompt to help debug early overflow errors. | ||
| { | ||
| const msgCount = activeSession.messages.length; | ||
| const systemLen = systemPromptText?.length ?? 0; | ||
| const promptLen = effectivePrompt.length; | ||
| log.info( | ||
| `[context-diag] pre-prompt: sessionKey=${params.sessionKey ?? params.sessionId} ` + | ||
| `messages=${msgCount} systemPromptChars=${systemLen} promptChars=${promptLen} ` + | ||
| `provider=${params.provider}/${params.modelId} sessionFile=${params.sessionFile}`, |
There was a problem hiding this comment.
[P2] sessionFile path logging may leak sensitive local paths.
This info-level diagnostic includes sessionFile=${params.sessionFile}; on multi-user installs or when logs are shared, absolute paths can expose usernames/home directories. Consider logging just path.basename(sessionFile) or a redacted/relative path, or gating this behind a higher verbosity/debug flag.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.ts
Line: 805:813
Comment:
[P2] `sessionFile` path logging may leak sensitive local paths.
This `info`-level diagnostic includes `sessionFile=${params.sessionFile}`; on multi-user installs or when logs are shared, absolute paths can expose usernames/home directories. Consider logging just `path.basename(sessionFile)` or a redacted/relative path, or gating this behind a higher verbosity/debug flag.
How can I resolve this? If you propose a fix, please make it concise.|
[P2] Session file path logging: This is consistent with existing logging throughout the codebase — |
6323330 to
3497229
Compare
3497229 to
05840c9
Compare
4cc46d8 to
2606b37
Compare
2606b37 to
330c2e8
Compare
6ccf3f8 to
511bcbb
Compare
511bcbb to
71399c7
Compare
71399c7 to
4cbd8ac
Compare
4cbd8ac to
17b1430
Compare
17b1430 to
3bb69b2
Compare
3bb69b2 to
4edc1af
Compare
Log message count, system prompt size, and user prompt size before each session.prompt() call. This helps diagnose early context overflow errors by revealing the actual payload sizes being sent to the model, enabling root cause analysis of unexpected overflows in new or small sessions.
4edc1af to
9c8ea69
Compare
|
Merged via squash.
Thanks @Glucksberg! |
|
This was a good idea. I expanded it a bit so we can get to the bottom of all these tricky compaction bugs. I also added a new log level guard to hide these potential expensive operations behind a less expensive check. Appreciate the PR! |
…thanks @Glucksberg Verified: - pnpm build - pnpm check - pnpm test Co-authored-by: Glucksberg <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
…thanks @Glucksberg Verified: - pnpm build - pnpm check - pnpm test Co-authored-by: Glucksberg <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
…thanks @Glucksberg Verified: - pnpm build - pnpm check - pnpm test Co-authored-by: Glucksberg <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
…thanks @Glucksberg Verified: - pnpm build - pnpm check - pnpm test Co-authored-by: Glucksberg <[email protected]> Co-authored-by: Tak Hoffman <[email protected]>
Summary
[context-diag]log before eachsession.prompt()call reporting context sizesProblem
When a session hits context overflow early (e.g., at 15k/200k reported by
/status), there is no visibility into what the actual payload sizes were at the time of the API call. The token counts shown by/statusmay be stale or misleading, making it impossible to diagnose whether the overflow was caused by a large system prompt, accumulated messages, or session contamination.Solution
Add an
info-level log right beforesession.prompt()that reports:messages: number of messages in the active sessionsystemPromptChars: character count of the system prompt (tools, skills, context files, runtime info)promptChars: character count of the user prompt being sentprovider/modelId: which model is being usedsessionFile: path to the session file for cross-referencingThis enables post-mortem analysis of overflow events by correlating the diagnostic log with the overflow error, revealing the actual context composition at the time of failure.
Test plan
pnpm build— passes🤖 Generated with Claude Code
Greptile Overview
Greptile Summary
Adds an
info-level[context-diag]log immediately beforeactiveSession.prompt()in the embedded runner. The log captures message count, system prompt and prompt character lengths, provider/modelId, and the session file path to help diagnose early context overflow issues by correlating the sizes at the time of the API call.Confidence Score: 4/5
session.prompt()and does not alter control flow. Main concern is operational/privacy impact from logging the session file path at info level.