Repository navigation
fix: 修复skill_exec未注入Skill专属环境变量的问题 (#359) #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,25 @@ | |
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _apply_skill_run_env(repository: BaseSkillRepository, skill_name: str, env: dict[str, str]) -> None: | ||
| """Inject skill-specific env without overriding explicit or non-empty host values.""" | ||
| try: | ||
| skill_env: dict[str, str] = repository.skill_run_env(skill_name) | ||
| for k, v in skill_env.items(): | ||
| k = k.strip() | ||
| if not k or not v.strip(): | ||
| continue | ||
| if k in env: # don't override explicit tool-call env | ||
| continue | ||
| if os.environ.get(k, "").strip(): # don't override host env | ||
| continue | ||
| if k.upper() in _BLOCKED_SKILL_ENV_KEYS: | ||
| continue | ||
| env[k] = v | ||
|
Comment on lines
+123
to
+133
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 注入循环对 触发条件: 模型/上游在 实际影响: 子进程同时看到 修正方向: 在 |
||
| except Exception: # pylint: disable=broad-except | ||
| pass | ||
|
Comment on lines
+119
to
+135
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题: 触发条件: skill 配置 实际影响: 子进程收到的 修正方向: 在 |
||
|
|
||
|
|
||
| def _is_text_mime(mime: str) -> bool: | ||
| """Return True when *mime* is a text-like content type.""" | ||
| if not mime: | ||
|
|
@@ -770,21 +789,7 @@ async def _run_program( | |
|
|
||
| # Inject skill-specific env from repository (e.g. api_key → primary_env) | ||
| repository = self._get_repository(ctx) | ||
| try: | ||
| skill_env: dict[str, str] = repository.skill_run_env(input_data.skill) | ||
| for k, v in skill_env.items(): | ||
| k = k.strip() | ||
| if not k or not v.strip(): | ||
| continue | ||
| if k in env: # don't override explicit tool-call env | ||
| continue | ||
| if os.environ.get(k, "").strip(): # don't override host env | ||
| continue | ||
| if k.upper() in _BLOCKED_SKILL_ENV_KEYS: | ||
| continue | ||
| env[k] = v | ||
| except Exception: # pylint: disable=broad-except | ||
| pass | ||
| _apply_skill_run_env(repository, input_data.skill, env) | ||
|
|
||
| # Stage editor helper if requested | ||
| await self._prepare_editor_env(ctx, ws, workspace_runtime, env, input_data.editor_text) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题: 注入循环对值调用
v.strip()(第 125 行)时未做类型防护;BaseSkillRepository.skill_run_env是抽象接口(_repository.py:125),自定义实现可返回含非字符串值(None/数字/任意对象)的 dict,此时抛AttributeError被外层except Exception: pass整体吞掉,同一技能其余 env 键全部静默丢失且无任何日志。触发条件: 任何自定义
BaseSkillRepository.skill_run_env返回含非 str 值的 dict(树内 loader_build_skill_run_env保证 str,但该钩子是公开扩展点且无类型强制);skill_exec 路径此前从不调用该钩子,属本次变更新引入的可达面,skill_run 旧路径同样受影响但本次将其复制到了第二个工具。实际影响: 注入在首个非法值处中断,技能所需凭据(如 api_key)部分或全部缺失,命令因缺环境变量失败而错误信息与真实原因无关,难以排查;已写入的前几个键造成不确定的部分注入状态。
修正方向: 对值(与键)做
str(v).strip()强制转换(与 loader_build_skill_run_env的str(key)/str(val)做法一致),或对非字符串项continue跳过,避免单键毁掉整批注入。