fix(agents): skip bootstrap file injection on continuation messages#44220
fix(agents): skip bootstrap file injection on continuation messages#44220JoshuaLelon wants to merge 2 commits into
Conversation
Greptile SummaryThis PR optimizes Pi session token usage by skipping the
Confidence Score: 3/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ff196ae54
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
This comment was marked as spam.
This comment was marked as spam.
1ff196a to
d228f31
Compare
|
Addressed in d228f31 — replaced the duplicate Also rebased on latest main. @greptile-apps anything else? |
d228f31 to
18970b4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18970b4739
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex Re: detecting first turn from transcript content rather than file existence — acknowledged. The current approach ( The duplicate Anything else to address? |
Only inject workspace bootstrap files on the first message of a Pi session. Continuation messages already have them in context from the initial turn, so re-injecting wastes ~35k tokens per message. Fixes openclaw#9157 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
18970b4 to
2c15960
Compare
|
Rebased onto latest |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c159603df
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const isFirstMessage = !(await fs | ||
| .stat(params.sessionFile) | ||
| .then(() => true) | ||
| .catch(() => false)); |
There was a problem hiding this comment.
Determine first-turn state from transcript contents
isFirstMessage is inferred only from fs.stat(sessionFile), but this codebase still treats “file exists, no assistant turn yet” as a first-turn-like state (prepareSessionManagerForRun has an explicit hadSessionFile && header && !hasAssistant branch in src/agents/pi-embedded-runner/session-manager-init.ts:44-52, and runWithOrphanedSingleUserMessage seeds this transcript shape in src/agents/pi-embedded-runner.e2e.test.ts:146-154). In those cases this change skips resolveBootstrapContextForRun, so the first successful reply loses bootstrap file context and bootstrap hook adjustments.
Useful? React with 👍 / 👎.
| .stat(params.sessionFile) | ||
| .then(() => true) | ||
| .catch(() => false); | ||
| const hadSessionFile = !isFirstMessage; |
There was a problem hiding this comment.
Recompute session-file presence after lock acquisition
hadSessionFile now comes from pre-lock isFirstMessage, but acquireSessionWriteLock explicitly retries while waiting on contended locks (src/agents/session-write-lock.ts:482-547), so the transcript can be created by another worker before this run enters the critical section. When that happens, this stale value misclassifies a continuation as first-turn, which skips continuation-only handling like contextEngine.bootstrap and passes the wrong hadSessionFile into session initialization.
Useful? React with 👍 / 👎.
Summary
resolveBootstrapContextForRun(). If the session file exists (continuation), skip bootstrap injection.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Security Impact (required)
Repro + Verification
Steps
Expected
Actual (before fix)
Evidence
resolveBootstrapContextForRun()is called unconditionally inattempt.ts. The session file existence check (fs.stat(params.sessionFile)) reliably distinguishes first vs. continuation messages.Compatibility / Migration
Failure Recovery (if this breaks)
Risks and Mitigations