fix(pi): accept an array systemPrompt and keep the documentation-paragraph relocation - #213
Open
iceteaSA wants to merge 2 commits into
Open
fix(pi): accept an array systemPrompt and keep the documentation-paragraph relocation#213iceteaSA wants to merge 2 commits into
iceteaSA wants to merge 2 commits into
Conversation
Pi's context.systemPrompt permits an array of segments, but buildAnthropicRequest only handled a single string. Each non-empty segment now becomes its own sanitized text block in top-level system[], with empty and whitespace-only entries skipped. Co-authored-by: randomvariable <redacted@localhost>
Normalize host-provided prompt segments into the same paragraph-aware path as string prompts so Pi documentation stays out of top-level system[]. Update array expectations for the shared relocation and add byte-equivalence coverage. Co-authored-by: randomvariable <redacted@localhost>
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Host as Pi Host (oh-my-pi)
participant Convert as buildAnthropicRequest
participant Split as splitPiSystemPrompt
participant Cache as Cache Control Logic
participant API as Anthropic API
Note over Host,API: System Prompt Normalization Flow
Host->>Convert: context.systemPrompt (string | readonly string[])
alt Array systemPrompt
Convert->>Convert: Filter non-empty segments (isNonEmptyText)
Convert->>Convert: Trim each segment
Convert->>Convert: Join with '\n\n'
else String systemPrompt
Convert->>Convert: Pass through as-is
end
Convert->>Split: normalizedSystemPrompt
Split-->>Convert: { systemText, cachedBlock }
alt systemText exists
Convert->>Convert: Push text block to system[]
end
alt cachedBlock exists
Convert->>Convert: Prepend cached prompt block to first user message
Convert->>Cache: Add cache_control: { type: 'ephemeral' }
end
Convert->>API: Request body with system[] + messages[]
Note over API: Documentation paragraph NOT in system[]<br/>(avoids OAuth billing rejection)
alt Happy Path (valid request)
API-->>Convert: 200 OK
else Documentation paragraph in system[]
API-->>Convert: 400/401 (billing rejection)
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pi-compatible hosts (oh-my-pi) pass
context.systemPromptas an array of segments;buildAnthropicRequestonly handled a string, so the prompt was dropped. This accepts the array form.The array is joined with
\n\nand routed through the same path the string branch uses (splitPiSystemPrompt→prependCachedPromptBlock), so Pi's documentation paragraph still moves out of top-levelsystem[]into the first user message's cached block. An earlier shape of this change pushed each segment straight intosystem[], which would have reintroduced the OAuth billing rejection that relocation exists to avoid — the new test pins byte-equivalence between the array and string paths, and it fails if the array takes a separate branch.Credit: original patch by randomvariable (CortexKit Discord, 2026-09-03), who could not open the PR themselves. Reviewed, reworked to share the relocation path, and re-authored here with
Co-authored-by.Changes
packages/pi/src/convert.ts—context.systemPrompt: string | readonly string[]; array segments are trimmed, empties dropped (isNonEmptyText, shared with the string branch), joined, and handed to the existing relocation path. The SDK type declaresstring; the array form is a host divergence, noted at the branch.packages/pi/src/tests/convert.test.ts— array happy paths, empty/whitespace segments, empty array, and the relocation contract:arrayBody.systemandarrayBody.messagesequal the string path's output; the docs paragraph is not insystem[].Verification
packages/pi: 98 pass / 0 fail · root typecheck 0 · format/biome clean.system[4]); reverting to that shape reddens it again.Base:
upstream/main360b68e(v1.22.0).Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Fixes
buildAnthropicRequestdropping Pi-compatible hosts' arraysystemPromptvalues, which previously only handled strings. Array segments are now joined and routed through the same docs-paragraph relocation path as string prompts, keeping Pi's documentation paragraph out of top-levelsystem[]to avoid OAuth billing rejection.\n\n.Written for commit 7da8919. Summary will update on new commits.