Skip to content

feat: add pre-prompt context size diagnostic logging#8930

Merged
Takhoffman merged 4 commits intoopenclaw:mainfrom
Glucksberg:feat/pre-prompt-context-diagnostics
Feb 13, 2026
Merged

feat: add pre-prompt context size diagnostic logging#8930
Takhoffman merged 4 commits intoopenclaw:mainfrom
Glucksberg:feat/pre-prompt-context-diagnostics

Conversation

@Glucksberg
Copy link
Contributor

@Glucksberg Glucksberg commented Feb 4, 2026

Summary

  • Add [context-diag] log before each session.prompt() call reporting context sizes

Problem

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 /status may 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 before session.prompt() that reports:

  • messages: number of messages in the active session
  • systemPromptChars: character count of the system prompt (tools, skills, context files, runtime info)
  • promptChars: character count of the user prompt being sent
  • provider/modelId: which model is being used
  • sessionFile: path to the session file for cross-referencing

This 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
  • Log output verified by reading the committed code

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

Adds an info-level [context-diag] log immediately before activeSession.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

  • This PR is likely safe to merge; it adds a single diagnostic log line with limited behavioral impact.
  • Change is localized to a logging block before session.prompt() and does not alter control flow. Main concern is operational/privacy impact from logging the session file path at info level.
  • src/agents/pi-embedded-runner/run/attempt.ts

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 4, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 805 to 813
// 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}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@Glucksberg
Copy link
Contributor Author

[P2] Session file path logging: This is consistent with existing logging throughout the codebase — sessionFile is already logged at info/warn level in multiple places (compaction logs in run.ts, session repair in attempt.ts, session init in session.ts). These logs are only written to the gateway's own log output and are not user-facing. Switching to path.basename() would reduce diagnostic value (can't distinguish between agents/sessions) without a meaningful security benefit, since the same full paths are already logged elsewhere in the same execution flow.

@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch 5 times, most recently from 6323330 to 3497229 Compare February 7, 2026 13:48
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch from 3497229 to 05840c9 Compare February 8, 2026 01:30
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch 6 times, most recently from 4cc46d8 to 2606b37 Compare February 10, 2026 13:31
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 10, 2026
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch from 2606b37 to 330c2e8 Compare February 11, 2026 01:34
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 11, 2026
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch 2 times, most recently from 6ccf3f8 to 511bcbb Compare February 11, 2026 13:33
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 11, 2026
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch from 511bcbb to 71399c7 Compare February 12, 2026 01:32
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 12, 2026
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch from 71399c7 to 4cbd8ac Compare February 13, 2026 01:34
@openclaw-barnacle openclaw-barnacle bot added size: XS experienced-contributor Contributor with 10+ merged PRs labels Feb 13, 2026
@Takhoffman Takhoffman self-assigned this Feb 13, 2026
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch from 4cbd8ac to 17b1430 Compare February 13, 2026 13:57
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 13, 2026
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 13, 2026
@Glucksberg Glucksberg force-pushed the feat/pre-prompt-context-diagnostics branch from 17b1430 to 3bb69b2 Compare February 13, 2026 22:15
Glucksberg added a commit to Glucksberg/OpenClaw that referenced this pull request Feb 13, 2026
@Takhoffman Takhoffman force-pushed the feat/pre-prompt-context-diagnostics branch from 3bb69b2 to 4edc1af Compare February 13, 2026 23:46
Glucksberg and others added 4 commits February 13, 2026 17:47
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.
@Takhoffman Takhoffman force-pushed the feat/pre-prompt-context-diagnostics branch from 4edc1af to 9c8ea69 Compare February 13, 2026 23:52
@Takhoffman Takhoffman merged commit 9bd2ccb into openclaw:main Feb 13, 2026
9 checks passed
@Takhoffman
Copy link
Contributor

Merged via squash.

  • Merge commit: 9bd2ccb
  • Verified: pnpm build, pnpm check, pnpm test
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @Glucksberg!

@Takhoffman
Copy link
Contributor

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!

steipete pushed a commit to azade-c/openclaw that referenced this pull request Feb 14, 2026
…thanks @Glucksberg

Verified:
- pnpm build
- pnpm check
- pnpm test

Co-authored-by: Glucksberg <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
@Glucksberg Glucksberg deleted the feat/pre-prompt-context-diagnostics branch February 14, 2026 03:42
mverrilli pushed a commit to mverrilli/openclaw that referenced this pull request Feb 14, 2026
…thanks @Glucksberg

Verified:
- pnpm build
- pnpm check
- pnpm test

Co-authored-by: Glucksberg <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
GwonHyeok pushed a commit to learners-superpumped/openclaw that referenced this pull request Feb 15, 2026
…thanks @Glucksberg

Verified:
- pnpm build
- pnpm check
- pnpm test

Co-authored-by: Glucksberg <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
cloud-neutral pushed a commit to cloud-neutral-toolkit/openclawbot.svc.plus that referenced this pull request Feb 15, 2026
…thanks @Glucksberg

Verified:
- pnpm build
- pnpm check
- pnpm test

Co-authored-by: Glucksberg <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling experienced-contributor Contributor with 10+ merged PRs size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments