openclaw - ✅(Solved) Fix Regression: cred.key?.trim is not a function on agents without ACP runtime after v2026.3.28 → v2026.3.31 upgrade [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58861Fetched 2026-04-08 02:31:50
View on GitHub
Comments
1
Participants
1
Timeline
8
Reactions
0
Participants
Timeline (top)
referenced ×5closed ×1cross-referenced ×1locked ×1

Error Message

lane task error: lane=session:agent:myclaw:feishu:direct:... error="TypeError: cred.key?.trim is not a function"

Root Cause

This is a regression bug introduced between v2026.3.28 and v2026.3.31. The issue appears to be in how credentials are processed for agents using the default runtime. The bug affects:

  • Every message processed by agents without ACP runtime
  • Agents with ACP runtime are unaffected

This is similar to Issue #37718 (cfg?.appId?.trim is not a function) but with cred.key instead of cfg.appId.

Fix Action

Fixed

PR fix notes

PR #58923: fix(auth): ensure credential key and token fields are strings during store load

Description (problem / solution / changelog)

Summary

  • Problem: Agents without ACP runtime crash on every incoming message with TypeError: cred.key?.trim is not a function (file: src/agents/models-config.providers.secrets.ts, line 134). This happens because cred.key can be a SecretRef object if users wrote it into auth-profiles.json instead of keyRef.
  • Root Cause: normalizeRawCredentialEntry in src/agents/auth-profiles/store.ts loads credentials from auth-profiles.json but does not validate the type of the key or token fields. If a user writes a SecretRef object into the key field instead of keyRef, the object passes through unchecked. Later, resolveApiKeyFromCredential calls cred.key?.trim(), which throws a TypeError because the object is truthy (so ?. does not short-circuit) but lacks a .trim() method.
  • Fix: Updated normalizeRawCredentialEntry to validate the type of key and token at load time. If they are non-string objects, we use coerceSecretRef to migrate them to keyRef/tokenRef (preserving the user's intent) and delete the invalid key/token field. This ensures downstream consumers always receive a string | undefined, preventing the crash.
  • What changed:
    • src/agents/auth-profiles/store.ts: Added type validation and SecretRef migration for key and token fields in normalizeRawCredentialEntry.
    • src/agents/auth-profiles.ensureauthprofilestore.test.ts: Added 4 test cases for non-string key handling: SecretRef migration, invalid type cleanup, existing keyRef preservation, and string passthrough.
  • What did NOT change (scope boundary): resolveApiKeyFromCredential, resolveApiKeyForProfile, collectApiKeyProfileAssignment, and all other downstream credential consumers remain unchanged. The fix is localized to the store loading normalization phase. No changes to the secrets runtime pipeline, OAuth flow, or gateway startup logic.

Reproduction

  1. Have an agent without runtime.type: "acp" configured (e.g., main, myclaw).
  2. In auth-profiles.json, set a credential's key to an object: {"source": "env", "provider": "default", "id": "OPENAI_API_KEY"}.
  3. Send any message to that agent via any channel (Feishu, Discord, etc.).
  4. Observe error in logs: lane task error: ... error="TypeError: cred.key?.trim is not a function".

Risk / Mitigation

  • Risk: The normalization might drop user credentials if they were intentionally using non-string formats not anticipated here.
  • Mitigation: We specifically use coerceSecretRef to detect and migrate valid SecretRef objects to keyRef rather than blindly dropping them. This preserves the configuration intent. Non-SecretRef non-string values (e.g., numbers, booleans) are safely dropped as they have no valid interpretation. Four targeted tests verify: (1) SecretRef migration works, (2) invalid types are cleaned, (3) existing keyRef is not overwritten, (4) valid string keys are untouched.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Gateway

Linked Issue/PR

Fixes #58861

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/agents/auth-profiles.ensureauthprofilestore.test.ts (modified, +249/-1)
  • src/agents/auth-profiles/store.ts (modified, +22/-0)

Code Example

lane task error: lane=session:agent:myclaw:feishu:direct:... 
error="TypeError: cred.key?.trim is not a function"
RAW_BUFFERClick to expand / collapse

Bug Description

After upgrading from v2026.3.28 to v2026.3.31, agents without ACP runtime configured fail with cred.key?.trim is not a function on every incoming message.

Steps to reproduce

  1. Have an agent without runtime.type: "acp" configured (e.g., main, myclaw)
  2. Send any message to that agent via Feishu
  3. Observe error in logs: cred.key?.trim is not a function

Expected behavior

Agents should handle messages normally without credential-related errors.

Actual behavior

Every message to affected agents causes this error:

lane task error: lane=session:agent:myclaw:feishu:direct:... 
error="TypeError: cred.key?.trim is not a function"

Environment

  • OpenClaw Version: 2026.3.31 (213a704)
  • Previous working version: v2026.3.28
  • Affected agents (no ACP runtime):
    • main - identity: "Main Agent", no runtime configured
    • myclaw (openclaw_ubuntu) - identity: "Ubuntu Bot", no runtime configured
  • Working agent (with ACP runtime):
    • coding - has runtime.type: "acp" with acpx backend - works fine ✅

Analysis

This is a regression bug introduced between v2026.3.28 and v2026.3.31. The issue appears to be in how credentials are processed for agents using the default runtime. The bug affects:

  • Every message processed by agents without ACP runtime
  • Agents with ACP runtime are unaffected

This is similar to Issue #37718 (cfg?.appId?.trim is not a function) but with cred.key instead of cfg.appId.

Changelog Relevance

v2026.3.31 has many breaking changes including:

  • Gateway/auth changes
  • Background tasks rewrite (SQLite-backed ledger)
  • ACPX/runtime version check changes

Impact

  • main and myclaw agents cannot process messages properly
  • Every message triggers the error
  • Only ACP-runtime agents (like coding) work correctly

extent analysis

TL;DR

Downgrade to v2026.3.28 or configure ACP runtime for affected agents as a temporary workaround.

Guidance

  • Review the changelog for v2026.3.31 to identify potential causes, focusing on gateway/auth changes and ACPX/runtime version check changes.
  • Verify if the error occurs only when cred.key is null or undefined, and if trimming is attempted on a non-string value.
  • Check if configuring runtime.type: "acp" for affected agents resolves the issue, as it does for the coding agent.
  • Investigate if the background tasks rewrite or SQLite-backed ledger changes are related to the credential processing issue.

Example

No code snippet is provided due to the lack of specific implementation details in the issue.

Notes

The fix may involve updating the credential processing logic to handle cases where cred.key is not a string or is null/undefined. The issue seems to be specific to agents without ACP runtime configured, suggesting a potential difference in how credentials are handled between runtime types.

Recommendation

Apply workaround: Configure ACP runtime for affected agents until a proper fix is available, as this has been shown to work for the coding agent.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Agents should handle messages normally without credential-related errors.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Regression: cred.key?.trim is not a function on agents without ACP runtime after v2026.3.28 → v2026.3.31 upgrade [1 pull requests, 1 comments, 1 participants]