[AI-Assisted] Fix ExtensionRunner initialization in embedded mode#2027
[AI-Assisted] Fix ExtensionRunner initialization in embedded mode#2027ArtemHorik wants to merge 1 commit intoopenclaw:mainfrom
Conversation
37a4aa7 to
05f1b90
Compare
|
Guys thats crucial - compaction not working properly without this fix.. please do priority review @sebslight |
902e3f5 to
557c548
Compare
557c548 to
1f78e4f
Compare
1f78e4f to
300e90a
Compare
| // IMPORTANT (embedded mode): bind the pi extension runner. | ||
| // | ||
| // In pi-coding-agent, ExtensionRunner defaults `ctx.model` to `undefined` until | ||
| // `extensionRunner.bindCore(...)` is called. Moltbot uses the SDK in embedded |
There was a problem hiding this comment.
[P1] Comment/PR description says "initialize" but code calls bindCore.
This is easy to miss during future maintenance/debugging: the PR text and the inline both refer to initializing the runner, but the actual change is binding core callbacks via extensionRunner.bindCore(...). If initialize() is a real API on this object, readers may assume it was invoked when it wasn’t.
Suggestion: update the inline comment (and/or PR description) to consistently describe the action as binding the core, or rename the variable/comment to reflect bindCore.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.ts
Line: 515:518
Comment:
[P1] Comment/PR description says "initialize" but code calls `bindCore`.
This is easy to miss during future maintenance/debugging: the PR text and the inline both refer to initializing the runner, but the actual change is binding core callbacks via `extensionRunner.bindCore(...)`. If `initialize()` is a real API on this object, readers may assume it was invoked when it wasn’t.
Suggestion: update the inline comment (and/or PR description) to consistently describe the action as binding the core, or rename the variable/comment to reflect `bindCore`.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| isIdle: () => true, | ||
| abort: () => { | ||
| void activeSession.abort(); | ||
| }, | ||
| hasPendingMessages: () => false, |
There was a problem hiding this comment.
[P1] isIdle/hasPendingMessages are hardcoded, which can break extensions relying on them.
In embedded mode these are currently always true/false, but extensions often gate actions (including compaction) on whether the agent is streaming or has queued messages. With the current stubs, an extension could attempt compaction or other work while the agent is mid-stream and get inconsistent behavior.
If activeSession exposes state for these (e.g. activeSession.isStreaming or similar), it’d be safer to wire these through rather than returning constants.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.ts
Line: 567:571
Comment:
[P1] `isIdle`/`hasPendingMessages` are hardcoded, which can break extensions relying on them.
In embedded mode these are currently always `true`/`false`, but extensions often gate actions (including compaction) on whether the agent is streaming or has queued messages. With the current stubs, an extension could attempt compaction or other work while the agent is mid-stream and get inconsistent behavior.
If `activeSession` exposes state for these (e.g. `activeSession.isStreaming` or similar), it’d be safer to wire these through rather than returning constants.
How can I resolve this? If you propose a fix, please make it concise.| compact: (options?: CompactOptions) => { | ||
| void (async () => { | ||
| try { | ||
| const result = await activeSession.compact(options?.customInstructions); | ||
| options?.onComplete?.(result); | ||
| } catch (error) { | ||
| const err = error instanceof Error ? error : new Error(String(error)); | ||
| options?.onError?.(err); | ||
| } | ||
| })(); |
There was a problem hiding this comment.
[P2] compact ignores returned promise and doesn’t surface completion as an async result.
compact is implemented as fire-and-forget (void (async () => { ... })()), so callers that await compact() will resolve immediately even though compaction is still running. Some extensions might reasonably expect compact to be awaitable (even if callbacks exist).
If the bindCore contract allows it, consider returning the inner promise (or making compact async) so the caller can choose between awaiting and using callbacks.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run/attempt.ts
Line: 574:583
Comment:
[P2] `compact` ignores returned promise and doesn’t surface completion as an async result.
`compact` is implemented as fire-and-forget (`void (async () => { ... })()`), so callers that `await` `compact()` will resolve immediately even though compaction is still running. Some extensions might reasonably expect `compact` to be awaitable (even if callbacks exist).
If the `bindCore` contract allows it, consider returning the inner promise (or making `compact` `async`) so the caller can choose between awaiting and using callbacks.
How can I resolve this? If you propose a fix, please make it concise.|
@ArtemHorik Can you repro this in the current main? |
|
Closing as duplicate of #4223. If this is incorrect, comment and we can reopen. |
Summary
extensionRunnerin embedded mode to fix auto-compaction summariesctx.modelremains undefined and compaction hooks fall back to "Summary unavailable..."Why
In embedded mode (used by bots),
extensionRunner.initialize()was never called, unlike interactive mode where the UI calls it. This causedcompaction-safeguardto skip real summarization.Changes
extensionRunner.initialize()after session creation inattempt.tsgetActiveToolsreturns only valid string tool names (filters undefined)setModelvalidates API key and returnsPromise<boolean>compactforwardsonComplete/onErrorcallbacks properlyTesting
✅ Fully tested locally with Clawdbot instance
AI Disclosure
Greptile Overview
Greptile Summary
This PR updates the embedded Pi runner startup so the session’s
extensionRunneris bound in embedded mode, enabling compaction extensions that depend onctx.modelto generate real summaries (instead of falling back to “Summary unavailable…”). It also adds stricter handling for active tool name extraction, model setting (API key presence), and forwards compaction completion/error callbacks.Change is localized to the embedded run attempt path (
src/agents/pi-embedded-runner/run/attempt.ts) and a corresponding changelog entry.Confidence Score: 4/5
isIdle/hasPendingMessages) and whethercompact()should be awaitable, but no obvious runtime errors are introduced in the diff shown.(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- CLAUDE.md (source)dashboard- AGENTS.md (source)