Skip to content

fix(actions): recover agent text from execution file (closes #177)#178

Merged
YiWang24 merged 1 commit into
mainfrom
claude/issues-prs-review-u3g9wl
Jun 10, 2026
Merged

fix(actions): recover agent text from execution file (closes #177)#178
YiWang24 merged 1 commit into
mainfrom
claude/issues-prs-review-u3g9wl

Conversation

@YiWang24

@YiWang24 YiWang24 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

Issue #177 ("Flag audit — 2026-06-01") was filed by automation with a body that
was literally a file path:

/home/runner/_work/_temp/claude-execution-output.json

Root cause

claude-code-action@v1.x no longer returns Claude's text — it only exposes
execution_file, a path to a JSONL transcript. claude-harness re-exports
that path under the deprecated result alias. Five pre-v1 callers still read
result as if it were text and used it directly:

Action Misuse of result
_common/flag-audit issue body (→ #177)
prd/create-release release notes body
stg/agent-test staged findings file
pr/agent-test-gen staged generated output
ci/eval-smoke re-exported result output

Fix

  • New shared action _common/extract-text + extract-text.sh that reads the
    execution file and recovers the agent's final text, with layered strategies:

    1. result record .result string (claude-code-action success)
    2. last assistant message's concatenated text blocks
    3. single-object .result
    4. plain-text passthrough (very old single-string output)

    Missing / skipped / unparseable → empty string, exit 0 (callers degrade).

  • Wired the helper into all five callers; each now feeds execution-file through
    extract-text instead of using the raw path.

  • Kept the result alias on claude-harness for any unmigrated consumers and
    pointed its docs at the new helper.

  • Added tests/actions/extract-text.bats (10 cases, all passing).

Verification

  • extract-text.bats — 10/10 pass
  • workflow-integrity.bats + harness-shape.bats + workflow-audit.bats — 46/46 pass
    (incl. "composite preserves deprecated result output alias")
  • All touched YAML parses; bash -n clean on the new script

Closes #177

https://claude.ai/code/session_01AaRMRGhaE2wWdis47Y4UNt


Generated by Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Added text extraction capability for AI-generated transcript outputs, enabling cleaner access to final text results.
  • Documentation

    • Updated output documentation to guide users on accessing extracted text from transcript files.
  • Tests

    • Added test coverage for text extraction functionality with various transcript formats and edge cases.

… its path

claude-code-action@v1.x exposes only execution_file (a path to a JSONL
transcript); claude-harness re-exports it as the deprecated `result` alias.
Five pre-v1 callers (flag-audit, agent-test, agent-test-gen, create-release,
eval-smoke) consumed `result` as if it were Claude's text output, so they
emitted the raw path. The visible symptom was flag-audit filing issues whose
body was literally "/home/runner/_work/_temp/claude-execution-output.json"
(#177).

Add a shared _common/extract-text action that reads the execution file and
recovers the agent's final text (result record -> last assistant text blocks
-> single-object .result -> plain-text passthrough), and wire it into all
five callers. Keep the `result` alias for any unmigrated consumers.

Closes #177
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d3b2cafa-9a3e-457b-9f8f-dab1ab56491f

📥 Commits

Reviewing files that changed from the base of the PR and between 5003f0d and 67f4a75.

📒 Files selected for processing (9)
  • actions/_common/claude-harness/action.yml
  • actions/_common/extract-text/action.yml
  • actions/_common/extract-text/extract-text.sh
  • actions/_common/flag-audit/action.yml
  • actions/ci/eval-smoke/action.yml
  • actions/pr/agent-test-gen/action.yml
  • actions/prd/create-release/action.yml
  • actions/stg/agent-test/action.yml
  • tests/actions/extract-text.bats

📝 Walkthrough

Walkthrough

This PR introduces a new extract-text action that allows callers to recover text output from claude-harness v1 execution transcripts (which output only file paths rather than text directly), applies it across five workflow actions, and updates documentation to guide users through the migration.

Changes

Extract-text capability and migration

Layer / File(s) Summary
Extract-text script and test suite
actions/_common/extract-text/extract-text.sh, tests/actions/extract-text.bats
Bash script implements four fallback strategies to extract text from execution transcripts: prioritize JSONL records with .type=="result", fall back to the last assistant message's concatenated text, then single JSON object .result, then plain text passthrough. Comprehensive Bats suite validates all strategies and edge cases including skipped execution, missing files, text concatenation, and precedence rules.
Extract-text composite action wrapper
actions/_common/extract-text/action.yml
New GitHub composite action wraps the extraction script, exposing execution-file and skipped inputs, invoking the script via environment variables, and outputting recovered text.
Documentation update and caller migration
actions/_common/claude-harness/action.yml, actions/_common/flag-audit/action.yml, actions/ci/eval-smoke/action.yml, actions/pr/agent-test-gen/action.yml, actions/prd/create-release/action.yml, actions/stg/agent-test/action.yml
Claude-harness result output docs clarify that v1 callers must use extract-text on execution-file to recover text. Five workflow actions (flag-audit, eval-smoke, agent-test-gen, create-release, agent-test) each add an extract-text step and rewire their output/body sources from the deprecated result path to the recovered text.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • YiAgent/OpenCI#1: Introduces claude-harness v1 API change that replaces the old result output with execution-file path, which motivates this PR's extract-text action and caller migration.
  • YiAgent/OpenCI#2: Also updates actions/_common/claude-harness/action.yml around the deprecated result output alias, directly related at the output-API wiring level.
  • YiAgent/OpenCI#3: Adds .openci/ vendoring that enables local action paths (./.openci/actions/_common/extract-text) to resolve at runtime across the caller workflows.

Suggested labels

area:docs

Poem

🐰 A script that extracts with grace,
Four fallback paths to find its place,
From JSONL dreams to plaintext true,
The harness v1 now shines right through!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issues-prs-review-u3g9wl

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 and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@YiWang24

Copy link
Copy Markdown
Collaborator Author

代码审查

变更意图:Bug 修复
涉及模块_common/extract-text(新增)、_common/claude-harness_common/flag-auditci/eval-smokepr/agent-test-genprd/create-releasestg/agent-test
影响范围:核心链路 — 所有依赖 claude-harness 文本输出的 action 均受影响
初始风险等级:Medium → 审查后降为 Low

意图说明:修复 claude-code-action@v1.x 升级后不再返回文本而是返回 JSONL 文件路径的问题(#177)。新增 extract-text 共享 action 从 execution file 中恢复 agent 最终文本,统一迁移 5 个误用 result 的调用方。


风险等级: 低 | 审查置信度: 高 | 结论: ✅ 可直接合入


1. 无影响变更

# 位置 变更内容 风险评估
1 claude-harness/action.yml 更新 result output 的 deprecated 说明文档 纯注释变更,无逻辑影响
2 tests/actions/extract-text.bats 新增 10 个 bats 测试用例 仅测试代码

2. 建议关注(非阻塞)

# 位置 说明
1 extract-text.sh Strategy C(L57) head -n1 在单 JSON 对象的 .result 为多行字符串时只取首行。但这是第 3 层 fallback(A/B 均失败才触发),且 legacy 单 JSON 格式的 .result 通常为单行,实际风险极低。如需严谨可改为 jq -r '.result // empty | strings' 去掉 head -n1
2 extract-text.sh jq -sr(L46, L54) slurp 模式将整个 transcript 加载到内存。正常 JSONL transcript 体积可控(通常 <1MB),GitHub Actions runner 内存充足。仅当异常巨大的 transcript 文件时可能 OOM,实际概率极低。

3. 需要修复的问题

无。


设计亮点

  1. 4 层 fallback 策略(result record → assistant text → 单对象 .result → 纯文本)覆盖了 claude-code-action 各版本的输出格式,降级路径清晰:缺失/跳过/不可解析 → 空 string + exit 0,让调用方自行决定如何降级。
  2. emit() heredoc 方式写入 GITHUB_OUTPUT 正确处理了多行文本,避免了 echo 截断问题。
  3. 调用方迁移一致性:5 个 caller 统一用 extract-text 中间层替代直接读取 result,命名各有语义(report / gen / notes / findings),不混淆。
  4. 向后兼容claude-harness 保留 deprecated result alias 并更新文档指向新 helper,未迁移的消费者仍可工作。
  5. 测试覆盖全面:10 个 bats 用例覆盖了 skip、missing file、empty input、4 种策略、优先级验证、多 block 拼接等场景。

完成度分析

  • 变更类型:Bug 修复(Flag audit — 2026-06-01 #177 flag-audit issue body 为文件路径)
  • 完成度:✅ 完整 — 根因分析到位,统一修复了所有 5 个受影响 caller,新增共享 action + 测试,向后兼容处理得当

影响分析 + 建议验证 + 最终结论

  • 影响分析:变更修改了所有 AI agent 调用链的文本提取路径。eval-smokeoutputs.result 语义从"文件路径"回归为"实际文本"(与 output description 一致),下游 reusable-ci.yml 只读取 needs.eval-smoke.result(job 状态)不读取 output 值,无兼容性问题。
  • 建议验证:合入后可观察下一次 flag-audit / eval-smoke / create-release 触发时 output 是否为实际文本而非路径。
  • 最终结论:✅ 设计严谨、迁移一致、测试充分,可直接合入。

@YiWang24

Copy link
Copy Markdown
Collaborator Author

代码审查报告

风险等级: | 审查置信度: | 结论: 修复后合入

摘要: PR #178 修复了 claude-code-action@v1.x 升级后 result 输出变成文件路径而非文本的问题。新增 extract-text helper action,并更新了 5 个调用方。核心逻辑正确,但发现 2 个需要修复的问题。

变更意图

  • 变更意图:Bug 修复
  • 涉及模块_common/extract-text(新增)、_common/claude-harness_common/flag-auditci/eval-smokepr/agent-test-genprd/create-releasestg/agent-test
  • 影响范围:核心链路(AI agent 输出提取)
  • 初始风险等级:Medium
  • 意图说明:修复 Flag audit — 2026-06-01 #177 issue,从 claude-harness 的 execution file 中正确提取 agent 文本输出,而非直接传递文件路径

1. 无影响变更

# 位置 变更内容 风险评估
1 claude-harness/action.yml 更新 result 输出的描述,指向新 helper 低风险,仅文档更新

2. 建议关注(非阻塞)

# 位置 说明
1 extract-text.sh 策略 D 纯文本 passthrough 逻辑依赖于 jq -e . 失败来判断,但如果文件是无效 JSON 但不是纯文本(如空文件、二进制),可能产生意外行为
2 extract-text.sh 第 62 行 head -n1 可能截断多行 .result 内容,虽然策略 C 针对单 JSON 对象场景,但仍建议改用 printf '%s' 保持完整

3. 需要修复的问题

# 严重度 置信度 位置 问题描述 修复建议
1 确定 extract-text.sh:32-37 空文件处理不完整:当文件存在但为空时,jq 会失败,text 保持空,然后策略 D 会尝试 cat 空文件,最终 emit ""。逻辑正确但效率低,建议在文件检查后增加非空检查 在 `if [ -z "$file" ]
2 确定 extract-text.sh:68-70 策略 D 的 cat 可能输出大量内容到 text 变量:如果文件是大文件(如超长 transcript),直接 cat 到变量可能导致内存问题或截断 增加文件大小检查,如 `if [ $(stat -c%s "$file" 2>/dev/null
3 可能 extract-text.sh:45-50 jq 策略 A 的 -sr 参数-s (slurp) 将整个输入作为数组,但对 JSONL 每行是独立 JSON 对象的情况,`[.. objects]` 递归可能不够高效

完成度分析

  • 变更类型:Bug 修复
  • 完成度:基本完整(需修复上述问题)
  • 测试覆盖:新增 extract-text.bats 10 个测试用例,覆盖主要场景 ✓
  • 文档更新:YAML 注释清晰说明了问题背景和解决策略 ✓

影响分析

正面影响

  • 修复了 5 个 action 的错误行为(输出文件路径而非实际内容)
  • 统一了文本提取逻辑,减少代码重复
  • 向后兼容:支持 JSONL、单 JSON 对象、纯文本多种格式

潜在影响

  • extract-text 成为新的关键依赖路径,如果它失败会影响下游所有 5 个 action
  • 新增的 jq 复杂度增加了处理失败的可能性(已有多层 fallback)

建议验证

  1. 在测试环境运行 flag-audit action,确认 issue body 不再是文件路径
  2. 验证 create-release 的 changelog 内容正确
  3. 对大文件(>100KB JSONL)进行压力测试

最终结论

修复后合入 — 核心逻辑正确,测试覆盖充分,但建议增加空文件和大文件的边界检查。


Code Review 修复任务

审查结论: 修复后合入

需要修复的问题

  1. [中] extract-text.sh:32 — 文件存在但为空的场景处理不够高效(虽然后续 jq 会失败但会浪费一次尝试)

    • 影响链:空文件 → jq 失败 → 策略 B/C 尝试 → 策略 D cat 空文件 → emit 空文本
    • 修复建议:在行 32 添加 -s 检查:if [ -z "$file" ] || [ ! -f "$file" ] || [ ! -s "$file" ]; then
  2. [中] extract-text.sh:68-70 — 大文件直接 cat 到变量可能有风险

    • 影响链:大文件(如>10MB)→ cat 到变量 → 内存压力/截断风险
    • 修复建议:在策略 D 前增加文件大小检查,限制 1-10MB
  3. [低] extract-text.sh:62head -n1 可能截断多行结果

    • 修复建议:改用 printf '%s' 或移除 head -n1(因为策略 C 针对单 JSON 对象)

修复要求

  • 仅修复上述问题,不改动其他代码
  • 保持现有代码风格
  • 修复后确认不影响已有 10 个 bats 测试用例

@YiWang24

Copy link
Copy Markdown
Collaborator Author

代码审查报告

风险等级: 低风险 | 审查置信度: 高 | 结论: 建议进一步验证(Lint 和 Coverage 检查失败需确认)

摘要: PR 修复了 Issue #177 报告的问题:claude-code-action@v1.x 返回的是执行文件路径而非文本内容,导致 5 个调用方误将路径当作文本输出。新增 _common/extract-text 共享 action 从 JSONL 执行文件中正确提取 agent 文本。

变更意图

  • 变更类型: Bug 修复 + 重构优化
  • 涉及模块: actions/_common/ (claude-harness, extract-text 新增), actions/_common/flag-audit, actions/ci/eval-smoke, actions/pr/agent-test-gen, actions/prd/create-release, actions/stg/agent-test
  • 影响范围: 核心链路(所有使用 claude-harness 的 agent 调用方)
  • 初始风险等级: Medium(涉及多个核心 action 的输出处理)

1. 无影响变更

# 位置 变更内容 风险评估
1 claude-harness/action.yml 更新 result 输出描述,添加迁移说明 低风险 - 仅文档更新

2. 建议关注(非阻塞)

# 位置 说明
1 extract-text.action.yml 多行 >80 字符 yamllint 警告,不影响功能
2 多个 action.yml 文件中 too many spaces after colon yamllint 风格警告,现有代码普遍存在

3. 需要修复的问题

# 严重度 置信度 位置 问题描述 修复建议
1 确定 CI - Lint 检查 Lint 检查失败,可能影响合入 需查看具体失败原因,确认是否阻塞
2 确定 CI - Coverage 检查 Coverage 检查失败,可能表示测试覆盖率下降 需查看具体失败原因,确认是否由新增代码导致

影响链分析(针对 CI 失败)

Lint 失败 → 可能导致 PR 无法合并 → 需确认是否因 yamllint 警告触发还是其他语法错误
Coverage 失败 → 可能表示新增代码缺少测试覆盖 → 但 PR 已添加 10 个 extract-text.bats 测试用例

完成度分析

  • Bug 修复覆盖: ✅ 完整 - 5 个受影响的调用方已全部迁移使用 extract-text
  • 测试覆盖: ✅ 完整 - 新增 tests/actions/extract-text.bats (10/10 通过)
  • 向后兼容: ✅ 完整 - claude-harness 保留 result 输出别名
  • 验证: ✅ 完整 - bash -n 语法检查通过,yamllint 仅风格警告

正面发现

  1. 测试驱动开发: 新增 10 个 BATS 测试用例覆盖所有提取策略
  2. 分层降级策略: 4 层提取策略(result → assistant → single JSON → plain text)
  3. 向后兼容: 保留 deprecated result 别名,不影响未迁移调用方
  4. 边界处理: 空文件、跳过、解析失败均返回空字符串并退出 0
  5. 验证充分: workflow-integrity.bats + harness-shape.bats + workflow-audit.bats = 46/46 通过

建议验证

  1. 确认 Lint 和 Coverage 检查失败的具体原因(可能是配置问题或阈值问题)
  2. 验证生产环境中 JSONL 执行文件的实际格式是否与测试用例一致
  3. 确认所有调用方在新代码合入后能正确获取文本输出

最终结论

修复后合入 - 代码质量和设计优秀,测试充分,但需先解决 CI 失败问题(Lint + Coverage)。建议:

  1. 查看 Lint/Coverage 失败日志
  2. 如是配置/阈值问题,调整配置或添加忽略规则
  3. 重新运行 CI 确认通过后合入

@github-actions

Copy link
Copy Markdown
Contributor

OpenCI issue agent executed:

  • escalate: needs-human

Reasoning:
Agent output did not contain a parseable action plan.

@YiWang24 YiWang24 marked this pull request as ready for review June 10, 2026 19:08
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@YiWang24 YiWang24 merged commit 0d64934 into main Jun 10, 2026
46 of 50 checks passed

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@YiWang24 YiWang24 deleted the claude/issues-prs-review-u3g9wl branch June 10, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag audit — 2026-06-01

2 participants