Skip to content

fix: list 结果过大导致 CLI 崩溃 & --endpoint 命令行参数不生效 - #168

Merged
rsonghuster merged 3 commits into
masterfrom
fix/list-large-output-and-cli-endpoint
Aug 23, 2026
Merged

fix: list 结果过大导致 CLI 崩溃 & --endpoint 命令行参数不生效#168
rsonghuster merged 3 commits into
masterfrom
fix/list-large-output-and-cli-endpoint

Conversation

@rsonghuster

@rsonghuster rsonghuster commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

问题

在一个函数数量很多的地域执行 s cli fc3 list --prefix <prefix> --region <region> --endpoint <custom endpoint>,命令报错退出:

Error Message:
Maximum call stack size exceeded

排查出两个独立的 bug。

1. list 结果过大时 CLI 崩溃

~/.s/logs/*/s_cli.log 的调用栈直指内核渲染路径:Et.outputSk.renderLxArray.forEach。内核用 prettyjson 渲染组件返回值,prettyjson 把整个返回值拍平成一个字符串数组,再用 push.apply(lines, subLines) 回灌,参数个数超过 V8 上限(本机 Node 22 实测 12w 个参数可以、13w 抛错)就抛 RangeError

复现时结果集是几千个函数(-o json 约 8MB),prettyjson 实际渲染约 18 万行,必然崩溃 —— 而且是在完整分页一分多钟之后才崩,等于白等。

2. --endpoint 命令行参数被静默忽略

日志里 list opts 能看到 endpoint,紧接着却是 get custom endpoint: undefinedendpoint=fcv3.<region>.aliyuncs.com。原因是所有子命令都从 inputs.props.endpoint 取值,而它只由 s.yaml 填充;s cli 模式没有 yaml,参数就丢了。所以请求实际打到了默认公网地址而不是指定的 endpoint,之前只有 FC_CLIENT_CUSTOM_ENDPOINT 或 s.yaml 有效。

改动

list 渲染兜底src/subCommands/list/index.tssrc/utils/index.ts

  • 两条非 --table 返回路径改走 output():预估渲染行数超过 MAX_DEFAULT_RENDER_LINES(5w) 时,直接 logger.write(JSON.stringify(...)) 打印,并提示可用 --limit/--next-token--table-o json/yaml
  • 只在内核默认渲染路径生效:指定 -o/--output-format/--output/--output-file,以及 app center 等程序化调用(isAppCenter())时原样返回,不破坏返回值契约。
  • estimateRenderLines 用 prettyjson 1.2.5 实测校准:对每个非标量数组元素补一行(prettyjson 的分隔行)后,对 list 返回值低估约 7%,最坏结构形状低估 25%,即 5w 阈值对应实际最多约 6.2w 行,距 12w 上限有 2x 余量。

--endpoint 生效src/base.tssrc/commands-help/list.ts

  • handlePreRun 从 argv 解析 --endpoint 写入 props.endpoint,命令行优先于 yaml;list 帮助文本补上该选项。
  • 冻结的 model 作用域不读 props.endpoint,行为未变;deploy/impl/function.tsplan/index.ts 本就会 unset 掉它。

Test plan

  • 相关三个 suite:list_test / base_test / utils_functions_test —— 81 tests 全通过(新增 11 条)
    • list:默认格式下超限打印 raw JSON + warn、-o json 时原样返回、小结果原样返回、app center 原样返回、单页 --limit 路径同样受保护
    • utils:isDefaultRenderOutput 各种 flag 形态(含 --output-format=json--prefix output 不误判)、estimateRenderLines 标量/嵌套/数组分隔行/阈值上下
    • base:endpoint 取自命令行、命令行覆盖 yaml、无参数时保留 yaml 值
  • 全量 npm test__tests__/ut):70/75 suites、1046 passed、2 skipped
  • npm run lint:0 errors(唯一 warning 在未改动的 src/resources/fc/impl/utils.ts:48,既有)
  • npx tsc --noEmit:仓库 src/ 0 错误
  • prettier --check 改动文件全部通过
  • npm run build(ncc):本地环境装不全依赖,需 CI 验证
  • 真机复跑原命令,确认 --endpoint 生效且大结果不再崩溃

说明:本地是用公网可得依赖 + 少量私有包桩件跑测试的,resources/slscommands/modelcommands/artModelServicecore/indexlocal/impl/baseLocalStart 5 个 suite 因桩件失败 —— 已用 pristine master 在同一套环境下对照,失败集合完全一致,非本次回归。

Summary by CodeRabbit

  • New Features

    • Added support for specifying a Function Compute endpoint with --endpoint.
    • Large default-rendered listings now fall back to JSON output to prevent rendering failures.
    • Added handling for nested, array, paginated, and full-list results.
  • Bug Fixes

    • Command-line endpoints now correctly override configured endpoints.
  • Documentation

    • Updated list command help with the new endpoint option.

`s cli fc3 list` crashed with "Maximum call stack size exceeded" whenever the
listing was large: the CLI core renders a component's return value with
prettyjson, which flattens the whole payload into one array of lines and
re-injects it via `push.apply(lines, subLines)`. Past the V8 argument limit
(~120k, measured on Node 22) that throws a RangeError. A real listing of 3793
functions renders to ~182k lines, so it always crashed after ~70s of paging.

The list result now falls back to printing raw JSON (with a hint about
--limit/--next-token, --table and -o json/yaml) when it would exceed the
renderer's limit. The guard only applies to the CLI's default render path:
--output-format/--output/--output-file and programmatic app center callers keep
the return value untouched.

estimateRenderLines is validated against prettyjson 1.2.5: it underestimates
the real list payload by ~7% and by at most 25% on the worst shape, so the 50k
threshold maps to ~62k actual lines, well below the limit.
Every subcommand reads the endpoint from `inputs.props.endpoint`, which is only
populated from s.yaml. In `s cli` mode there is no yaml, so `--endpoint` was
parsed into argv and then silently ignored: `s cli fc3 list --endpoint http://...`
still went to the public `fcv3.<region>.aliyuncs.com` instead of the requested
cluster, and only FC_CLIENT_CUSTOM_ENDPOINT worked.

handlePreRun now reads --endpoint from argv and writes it into props.endpoint,
so the command line takes precedence over yaml. The option is documented in the
`list` help text.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 71875ad5-2b36-4c89-ace6-34ad316da042

📥 Commits

Reviewing files that changed from the base of the PR and between a67635b and b337678.

📒 Files selected for processing (7)
  • __tests__/ut/commands/list_test.ts
  • __tests__/ut/core/base_test.ts
  • __tests__/ut/utils/utils_functions_test.ts
  • src/base.ts
  • src/commands-help/list.ts
  • src/subCommands/list/index.ts
  • src/utils/index.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The list command now avoids oversized default-renderer output by writing raw JSON. New utilities detect output modes and estimate rendered lines. The base command now propagates a command-line endpoint, and list help documents the option.

Changes

List output handling

Layer / File(s) Summary
Render-size utilities and tests
src/utils/index.ts, __tests__/ut/utils/utils_functions_test.ts
The utilities detect default rendering and estimate scalar, array, and object output sizes against a 50,000-line threshold.
List result output routing
src/subCommands/list/index.ts, __tests__/ut/commands/list_test.ts
Paginated and full list results use shared output handling. Oversized default-rendered results produce a warning and formatted JSON. Other output modes return results unchanged.

Command-line endpoint handling

Layer / File(s) Summary
Endpoint option and pre-run propagation
src/commands-help/list.ts, src/base.ts, __tests__/ut/core/base_test.ts
List help documents --endpoint. Base.handlePreRun applies a non-empty command-line endpoint and overrides YAML configuration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to b3376

The change adds CLI endpoint override behavior for list operations with YAML fallback. It is generally mergeable, but the parser should be confirmed to forward string values and reject a missing endpoint value; otherwise an invalid invocation could cause incorrect command behavior.

Sequence Diagram(s)

sequenceDiagram
  participant ListCommand
  participant RenderUtils
  participant Logger
  ListCommand->>RenderUtils: Detect output mode
  ListCommand->>RenderUtils: Estimate rendered lines
  alt Oversized default output
    ListCommand->>Logger: Write warning and formatted JSON
  else Small or explicit-format output
    ListCommand-->>ListCommand: Return result
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes both main changes: preventing CLI crashes from oversized list output and fixing the --endpoint command-line argument.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/list-large-output-and-cli-endpoint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

`index.ts#list` returns it from an exported class, and tsconfig has
`declaration: true`, so tsc needs the type to be nameable:
TS4053 "Return type of public method from exported class has or is using
name 'IListResult' ... but cannot be named".
@rsonghuster rsonghuster changed the title Fix/list large output and cli endpoint fix: list 结果过大导致 CLI 崩溃 & --endpoint 命令行参数不生效 Aug 23, 2026
@rsonghuster
rsonghuster merged commit d9fa9a9 into master Aug 23, 2026
6 checks passed
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.

1 participant