[GH-ISSUE #6107] [Bug] Kuna regex errors omit the structured pattern issue #3740

Closed
opened 2026-10-31 00:43:33 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @coygeek on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/6107

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

MCP or agent integration

Observed behavior

Kuna-backed search_strings and search_procedures with pattern: "[" and mode: "regex" correctly return invalid_request / invalid_input with input-contract recovery, but omit details.issues. Remediation says “Correct the listed fields” although none are listed. The message does identify invalid regex syntax. Correcting the pattern to fixture succeeded for both operations.

Reproduction

Place this focused test under tests/boundary/mcp/kunaInputDiagnostics.test.ts and run npx vitest run tests/boundary/mcp/kunaInputDiagnostics.test.ts --maxWorkers 1. This is the executed test extracted from a file that also contained two unrelated controls. It uses the repository simulated Kuna executable, the production Kuna client/inventory path, the real supervised regex worker, and the shared error projector. It does not launch a real Kuna engine or exercise MCP transport.

import { expect, it } from "vitest";
import { session } from "../providers/kuna/kunaSessionFixture.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";

it("projects invalid Kuna patterns from simulated provider inventories", async () => {
  const fixture = await session("rea-kuna-pattern-proof-", { stringRows: [{ text: "fixture", address: 4096 }], functions: [{ name: "fixture", addr: "0x1000" }] });
  const client = fixture.open();
  try {
    for (const operation of ["search_strings", "search_procedures"] as const) {
      const result = await client.execute(operation, { pattern: "[", mode: "regex" });
      expect(result.ok).toBe(false);
      if (result.ok) throw new Error("Invalid pattern accepted");
      const projected = projectAnalysisError(result.error);
      console.log("kuna-invalid", JSON.stringify(projected));
      expect(projected).toMatchObject({ code: "invalid_request", category: "invalid_input", retryable: false, recovery: { kind: "inspect_input_contract", operation } });
      expect(projected.details).toBeUndefined();
      expect(projected.remediation.action).toContain("Correct the listed fields");
      const valid = await client.execute(operation, { pattern: "fixture", mode: "regex" });
      expect(valid.ok).toBe(true);
      console.log("kuna-corrected", operation, JSON.stringify(valid.ok ? valid.value.result : valid.error));
    }
  } finally { expect((await client.close()).ok).toBe(true); }
}, 30000);

Both malformed-pattern requests reproduced the omission; both corrected-pattern controls succeeded; the client closed successfully. All three cases in the combined focused file passed.

Expected behavior

Keep the correct rejection, operation identity and recovery. Add a structured issue identifying pattern with an invalid_format reason so clients can map the error to the input contract. IDA already returns this issue for the same accepted search arguments.

Impact and scope

P3: incomplete structured diagnostics and misleading field-list wording for rejected caller input. Manual correction is possible from the existing message and succeeded in both controls. Valid matching results were preserved; no data loss, target mutation, or security boundary crossing was observed. Executed scope is the production Kuna boundary with simulated inventories for both search operations. Real Kuna engines, CLI delivery and MCP transport were not executed.

REA version

rea-agents 6.7.0; source revision 52415975942a4b9c53a817915b313ccc404f280e.

Runtime and platform

macOS 27.0.1 arm64; Node.js v26.12.0; Vitest 5.0.3. The contributor Node 24.18.0 pin was not exercised. No real Kuna engine was launched.

Target and artifact context

The repository simulated Kuna executable exports one string and one callable named fixture at 0x1000; its synthetic target is not executed.

Interface

Other

Earliest failure stage

Request parsing or validation

Relevant output or evidence

Observed string-search diagnostic:

{"code":"invalid_request","category":"invalid_input","message":"Invalid regex pattern: Invalid regular expression: /[/iu: Unterminated character class","retryable":false,"remediation":{"action":"Read the declared input schema or CLI usage for search_strings; if using MCP and the catalog may be stale, call tools/list. Correct the listed fields, then retry. Do not repeat the unchanged call."},"recovery":{"kind":"inspect_input_contract","operation":"search_strings"}}

details is absent. The procedure search returned the equivalent diagnostic with search_procedures. Both corrected searches returned the expected fixture result at 0x1000.

Typed outcome or recovery expected

Preserve invalid_request, invalid_input, retryable: false, and the existing inspect_input_contract operation. Include details.issues: [{"path":["pattern"],"reason":"invalid_format","message":"Supply a valid regular expression."}] or an equivalent bounded pattern diagnostic.

Analysis or suspected cause

Source-derived: Kuna string search and procedure search delegate to the matcher without an invalid-pattern callback. The default invalid-pattern constructor supplies userMessage but no input issues. The projector emits details only for nonempty issues, whereas input remediation always refers to listed fields. The producing matcher knows the rejected argument and can preserve that identity.

Additional context

Related #5986 concerns the separate Hopper invalid-pattern override, which creates HopperRemoteError and loses input-contract recovery as well as the pattern issue. #5980 concerns an address-normalization constructor in Kuna list_strings. Changing either existing constructor leaves this default matcher constructor unchanged, although a shared input-error helper could support their repairs. #4689 concerns attribution of failed callable inventory loads, which succeed here.

Fetched main d8a9673fc44fde4bd30ff98c241886e6683580ca changes regex resource-limit recovery but leaves this invalid-pattern fallback and the relevant Kuna call sites unchanged. That later revision was inspected, not executed.

Originally created by @coygeek on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/6107 ### Before submitting - [x] I searched the open and closed issues for a related report. - [x] I removed credentials, tokens, private paths, and sensitive target data. ### Area MCP or agent integration ### Observed behavior Kuna-backed `search_strings` and `search_procedures` with `pattern: "["` and `mode: "regex"` correctly return `invalid_request` / `invalid_input` with input-contract recovery, but omit `details.issues`. Remediation says “Correct the listed fields” although none are listed. The message does identify invalid regex syntax. Correcting the pattern to `fixture` succeeded for both operations. ### Reproduction Place this focused test under `tests/boundary/mcp/kunaInputDiagnostics.test.ts` and run `npx vitest run tests/boundary/mcp/kunaInputDiagnostics.test.ts --maxWorkers 1`. This is the executed test extracted from a file that also contained two unrelated controls. It uses the repository simulated Kuna executable, the production Kuna client/inventory path, the real supervised regex worker, and the shared error projector. It does not launch a real Kuna engine or exercise MCP transport. ```ts import { expect, it } from "vitest"; import { session } from "../providers/kuna/kunaSessionFixture.js"; import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js"; it("projects invalid Kuna patterns from simulated provider inventories", async () => { const fixture = await session("rea-kuna-pattern-proof-", { stringRows: [{ text: "fixture", address: 4096 }], functions: [{ name: "fixture", addr: "0x1000" }] }); const client = fixture.open(); try { for (const operation of ["search_strings", "search_procedures"] as const) { const result = await client.execute(operation, { pattern: "[", mode: "regex" }); expect(result.ok).toBe(false); if (result.ok) throw new Error("Invalid pattern accepted"); const projected = projectAnalysisError(result.error); console.log("kuna-invalid", JSON.stringify(projected)); expect(projected).toMatchObject({ code: "invalid_request", category: "invalid_input", retryable: false, recovery: { kind: "inspect_input_contract", operation } }); expect(projected.details).toBeUndefined(); expect(projected.remediation.action).toContain("Correct the listed fields"); const valid = await client.execute(operation, { pattern: "fixture", mode: "regex" }); expect(valid.ok).toBe(true); console.log("kuna-corrected", operation, JSON.stringify(valid.ok ? valid.value.result : valid.error)); } } finally { expect((await client.close()).ok).toBe(true); } }, 30000); ``` Both malformed-pattern requests reproduced the omission; both corrected-pattern controls succeeded; the client closed successfully. All three cases in the combined focused file passed. ### Expected behavior Keep the correct rejection, operation identity and recovery. Add a structured issue identifying `pattern` with an `invalid_format` reason so clients can map the error to the input contract. [IDA already returns this issue](https://github.com/morluto/rea/blob/52415975942a4b9c53a817915b313ccc404f280e/src/ida/IdaInput.ts#L61-L76) for the same accepted search arguments. ### Impact and scope P3: incomplete structured diagnostics and misleading field-list wording for rejected caller input. Manual correction is possible from the existing message and succeeded in both controls. Valid matching results were preserved; no data loss, target mutation, or security boundary crossing was observed. Executed scope is the production Kuna boundary with simulated inventories for both search operations. Real Kuna engines, CLI delivery and MCP transport were not executed. ### REA version rea-agents 6.7.0; source revision `52415975942a4b9c53a817915b313ccc404f280e`. ### Runtime and platform macOS 27.0.1 arm64; Node.js v26.12.0; Vitest 5.0.3. The contributor Node 24.18.0 pin was not exercised. No real Kuna engine was launched. ### Target and artifact context The repository simulated Kuna executable exports one string and one callable named `fixture` at `0x1000`; its synthetic target is not executed. ### Interface Other ### Earliest failure stage Request parsing or validation ### Relevant output or evidence Observed string-search diagnostic: ```json {"code":"invalid_request","category":"invalid_input","message":"Invalid regex pattern: Invalid regular expression: /[/iu: Unterminated character class","retryable":false,"remediation":{"action":"Read the declared input schema or CLI usage for search_strings; if using MCP and the catalog may be stale, call tools/list. Correct the listed fields, then retry. Do not repeat the unchanged call."},"recovery":{"kind":"inspect_input_contract","operation":"search_strings"}} ``` `details` is absent. The procedure search returned the equivalent diagnostic with `search_procedures`. Both corrected searches returned the expected `fixture` result at `0x1000`. ### Typed outcome or recovery expected Preserve `invalid_request`, `invalid_input`, `retryable: false`, and the existing `inspect_input_contract` operation. Include `details.issues: [{"path":["pattern"],"reason":"invalid_format","message":"Supply a valid regular expression."}]` or an equivalent bounded pattern diagnostic. ### Analysis or suspected cause Source-derived: [Kuna string search](https://github.com/morluto/rea/blob/52415975942a4b9c53a817915b313ccc404f280e/src/kuna/KunaStringQueries.ts#L83-L91) and [procedure search](https://github.com/morluto/rea/blob/52415975942a4b9c53a817915b313ccc404f280e/src/kuna/KunaSessionClient.ts#L741-L750) delegate to the matcher without an invalid-pattern callback. [The default invalid-pattern constructor](https://github.com/morluto/rea/blob/52415975942a4b9c53a817915b313ccc404f280e/src/process/RegexMatcher.ts#L117-L125) supplies `userMessage` but no input issues. [The projector](https://github.com/morluto/rea/blob/52415975942a4b9c53a817915b313ccc404f280e/src/domain/analysisErrorProjection.ts#L333-L344) emits details only for nonempty issues, whereas [input remediation](https://github.com/morluto/rea/blob/52415975942a4b9c53a817915b313ccc404f280e/src/domain/analysisErrorPresentation.ts#L133-L134) always refers to listed fields. The producing matcher knows the rejected argument and can preserve that identity. ### Additional context Related #5986 concerns the separate Hopper invalid-pattern override, which creates `HopperRemoteError` and loses input-contract recovery as well as the pattern issue. #5980 concerns an address-normalization constructor in Kuna `list_strings`. Changing either existing constructor leaves this default matcher constructor unchanged, although a shared input-error helper could support their repairs. #4689 concerns attribution of failed callable inventory loads, which succeed here. Fetched main `d8a9673fc44fde4bd30ff98c241886e6683580ca` changes regex resource-limit recovery but leaves this invalid-pattern fallback and the relevant Kuna call sites unchanged. That later revision was inspected, not executed.
Author
Owner

@XinwangTao commented on GitHub (Oct 22, 2026):

确认,这是自相矛盾的诊断:识别了 invalid regex syntax、返回了 input-contract recovery,但 details.issues 为空,remediation 还写着 "Correct the listed fields" 却一个字段都没列——调用者完全无从下手。既然 IDA 路径已能通过同一投影器返回结构化 pattern issue,说明是 Kuna 侧没把 pattern 诊断喂进投影器。建议 regex 编译失败时把 pattern 原文、错误位置/偏移(若可得)和失败原因放入 details.issues;同时 remediation 文案在 issues 为空时必须禁用 "listed fields" 这类说法。

<!-- gh-comment-id:6330517032 --> @XinwangTao commented on GitHub (Oct 22, 2026): 确认,这是自相矛盾的诊断:识别了 invalid regex syntax、返回了 input-contract recovery,但 details.issues 为空,remediation 还写着 "Correct the listed fields" 却一个字段都没列——调用者完全无从下手。既然 IDA 路径已能通过同一投影器返回结构化 pattern issue,说明是 Kuna 侧没把 pattern 诊断喂进投影器。建议 regex 编译失败时把 pattern 原文、错误位置/偏移(若可得)和失败原因放入 details.issues;同时 remediation 文案在 issues 为空时必须禁用 "listed fields" 这类说法。
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#3740
No description provided.