Skip to content

Conversation

tpfz
Copy link
Collaborator

@tpfz tpfz commented Oct 10, 2025

What type of PR is this?

Check the PR title.

  • This PR title match the format: [<type>][<scope>]: <description>. For example: [fix][backend] flaky fix
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Add documentation if the current PR requires user awareness at the usage level.
  • This PR is written in English. PRs not in English will not be reviewed.

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

(Optional) Which issue(s) this PR fixes:

tpfz and others added 2 commits October 10, 2025 19:16
(LogID: 202510101913360100911101348473F04)

Co-Authored-By: Coda <[email protected]>
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 81.49920% with 116 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ules/evaluation/infra/runtime/http_faas_runtime.go 68.20% 66 Missing and 3 partials ⚠️
...ackend/modules/evaluation/infra/runtime/factory.go 85.71% 10 Missing and 4 partials ⚠️
...les/evaluation/infra/runtime/javascript_runtime.go 88.09% 9 Missing and 1 partial ⚠️
...modules/evaluation/infra/runtime/python_runtime.go 88.63% 9 Missing and 1 partial ⚠️
...ackend/modules/evaluation/infra/runtime/manager.go 91.01% 6 Missing and 2 partials ⚠️
backend/modules/evaluation/pkg/conf/evaluator.go 90.00% 5 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #220      +/-   ##
==========================================
+ Coverage   64.08%   64.30%   +0.22%     
==========================================
  Files         477      481       +4     
  Lines       51830    52371     +541     
==========================================
+ Hits        33214    33677     +463     
- Misses      16286    16354      +68     
- Partials     2330     2340      +10     
Flag Coverage Δ
unittests 64.30% <81.49%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nd/api/handler/coze/loop/apis/evaluator_service.go 4.34% <100.00%> (+4.34%) ⬆️
backend/modules/evaluation/pkg/conf/evaluator.go 76.85% <90.00%> (+28.85%) ⬆️
...ackend/modules/evaluation/infra/runtime/manager.go 91.01% <91.01%> (ø)
...les/evaluation/infra/runtime/javascript_runtime.go 88.09% <88.09%> (ø)
...modules/evaluation/infra/runtime/python_runtime.go 88.63% <88.63%> (ø)
...ackend/modules/evaluation/infra/runtime/factory.go 85.71% <85.71%> (ø)
...ules/evaluation/infra/runtime/http_faas_runtime.go 68.20% <68.20%> (ø)

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 803e5b2...7c18ba2. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

wec4dre96-w and others added 20 commits October 10, 2025 20:14
(LogID: 202510111803140100911101340639242)

Co-Authored-By: Coda <[email protected]>
…rectory

- Enhanced runtime package test coverage from 41.3% to 86.1%
- Added comprehensive tests for RuntimeFactory, RuntimeManager, HTTPFaaSRuntimeAdapter
- Extended PythonRuntime and JavaScriptRuntime testing with return_val functions
- Added concurrent access testing and error handling verification
- Implemented mock-based testing patterns following existing code style
- 移除测试文件中的多余空行
- 修复代码缩进不一致问题
- 使用go fmt格式化代码

这些修改仅涉及格式问题,未更改任何业务逻辑。
- 格式化运行时相关文件
- 修复代码缩进和空白字符问题
- 保持业务逻辑不变
- Fixed unchecked error returns in http_faas_runtime.go
- Added safe env var helper functions in runtime_test.go
- Removed unnecessary type conversions in evaluator.go
- All packages now pass golangci-lint checks
- Added missing Apache-2.0 license headers to 53 frontend TypeScript/TSX files
- Fixed 48 files automatically using license-eye tool
- Manually added headers to 5 .less files that weren't auto-fixable
- All files now pass license header validation
This reverts commit 2cee2c1.
- 统一docker和k8s版本的响应格式
- 实现Pyodide预加载机制,使用vendor离线依赖
- 优化进程池管理,支持预创建进程
- 改进代码执行逻辑,使用临时文件避免转义问题
- 添加完整的错误处理和日志记录
- 支持return_val函数和多种返回值格式提取
- 删除ModelConfig配置
@tpfz tpfz force-pushed the feat/open-code-eval branch from 777a25a to 4879e6e Compare October 15, 2025 06:52
# 后台健康检查循环
(
while true; do
if sh /coze-loop/bootstrap/js-faas/healthcheck.sh; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

/coze-loop/bootstrap/js-faas/healthcheck.sh 这个路径规范和其他组件的不一样,修改为保持一致吧;目录名在 docker-compose.yml 中定义的

)&

# 启动JavaScript FaaS服务器
exec deno run --allow-net=0.0.0.0:8000 --allow-env --allow-read=/coze-loop/bootstrap/js-faas,/tmp --allow-write=/tmp --allow-run /coze-loop/bootstrap/js-faas/js_faas_server.ts No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

一样的目录名问题

Copy link
Collaborator

Choose a reason for hiding this comment

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

app 的启动时间会明显变长吗,为什么要调整这个检测次数

EXPOSE 8000

# 默认命令 - 使用 entrypoint 脚本
CMD ["/app/entrypoint.sh"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

CMD 感觉没有必要加?

CMD deno eval "try { const resp = await fetch('http://localhost:8000/health'); if (resp.ok) { Deno.exit(0); } else { Deno.exit(1); } } catch (e) { Deno.exit(1); }"

# 暴露端口
EXPOSE 8000
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里暴露的端口没有必要?

Copy link
Collaborator

Choose a reason for hiding this comment

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

在 docker-compose.yaml 中的 comment 对这个问题吧

working_dir: /app
entrypoint: [ "sh", "/coze-loop/bootstrap/python-faas/entrypoint.sh" ]
deploy:
resources:
Copy link
Collaborator

Choose a reason for hiding this comment

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

342-348 配置不对

- SETGID
healthcheck:
test: [ "CMD", "sh", "/coze-loop/bootstrap/python-faas/healthcheck.sh" ]
interval: 60s
Copy link
Collaborator

Choose a reason for hiding this comment

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

感觉 interval、timeout、start_period 设置时间太长了吧

restart: always
networks:
- coze-loop-network
ports:
Copy link
Collaborator

Choose a reason for hiding this comment

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

一样的端口问题

- "${COZE_LOOP_JS_FAAS_PORT:-8891}:8000"
volumes:
- js_faas_workspace:/tmp/faas-workspace
- ./bootstrap/js-faas:/coze-loop/bootstrap/js-faas
Copy link
Collaborator

Choose a reason for hiding this comment

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

一样的路径命名问题

cpus: "${JS_FAAS_CPU_RESERVE:-0.25}"
healthcheck:
test: [ "CMD", "sh", "/coze-loop/bootstrap/js-faas/healthcheck.sh" ]
interval: 60s
Copy link
Collaborator

Choose a reason for hiding this comment

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

一样的健康检查配置考虑

Copy link
Collaborator

@CozeLoop CozeLoop left a comment

Choose a reason for hiding this comment

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

Summary:

  • Must-Fix: JS return_val is not captured by the current JS FaaS wrapper because it logs a raw string. Please emit a single JSON line (e.g., console.log(JSON.stringify({ret_val}))) so the server can parse it, or add an explicit marker protocol.
  • Should-Fix: Provide fail-open defaults for COZE_LOOP_JS_FAAS_URL and COZE_LOOP_PYTHON_FAAS_URL to improve robustness across dev/test environments.
  • Suggestion: Use normalizeLanguage(language) in the HTTP adapter, and include TypeScript aliases (ts/typescript) in config key normalization.

These changes will restore functional correctness for JS evaluators, reduce configuration friction, and make the runtime adapter more resilient.

Comment on lines +136 to +149
// return_val函数实现
function return_val(value) {
/**
* 修复后的return_val函数实现 - 只输出ret_val内容
* @param {string} value - 要返回的值,通常是JSON字符串
*/
// 处理输入值
const ret_val = (value === null || value === undefined) ? "" : String(value);
// 直接输出ret_val内容,供JavaScript FaaS服务器捕获
console.log(ret_val);
}
`
Copy link
Collaborator

Choose a reason for hiding this comment

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

[🚫Must-Fix] JavaScript return_val not captured by FaaS wrapper

Problem: In the JS branch of GetReturnValFunction, the implementation logs a raw string with console.log(ret_val);. The JS FaaS server (js_faas_server.ts) extracts ret_val by parsing the last JSON line printed by user code. A plain string will not be recognized, causing ret_val to be empty in responses.

Why it matters: This breaks functional correctness for JS evaluators—downstream components expecting ret_val will receive empty values. It also creates inconsistency with the Python branch which emits a structured output with markers.

Fix: Emit a compact JSON object on a single line so the server reliably parses it. Example:

function return_val(value) {
  const ret_val = (value === null || value === undefined) ? "" : String(value);
  // Emit a single JSON line for the FaaS wrapper to parse
  console.log(JSON.stringify({ ret_val }));
}

Alternatively, align with the Python approach and add explicit start/end markers if the server supports them.

Comment on lines +36 to +39
pythonFaaSURL := os.Getenv("COZE_LOOP_PYTHON_FAAS_URL")
if pythonFaaSURL == "" {
return nil, fmt.Errorf("必须配置Python FaaS服务URL,请设置COZE_LOOP_PYTHON_FAAS_URL环境变量")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[🚨Should-Fix] Fail-open to default Python FaaS URL when env var is missing

Problem: NewPythonRuntime returns an error if COZE_LOOP_PYTHON_FAAS_URL is not set. This forces environment configuration in all contexts and can block evaluation in dev/test clusters that already expose the default service endpoint.

Fix: Provide a default URL fallback consistent with the adapter’s default. Example:

pythonFaaSURL := os.Getenv("COZE_LOOP_PYTHON_FAAS_URL")
if pythonFaaSURL == "" {
    pythonFaaSURL = "http://coze-loop-python-faas:8000"
    logger.WithField("python_faas_url", pythonFaaSURL).Warn("COZE_LOOP_PYTHON_FAAS_URL not set; using default")
}

Benefit: Improves robustness and reduces configuration friction across environments.

Comment on lines +127 to +133
normalizedKey := langKey
switch strings.ToLower(langKey) {
case "python":
normalizedKey = string(evaluatordto.LanguageTypePython)
case "js", "javascript":
normalizedKey = string(evaluatordto.LanguageTypeJS)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[💡Suggestion] Normalize language keys to include TypeScript aliases

Observation: When standardizing the second-level language keys, JS normalization only covers "js" and "javascript". Elsewhere in this PR (e.g., HTTP adapter) TypeScript aliases are considered.

Improvement: Include "ts" and "typescript" for consistency and to avoid configuration surprises:

switch strings.ToLower(langKey) {
case "python":
    normalizedKey = string(evaluatordto.LanguageTypePython)
case "js", "javascript", "ts", "typescript":
    normalizedKey = string(evaluatordto.LanguageTypeJS)
}

This helps users who author templates with TypeScript labels.

Copy link
Collaborator

@CozeLoop CozeLoop left a comment

Choose a reason for hiding this comment

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

Aime CR summary: Backend runtime integration (factory/manager + HTTP FaaS adapter) is correct and concurrency-safe. ValidateEvaluator handler correctly restores service invocation. Config decoding and language normalization look good. No Must-Fix or Should-Fix issues found on backend Go changes. A few non-blocking suggestions: centralize default FaaS BaseURL config, remove unused basicSyntaxValidation or wire it into ValidateCode, and consider unifying logs to English for consistency. Full report is available in Feishu: https://bytedance.larkoffice.com/docx/RbfJdgpZsoqiBhxJ6epcqYWXnQf

name: {{ include "secret.name" . }}
key: rmq-namesrv-password
# faas
- name: COZE_LOOP_PYTHON_FAAS_URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

和 docker env 一样的问题,参考其他的 env 写法吧

port: 8888
targetPort: 8888

image:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里测试的提交恢复下

custom:
image:
registry:
registry: ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里应该没必要改吧

# 后台健康检查循环
(
while true; do
if sh /coze-loop/bootstrap/healthcheck.sh; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

/coze-loop/bootstrap 和 docker 部署一样路径命名的考虑

metadata:
name: {{ include "js-faas.fullname" . }}
labels:
{{- include "js-faas.labels" . | nindent 4 }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

不要使用换行+nindent 了吧,直接和 4 行一致不换行

name: coze-loop-python-faas
description: Python FaaS service for Coze Loop
type: application
version: 1.2.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

同样的版本号为 1.0.0

# 后台健康检查循环
(
while true; do
if sh /coze-loop/bootstrap/healthcheck.sh; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

仍然 /coze-loop/bootstrap 路径命名

Copy link
Collaborator

Choose a reason for hiding this comment

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

问题基本和 js-faas 目录下文件一致,参考修改下吧

port: 8000
targetPort: 8000

image:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里的 image 托管后需要修改

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件测试完后也不需要改

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.

4 participants