Skip to content

fix(pi-embed): start the extensions, and refuse a metered run that is not on the gateway model - #1732

Merged
pyramation merged 1 commit into
mainfrom
feat/pi-embed-bind-extensions
Aug 15, 2026
Merged

fix(pi-embed): start the extensions, and refuse a metered run that is not on the gateway model#1732
pyramation merged 1 commit into
mainfrom
feat/pi-embed-bind-extensions

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

An embedded run loaded its extensions and never started them, so the metered lane silently didn't take effect.

pi emits session_start from session.bindExtensions(...) — a call its own CLI modes make once their UI exists, and createAgentSession never makes. The metered lane selects its model from exactly that event:

// @agentic-kit/pi-ext-metered-model
pi.registerProvider(providerName, config);
pi.on('session_start', async (_e, ctx) => pi.setModel(ctx.modelRegistry.find(providerName, modelId)));

So startRun returned a session on whatever provider key the process happened to hold — outside the gateway, unmetered, and indistinguishable from a healthy run. Verified against the installed pi: the same session reports model: null without the bind and constructive-gateway/deepseek-v4-pro with it.

startRun now fires it, then insists on the result:

const result = await pi.createAgentSession({ ... });
await result.session.bindExtensions({});
assertMeteredModelSelected(run, result.session);   // throws unless
                                                   // model === `${lane.providerName}/${lane.selectedModel}`

The assertion only applies when the metered lane selected a model (selectModel: false and log-only embeddings are unaffected). Under-reported usage is the failure this lane exists to prevent, so a session that ended up elsewhere fails the run rather than billing nothing.

Link to Devin session: https://app.devin.ai/sessions/450ce6d6659c47759c184ae6ec19a2a8
Requested by: @pyramation

… not on the gateway model

pi emits `session_start` from `bindExtensions`, which its CLI modes call once their UI exists — `createAgentSession` never does. An embedder that skips it loads the extensions but never starts them, and the metered lane selects its model from exactly that event: so a run stayed on whatever provider key the process happened to hold, outside the gateway and unmetered, while looking healthy. `startRun` now fires it, then asserts the session really is on `<gateway>/<selected model>` and fails otherwise — under-reported usage is the one failure this lane exists to prevent.
@pyramation pyramation self-assigned this Aug 15, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit f9f1895 into main Aug 15, 2026
20 checks passed
@pyramation
pyramation deleted the feat/pi-embed-bind-extensions branch August 15, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant