Skip to content

fix(agent-key): restore getAgentDisplayName for HTTP-header-safe agent keys#3371

Open
FuDesign2008 wants to merge 4 commits intocode-yeongyu:devfrom
FuDesign2008:fix/agent-key-zwsp-header-leak
Open

fix(agent-key): restore getAgentDisplayName for HTTP-header-safe agent keys#3371
FuDesign2008 wants to merge 4 commits intocode-yeongyu:devfrom
FuDesign2008:fix/agent-key-zwsp-header-leak

Conversation

@FuDesign2008
Copy link
Copy Markdown

@FuDesign2008 FuDesign2008 commented Apr 12, 2026

Summary

  • Commit 79b4b0a reintroduced ZWSP into config.agent object keys by switching remapAgentKeysToDisplayNames to call getAgentListDisplayName, which returns ZWSP-prefixed runtime names (e.g. \u200BSisyphus - Ultraworker).
  • These keys are used as HTTP header values in the OpenCode /agent API; ZWSP violates RFC 7230, causing TypeError: Header 'mode_type' has invalid value.
  • This is a regression of the same bug previously documented and fixed in Breaking change: ZWSP (U+200B) prefix added to agent names breaks prompt_async API consumers #3238.

Root Cause

- const displayName = getAgentListDisplayName(key)  // "\u200BSisyphus - Ultraworker" — ZWSP in key!
+ const displayName = getAgentDisplayName(key)       // "Sisyphus - Ultraworker"  — HTTP-safe

The name field inside each agent object continues to use getAgentRuntimeName(key) (with ZWSP prefix), so OpenCode's localeCompare sort ordering is fully preserved.

Changes

File Change
src/plugin-handlers/agent-key-remapper.ts Revert key lookup to getAgentDisplayName; name field keeps getAgentRuntimeName
src/plugin-handlers/agent-key-remapper.test.ts Restore assertions that object keys contain no ZWSP; restore the deleted expect(name).not.toContain("\u200B") guard
src/plugin-handlers/agent-config-handler.test.ts Revert constants to getAgentDisplayName

Testing

bun run typecheck   ✅
bun run build       ✅
bun test src/plugin-handlers/agent-key-remapper.test.ts src/plugin-handlers/agent-config-handler.test.ts
 18 pass / 0 fail   ✅

Closes #3281


Summary by cubic

Removes ZWSP from agent keys and name fields to keep /agent HTTP headers RFC 7230 compliant. Enforces core agent ordering via reorderAgentsByPriority (display-name matching + JS key insertion) and treats the order field as metadata only; fixes default_agent, command routing, and priority matching.

  • Bug Fixes
    • Use getAgentDisplayName for agent keys, agent.name, default_agent, command agent mapping, and core priority display names; ZWSP is forbidden everywhere.
    • Update AGENTS.md to clarify ordering is guaranteed by reorderAgentsByPriority and that order is metadata; refresh tests to assert clean keys/names and verify routing/ordering against clean display names.

Written for commit 9bd9dfa. Summary will update on new commits.

…t keys

Commit 79b4b0a reintroduced ZWSP characters into config.agent object keys by
switching remapAgentKeysToDisplayNames to use getAgentListDisplayName, which
returns ZWSP-prefixed runtime names (e.g. U+200B + 'Sisyphus - Ultraworker').

These object keys are used as HTTP header values in the OpenCode /agent API.
ZWSP is an invalid RFC 7230 header character, causing:
  TypeError: Header 'mode_type' has invalid value

Fix: revert the key lookup to getAgentDisplayName (no ZWSP prefix). The name
field inside each agent object continues to use getAgentRuntimeName (with ZWSP)
so OpenCode's localeCompare sort ordering is preserved.

Closes code-yeongyu#3281
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes a regression causing HTTP header validation errors by removing ZWSP from agent keys while preserving sorting via the internal name field. Tests verify the fix.

@FuDesign2008
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 12, 2026
…, and priority ordering

Three more code paths still used getAgentListDisplayName (ZWSP-prefixed) where
the keys must be HTTP-header-safe (no ZWSP):

- agent-config-handler.ts: default_agent was set to getAgentRuntimeName(),
  causing mismatches with the clean agent keys and ZWSP in the displayed name

- agent-priority-order.ts: CORE_AGENT_ORDER.displayName used
  getAgentListDisplayName() for key matching, so core agents were not found
  and priority ordering silently broke

- command-config-handler.ts: cmd.agent was remapped to getAgentListDisplayName(),
  making command routing fail to resolve against clean agent keys

All three now use getAgentDisplayName() (no ZWSP). The name field inside each
agent object continues to use getAgentRuntimeName() (ZWSP) for localeCompare
sort ordering.

Closes code-yeongyu#3281
@FuDesign2008
Copy link
Copy Markdown
Author

Follow-up: extended ZWSP fix to three more code paths (see commit a3143d0)

After the initial fix to agent-key-remapper.ts, three more places still used getAgentListDisplayName (ZWSP-prefixed) where clean names are required:

File Problem Fix
agent-config-handler.ts default_agent set to getAgentRuntimeName() → ZWSP leaked into startup display name and broke agent lookup getAgentDisplayName()
agent-priority-order.ts CORE_AGENT_ORDER.displayName used getAgentListDisplayName() for key matching → core agents not found → priority ordering silently broke getAgentDisplayName()
command-config-handler.ts cmd.agent remapped to getAgentListDisplayName() → command routing failed to resolve against clean agent keys getAgentDisplayName()

All 147 tests pass after the fix.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 6 files (changes from recent commits).

Auto-approved: This PR correctly restores HTTP-safe agent keys by removing ZWSP, fixing a documented regression causing header errors while maintaining UI sort order via the internal name field.

…er violation

OpenCode passes the agent name field as the mode_type HTTP header value.
ZWSP in the name field causes TypeError: Header 'mode_type' has invalid value,
blocking all agent invocations.

Changed rewriteAgentNameForListDisplay to use getAgentDisplayName (clean) instead
of getAgentRuntimeName (ZWSP-prefixed). Agent ordering is handled deterministically
by reorderAgentsByPriority via the explicit order field (1-4), not by name sorting.

Node.js localeCompare treats ZWSP as ignorable (returns 0), confirming the ZWSP
sorting mechanism was never effective. Updated AGENTS.md to document the order
field as the canonical ordering mechanism and prohibit ZWSP in the name field.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/plugin-handlers/AGENTS.md">

<violation number="1" location="src/plugin-handlers/AGENTS.md:16">
P3: Don't describe `order` as the mechanism that guarantees ordering; this repo only stores it, while actual ordering still comes from display-name handling.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

The order field is metadata stored by this repo; actual ordering
is guaranteed by reorderAgentsByPriority matching core agents by
display name and leveraging JavaScript key-insertion order.

Addresses cubic review: P3 — do not describe order as the mechanism
that guarantees ordering.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Requires human review: PR description claims the 'name' field keeps ZWSP, but the code diff shows it is removed. This contradicts the previous requirement that ZWSP in 'name' is needed for UI sorting.

@FuDesign2008
Copy link
Copy Markdown
Author

Re: cubic P3 — order as ordering mechanism

Fixed in commit 9bd9dfa (docs(agent-key): clarify ordering mechanism in AGENTS.md).

Agreed with the feedback. The corrected wording now reads:

reorderAgentsByPriority iterates over CANONICAL_CORE_AGENT_ORDER, matches each core agent by display name, and inserts it first into the result object. JavaScript preserves string-key insertion order (ES2015+), so core agents always appear before custom agents regardless of alphabetical order.

The order field (integers 1-4) is stored as metadata this repo can provide — this repo only stores it; whether OpenCode consumes it for rendering is outside this codebase's control.

The actual ordering guarantee is the display-name matching loop + JS key-insertion order in reorderAgentsByPriority. The order field is supplementary metadata only.

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.

[Bug]: Header 'x-opencode-agent-name' has invalid value: '​Atlas (Plan Executor)'

1 participant