fix(doctor,memory): guard apiKey.trim() against non-string SecretRef values#35665
fix(doctor,memory): guard apiKey.trim() against non-string SecretRef values#35665Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…values When openclaw.json uses environment variable references or vault-resolved secrets for API keys, the config resolver returns a SecretRef object instead of a plain string. Calling .trim() on this object throws TypeError: resolved?.remote?.apiKey?.trim is not a function, crashing `openclaw doctor` at the end of its run. Added typeof checks before calling .trim() in doctor-memory-search.ts and embeddings-ollama.ts. Closes openclaw#35444 Made-with: Cursor
Greptile SummaryThis PR fixes a real Changes verified:
Design rationale: Test coverage: Verdict: The fix is correct, minimal, and well-scoped to the reported issue. Confidence Score: 4/5
Last reviewed commit: 5a3ce5a |
|
Thanks for the contribution here, and for helping narrow down the SecretRef doctor crash. We merged #36835, which supersedes this PR and fixes the broader doctor/memory SecretRef surface in one place, including the related runtime embedding paths. I’m closing this as superseded by #36835, but I appreciate the fix and the investigation that went into it. |
Summary
openclaw doctorcrashes withTypeError: resolved?.remote?.apiKey?.trim is not a functionwhen the configuration uses SecretRef values (environment variable references like$OPENAI_API_KEYor vault-resolved secrets) for API keys. The config resolver returns a SecretRef object instead of a plain string, and calling.trim()on it throws.Two locations fixed:
src/commands/doctor-memory-search.ts—hasRemoteApiKeychecksrc/memory/embeddings-ollama.ts—resolveOllamaApiKeyfunctionBoth now check
typeof rawApiKey === "string"before calling.trim().Type of Change
Scope
Linked Issues
Closes #35444
User-Visible Changes
openclaw doctorno longer crashes when API keys are configured via environment variable references or vault secrets.Security Impact
Verification
oxfmtEvidence
Human Verification
openclaw.jsonwith$OPENAI_API_KEYenv reference for memory search API keyopenclaw doctor— should complete without TypeErrorCompatibility
Fully backward compatible. String API keys behave identically.
Failure Recovery
Revert this single commit to restore previous behavior.
Risks and Mitigations