[GH-ISSUE #1632] [Bug] Pi code-mode reference budget drops selector types during REA discovery #550

Closed
opened 2026-10-15 18:26:05 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @N0zoM1z0 on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/1632

Before submitting

  • Searched related integration issues, including #1587.
  • Removed credentials, private paths and target data.

Area

MCP / agent integration: Pi code-mode tool discovery.

Observed behavior

Pi 1.1.0 discovers REA through its native MCP/code-mode workflow, but the generated SDK declaration for trace_application_feature presents the discriminated seed selector as unknown. The advertised REA input schema retains its valid object alternatives. In two independent model transcripts, the generated declaration contained seed: unknown; the agent guessed invalid selector fields and recovered after client-side schema rejection.

Two fresh native Pi CLI bundle runs both answered the routes, backend, retry count and static-vs-runtime question correctly. One used seven REA calls without errors; the other used seventeen, including one invalid {kind: "module", path: "app.js"} seed. An earlier imported-CLI experiment also recovered from two invalid seeds. These are successful final answers with non-uniform call quality, not a strict zero-error pass.

Reproduction

  1. Install Pi 1.1.0 in a private directory and create independent HOME/XDG directories and a project Git root.
  2. Install the current REA skill and MCP registration using public rea setup --client pi --yes. Use Pi's default shared personal skill discovery, with no explicit skill setting.
  3. Run native pi --offline --provider openai-codex --model gpt-6-sol --thinking low --no-session --no-context-files --mode json -p ... against an inert two-module Unicode-path bundle.
  4. Inspect the code-mode SDK declaration and complete tool start/end events, rather than exit code alone.

Expected behavior

Native tool discovery preserves enough selector structure for an agent to construct valid calls without inventing fields.

REA version

Source head 1bba5545, skill 37; source package metadata still says 6.3.0. This is not the published npm 6.3.0 build.

Runtime and platform

Linux x64, Node 24.18.0, Pi 1.1.0, real Codex-backed gpt-6-sol. All runs sequential, one CPU and a 3 GiB process-tree ceiling.

Interface / earliest failure stage

MCP; client schema projection / agent call construction. All 170 advertised schemas and a real named-schema JavaScript Evidence call passed the independent native verifier.

Analysis and follow-up

A reduced repeat now establishes a Pi client declaration-projection defect: its per-schema $ref expansion budget is shared across properties, so earlier Evidence fields consume the budget before the selector is rendered. This does not establish a REA schema defect or prove that type loss alone caused the earlier model mistakes. The original runtime parameter validation remains effective. Do not loosen REA selectors, rewrite valid contracts to fit a single client, or hardcode client-specific recovery in the skill based on these observations. No production fix is proposed.

Refs #1587, #1627. Other model providers and native Windows/macOS remain unverified.

Confirmed boundary reduction (2026-10-10)

  • Repeated against source b09dd333, actual REA stdio tools/list, installed Pi/Pi-codemode 1.1.0, and its real MCP mapper and declaration renderer. The complete catalog contains 170 tools.
  • The actual trace_application_feature input renders seed: unknown. The same seed and $defs render their proper alternatives when isolated from earlier input fields. The full rendered input is about 3,191 characters, below the renderer's 16,000-character input limit.
  • A standalone, valid synthetic schema loses the selector after 32 preceding local-reference expansions; 0, 30 and 31 preserve it, while 32 and 33 lose it. No REA tool execution, MCP server or model is needed for that minimal case.
  • Native Pi CLI/codemode independently captured the same seed: unknown declaration while loading the installed skill and successfully calling real REA JavaScript analysis. All owned process lineages finished verified empty. That successful analysis is separate from the declaration failure.
  • Pi v1.1.0 renderer source has the shared 32-reference counter; the inspected upstream main ea448f454af474f3e2fe9733b331e17b0662f5d6 retains it. This is distinct from the broader omitted-constraint report pi#10707.

The correction belongs at the client declaration/resource-budget boundary. Do not weaken REA selectors or change valid contracts to hide it. No client patch or upstream publication has been made; this compatibility bug remains open. The new native repeat uses a deterministic loopback model and does not add live-model or Windows/macOS acceptance claims.

Originally created by @N0zoM1z0 on GitHub (Oct 10, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/1632 ### Before submitting - [x] Searched related integration issues, including #1587. - [x] Removed credentials, private paths and target data. ### Area MCP / agent integration: Pi code-mode tool discovery. ### Observed behavior Pi 1.1.0 discovers REA through its native MCP/code-mode workflow, but the generated SDK declaration for `trace_application_feature` presents the discriminated `seed` selector as `unknown`. The advertised REA input schema retains its valid object alternatives. In two independent model transcripts, the generated declaration contained `seed: unknown`; the agent guessed invalid selector fields and recovered after client-side schema rejection. Two fresh native Pi CLI bundle runs both answered the routes, backend, retry count and static-vs-runtime question correctly. One used seven REA calls without errors; the other used seventeen, including one invalid `{kind: "module", path: "app.js"}` seed. An earlier imported-CLI experiment also recovered from two invalid seeds. These are successful final answers with non-uniform call quality, not a strict zero-error pass. ### Reproduction 1. Install Pi 1.1.0 in a private directory and create independent HOME/XDG directories and a project Git root. 2. Install the current REA skill and MCP registration using public `rea setup --client pi --yes`. Use Pi's default shared personal skill discovery, with no explicit skill setting. 3. Run native `pi --offline --provider openai-codex --model gpt-6-sol --thinking low --no-session --no-context-files --mode json -p ...` against an inert two-module Unicode-path bundle. 4. Inspect the code-mode SDK declaration and complete tool start/end events, rather than exit code alone. ### Expected behavior Native tool discovery preserves enough selector structure for an agent to construct valid calls without inventing fields. ### REA version Source head 1bba5545, skill 37; source package metadata still says 6.3.0. This is not the published npm 6.3.0 build. ### Runtime and platform Linux x64, Node 24.18.0, Pi 1.1.0, real Codex-backed gpt-6-sol. All runs sequential, one CPU and a 3 GiB process-tree ceiling. ### Interface / earliest failure stage MCP; client schema projection / agent call construction. All 170 advertised schemas and a real named-schema JavaScript Evidence call passed the independent native verifier. ### Analysis and follow-up A reduced repeat now establishes a Pi client declaration-projection defect: its per-schema `$ref` expansion budget is shared across properties, so earlier Evidence fields consume the budget before the selector is rendered. This does **not** establish a REA schema defect or prove that type loss alone caused the earlier model mistakes. The original runtime parameter validation remains effective. Do not loosen REA selectors, rewrite valid contracts to fit a single client, or hardcode client-specific recovery in the skill based on these observations. No production fix is proposed. Refs #1587, #1627. Other model providers and native Windows/macOS remain unverified. ### Confirmed boundary reduction (2026-10-10) - Repeated against source `b09dd333`, actual REA stdio `tools/list`, installed Pi/Pi-codemode 1.1.0, and its real MCP mapper and declaration renderer. The complete catalog contains 170 tools. - The actual `trace_application_feature` input renders `seed: unknown`. The same seed and `$defs` render their proper alternatives when isolated from earlier input fields. The full rendered input is about 3,191 characters, below the renderer's 16,000-character input limit. - A standalone, valid synthetic schema loses the selector after 32 preceding local-reference expansions; 0, 30 and 31 preserve it, while 32 and 33 lose it. No REA tool execution, MCP server or model is needed for that minimal case. - Native Pi CLI/codemode independently captured the same `seed: unknown` declaration while loading the installed skill and successfully calling real REA JavaScript analysis. All owned process lineages finished verified empty. That successful analysis is separate from the declaration failure. - [Pi v1.1.0 renderer source](https://github.com/earendil-works/pi/blob/abe508e1b89912adde45528136c3221eb69acdd7/packages/codemode/src/declarations.ts) has the shared 32-reference counter; the inspected upstream main `ea448f454af474f3e2fe9733b331e17b0662f5d6` retains it. This is distinct from the broader omitted-constraint report [pi#10707](https://github.com/earendil-works/pi/issues/10707). The correction belongs at the client declaration/resource-budget boundary. Do not weaken REA selectors or change valid contracts to hide it. No client patch or upstream publication has been made; this compatibility bug remains open. The new native repeat uses a deterministic loopback model and does not add live-model or Windows/macOS acceptance claims.
bsakaguchi 2026-10-15 18:26:05 +00:00
Author
Owner

@N0zoM1z0 commented on GitHub (Oct 10, 2026):

Confirmed the declaration-loss boundary independently of model behavior. Pi 1.1.0 shares 32 local-reference expansions across the complete input; REA's earlier Evidence field consumes them before seed. The same selector renders correctly in isolation. Native Pi codemode discovery also returns seed: unknown, while real analysis, skill loading and cleanup succeed. Updated this issue's classification; parameter validation remains intact.

Minimal reproduction using @earendil-works/pi-codemode@1.1.0 (no REA/MCP/model required):

import { schemaToType } from '@earendil-works/pi-codemode/declarations';
const schema = {
  type: 'object',
  properties: {
    ...Object.fromEntries(Array.from({ length: 32 }, (_, i) =>
      [`a${String(i).padStart(2, '0')}`, { $ref: '#/$defs/text' }])),
    seed: { $ref: '#/$defs/selector' },
  },
  required: ['seed'],
  $defs: {
    text: { type: 'string' },
    selector: { type: 'object',
      properties: { kind: { const: 'module' }, value: { type: 'string' } },
      required: ['kind', 'value'],
    },
  },
};
console.log(schemaToType(schema)); // seed: unknown
delete schema.properties.a00;
console.log(schemaToType(schema)); // seed: { kind: "module"; value: string; }

This is a client projection bug, not evidence that the REA union is invalid. Keep the issue open for a bounded client-side correction; the reduced result does not prove that it caused every earlier model mistake.

<!-- gh-comment-id:6103137160 --> @N0zoM1z0 commented on GitHub (Oct 10, 2026): Confirmed the declaration-loss boundary independently of model behavior. Pi 1.1.0 shares 32 local-reference expansions across the complete input; REA's earlier Evidence field consumes them before `seed`. The same selector renders correctly in isolation. Native Pi codemode discovery also returns `seed: unknown`, while real analysis, skill loading and cleanup succeed. Updated this issue's classification; parameter validation remains intact. Minimal reproduction using `@earendil-works/pi-codemode@1.1.0` (no REA/MCP/model required): ```js import { schemaToType } from '@earendil-works/pi-codemode/declarations'; const schema = { type: 'object', properties: { ...Object.fromEntries(Array.from({ length: 32 }, (_, i) => [`a${String(i).padStart(2, '0')}`, { $ref: '#/$defs/text' }])), seed: { $ref: '#/$defs/selector' }, }, required: ['seed'], $defs: { text: { type: 'string' }, selector: { type: 'object', properties: { kind: { const: 'module' }, value: { type: 'string' } }, required: ['kind', 'value'], }, }, }; console.log(schemaToType(schema)); // seed: unknown delete schema.properties.a00; console.log(schemaToType(schema)); // seed: { kind: "module"; value: string; } ``` This is a client projection bug, not evidence that the REA union is invalid. Keep the issue open for a bounded client-side correction; the reduced result does not prove that it caused every earlier model mistake.
Author
Owner

@akushonkamen commented on GitHub (Oct 11, 2026):

Claiming this — branch with the fix and a regression test coming shortly.

Reproduced the mechanism from the REA side of the wire: src/contracts/toolSchemaMetadata.ts:56-73 (toolInputSchemaWithMetadata) unconditionally requests shared definitions from the zod projection (libraryOptions: { reused: "ref" }, line 65), so the advertised trace_application_feature input schema ships as 22 $defs + 26 $ref (measured via McpServer+InMemoryTransport listTools(); zod's native projection is fully inlined, 0 refs). Pi 1.1.0's schemaToType shares 32 local-reference expansions across the whole input — the leading Evidence-typed field (native_observations) alone consumes 22, 46 total — so seed renders as unknown (reproduced locally with @earendil-works/pi-codemode@1.1.0 against the real advertised schema; fully inlining the refs restores the structured selector, reordering properties does not).

Planned REA-side change: inline local $refs within a bounded budget in the advertised input projection (reusing the inlineWithinBudget mechanism from src/contracts/compactInputSchema.ts:119-233) instead of unconditionally requesting reused: "ref". The contract itself is untouched — same selectors, same validation — only the wire representation. Naive inline-all is explicitly not the goal: it grows this one tool's advertised schema ~6.7 KB → ~25 KB and would aggravate the static-context pressure from #1554; the exact budget is negotiable. The regression test will assert the advertised schema stays within the client's 32-expansion budget.

Disclosure: this investigation and the fix are produced with AI assistance (a Claude Code agent operated by akushonkamen), per repo convention.

<!-- gh-comment-id:6105382324 --> @akushonkamen commented on GitHub (Oct 11, 2026): Claiming this — branch with the fix and a regression test coming shortly. Reproduced the mechanism from the REA side of the wire: `src/contracts/toolSchemaMetadata.ts:56-73` (`toolInputSchemaWithMetadata`) unconditionally requests shared definitions from the zod projection (`libraryOptions: { reused: "ref" }`, line 65), so the advertised `trace_application_feature` input schema ships as 22 `$defs` + 26 `$ref` (measured via `McpServer`+`InMemoryTransport` `listTools()`; zod's native projection is fully inlined, 0 refs). Pi 1.1.0's `schemaToType` shares 32 local-reference expansions across the whole input — the leading Evidence-typed field (`native_observations`) alone consumes 22, 46 total — so `seed` renders as `unknown` (reproduced locally with `@earendil-works/pi-codemode@1.1.0` against the real advertised schema; fully inlining the refs restores the structured selector, reordering properties does not). Planned REA-side change: inline local `$ref`s within a bounded budget in the advertised input projection (reusing the `inlineWithinBudget` mechanism from `src/contracts/compactInputSchema.ts:119-233`) instead of unconditionally requesting `reused: "ref"`. The contract itself is untouched — same selectors, same validation — only the wire representation. Naive inline-all is explicitly not the goal: it grows this one tool's advertised schema ~6.7 KB → ~25 KB and would aggravate the static-context pressure from #1554; the exact budget is negotiable. The regression test will assert the advertised schema stays within the client's 32-expansion budget. Disclosure: this investigation and the fix are produced with AI assistance (a Claude Code agent operated by akushonkamen), per repo convention.
Author
Owner

@akushonkamen commented on GitHub (Oct 11, 2026):

Opened #1749 with the fix and the budget regression test (rebased onto current main). It keeps the shared form for the 153 tools inside Pi's 32-expansion budget and re-projects only the 17 over-budget tools with the inline projection; per-tool measurements (expansion counts, wire sizes, the seed selector rendering) are in the PR description for the client-side vs REA-side arbitration.

<!-- gh-comment-id:6106631308 --> @akushonkamen commented on GitHub (Oct 11, 2026): Opened #1749 with the fix and the budget regression test (rebased onto current main). It keeps the shared form for the 153 tools inside Pi's 32-expansion budget and re-projects only the 17 over-budget tools with the inline projection; per-tool measurements (expansion counts, wire sizes, the `seed` selector rendering) are in the PR description for the client-side vs REA-side arbitration.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#550
No description provided.