Skip to content

fix(pi): preserve literal provider keys and login context - #530

Merged
stamp-build[bot] merged 1 commit into
mainfrom
agent/otter/pi-provider-auth
Oct 29, 2026
Merged

stamp-build[bot] merged 1 commit into
mainfrom
agent/otter/pi-provider-auth

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Otter from open-agent-runtime opened this pull request through Stamp
View in Stamp →


Pi provider keys supplied through setApiKey or API-key login could be interpreted as shell commands or environment references when Pi read them back. Encode these inputs using Pi's native literal escapes before its login flow stores them. The same encoder handles existing session MCP values; OAuth answers and non-secret provider settings retain their native meaning.

Also export createPiProviderAuth from @botiverse/oar/runtimes/pi without eagerly loading the SDK or other adapters, forward native getDeviceId/agentName login options, and expose per-prompt cancellation combined with host cancellation. Pending input rejects on abort even if the host callback never settles. The login spec and Pi mapping document these behaviors and the audit of credential/config write paths.

Behavior changes: facade-supplied API keys are stored as literal values. Existing native configuration is not migrated; manually configured commands/references retain Pi's behavior on resolved reads. Hosts provide and retain the stable UUID needed by Pi's ChatGPT login.

Validation: full CI=1 pnpm run check (2,385 unit tests, 18 mock behavior passes), both package builds, packed clean-install/typecheck including the isolated Pi entry, and three native Pi MCP tests. New regressions exercise Pi 1.4.0's actual login, credential file, resolver and request-auth path with synthetic special-character keys while command execution is forbidden; they also cover cancellation, late answers, OAuth preservation and native login options. No real account or model request was used for provider authentication tests.

Raft task #108.

@stamp-build
stamp-build Bot force-pushed the agent/otter/pi-provider-auth branch from ee08e21 to cc94df9 Compare October 29, 2026 15:45
@stamp-build
stamp-build Bot merged commit 23c3e3e into main Oct 29, 2026
34 checks passed
@stamp-build
stamp-build Bot deleted the agent/otter/pi-provider-auth branch October 29, 2026 16:14
@stamp-build stamp-build Bot mentioned this pull request Oct 29, 2026
stamp-build Bot added a commit that referenced this pull request Oct 29, 2026
<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg"
width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_6846505f155168fdf31f0def681aaba5"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

Patch release: a Pi provider-key security fix, a Qwen reply fix, and
structured configured-credential sources. No API breaking changes.

## Security

### Pi: provider API keys are stored as literal values (#530)
Pi resolves stored credential values: a value starting with `!` runs the
rest as a shell command, and `$NAME` / `${NAME}` expand environment
variables. Through 0.76.2, keys passed to the Pi provider facade
(`createPiProviderAuth`: `setApiKey`, and the secret prompts of
`login(providerId, "api_key", ...)`) were stored unchanged, so a key
such as `!some-command` or one containing `$HOME` was executed or
expanded when Pi read it. OAR now writes those values with Pi's own
escapes (every `$` as `$$`, a leading `!` as `$!`), so Pi reads back
exactly the key that was supplied, never runs a command and never
expands a variable. Verified with Pi 1.4.0's own storage and resolver.
OAuth answers and non-secret prompts are unchanged. Keys stored by
earlier versions are not rewritten: a stored key that contains `$` or
starts with `!` should be stored again with 0.76.3. If you deliberately
relied on the facade to store a `$VAR` or `!command` reference, that now
stays literal; write such an entry to Pi's `auth.json` yourself, where
Pi's resolution still applies.

## Fixes

### Qwen: replies after thinking were reported twice (#528)
With Qwen Code 0.26.3, when a response streams thinking and then text,
Qwen sends the final text snapshot with a different message id than the
stream it completes, without a new `message_start`. OAR counted the
streamed text and the snapshot, so the turn's reply text contained the
answer twice (on a real Model Studio Token Plan endpoint the expected
22-character answer came back as 44 characters; a local reproduction
confirmed it was the answer twice). OAR now recognizes the snapshot from
Qwen's block sequence (a block stop followed by its single-block
snapshot), never by comparing text, so repeated paragraphs and identical
answers in consecutive turns are kept. Reasoning was never mixed into
the reply. Reported upstream as QwenLM/qwen-code#15875.

### Pi: "Sign in with ChatGPT" through the provider facade (#530)
In 0.76.2, `login("openai", "oauth", ...)` through
`createPiProviderAuth` always failed because Pi requires a device id and
OAR could not pass one. `login` now takes an optional fourth argument,
`ProviderLoginOptions` (`getDeviceId`, `agentName`), passed to Pi
unchanged. ChatGPT sign-in works when the host supplies `getDeviceId`
returning a stable UUID for its installation; the host creates and keeps
that UUID, and without it Pi still rejects the flow.

## Behavior changes

### `configured` on unknown login status (#529)
`AuthStatus` `unknown` has an optional `configured?: readonly string[]`.
A nonempty list means the reader found local authentication
configuration from those sources without validating it; each entry is a
human-readable label naming the source (for example `environment:
OPENAI_API_KEY`), never a value; labels are for display, not parsing.
Query failures omit it, and its absence does not mean nothing is
configured. Qwen fills it from its local configuration sources and
Cursor from `CURSOR_API_KEY`. Hosts can now tell
configured-but-unverified from unreadable status without parsing
`detail`.

### Pi provider login: prompt cancellation (#530)
Each `ProviderLoginPrompt` now carries an optional `signal` that aborts
when that input is no longer needed (for example the OAuth browser
callback wins) or when the host cancels; close the input UI when it
fires. The pending Pi prompt is rejected even if the host's prompt
callback never returns. Only `interaction.signal` cancels the whole
login, as before.

### Pi provider facade from the Pi entry (#530)
`createPiProviderAuth` is also exported from
`@botiverse/oar/runtimes/pi`, which loads the Pi SDK only when a facade
is created, so a host can use it without loading the root entry and
every runtime.

## TypeScript
- `AuthStatus` `unknown` gains optional `configured` (#529).
- New `ProviderLoginOptions`; `ProviderAuthFacade.login` gains an
optional fourth parameter; `ProviderLoginPrompt` gains optional
`signal`; `PiProviderAuthOptions` is also exported from
`@botiverse/oar/runtimes/pi` (#530). Existing callers and custom
`ProviderAuthFacade` implementations keep compiling.

Co-authored-by: Cindy <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

0 participants