Repository navigation
[feature][for merge][part0] Support terminal-bench-2 - #319
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the Harbor benchmark integration, adding HarborSummarizer for result aggregation, HarborTask for running evaluation jobs, and an example configuration file. While the implementation is comprehensive, several critical issues were identified in the review: HarborSummarizer contains bugs that will cause crashes, including the use of a non-existent mmengine.utils.TimeStub class, an unsupported csv format in tabulate, and malformed table row construction. Additionally, HarborTask has potential runtime issues, such as overwriting existing OPENAI_API_KEY environment variables, calling signal.signal in potentially non-main threads, and a risk of AttributeError when updating config.verifier.env if it is uninitialized.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| for dataset_abbr, metric in dataset_abbrs: | ||
| for model_abbr in self.model_abbrs: | ||
| if metric is None: | ||
| for k in parsed_results.get(model_abbr, {}).get(dataset_abbr, {}).keys(): | ||
| row = [dataset_abbr, 'a39421', k, dataset_eval_mode.get(dataset_abbr, 'gen')] | ||
| if has_total_count: | ||
| row.insert(4, raw_results[model_abbr][dataset_abbr].get('total_count', '-')) | ||
| row.append(parsed_results[model_abbr][dataset_abbr][k]) | ||
| table.append(row) | ||
| else: | ||
| if dataset_abbr in parsed_results[model_abbr] and metric in parsed_results[model_abbr][dataset_abbr]: | ||
| row = [dataset_abbr, 'a39421', metric, dataset_eval_mode.get(dataset_abbr, 'gen')] | ||
| if has_total_count: | ||
| row.insert(4, raw_results[model_abbr][dataset_abbr].get('total_count', '-')) | ||
| row.append(parsed_results[model_abbr][dataset_abbr][metric]) | ||
| table.append(row) | ||
|
|
||
| for sg in self.summary_groups: | ||
| for model_abbr in self.model_abbrs: | ||
| if sg['name'] in parsed_results[model_abbr]: | ||
| row = [sg['name'], sg.get('version', '-'), sg.get('metric', 'naive_average'), dataset_eval_mode.get(sg['name'], 'gen')] | ||
| if has_total_count: | ||
| row.insert(4, len(sg['subsets'])) | ||
| row.extend([parsed_results[m].get(sg['name'], {}).get(sg.get('metric', 'naive_average'), '-') for m in self.model_abbrs]) | ||
| table.append(row) |
There was a problem hiding this comment.
The current implementation of table row construction loops over self.model_abbrs and appends a single model's score to a new row, then appends that row to the table. However, the table header contains columns for all models. This results in malformed rows where the columns do not align with the header (e.g., a row for the second model will have its score displayed under the first model's column, and the row length will not match the header length). Additionally, the summary groups loop will add duplicate rows for each model that has results. We should construct a single row per metric/summary group and populate the scores for all models in that row.
for dataset_abbr, metric in dataset_abbrs:
if metric is None:
metrics = set()
for model_abbr in self.model_abbrs:
metrics.update(parsed_results.get(model_abbr, {}).get(dataset_abbr, {}).keys())
for k in sorted(metrics):
row = [dataset_abbr, 'a39421', k, dataset_eval_mode.get(dataset_abbr, 'gen')]
if has_total_count:
total_count = '-'
for model_abbr in self.model_abbrs:
if dataset_abbr in raw_results.get(model_abbr, {}) and 'total_count' in raw_results[model_abbr][dataset_abbr]:
total_count = raw_results[model_abbr][dataset_abbr]['total_count']
break
row.insert(4, total_count)
for model_abbr in self.model_abbrs:
row.append(parsed_results.get(model_abbr, {}).get(dataset_abbr, {}).get(k, '-'))
table.append(row)
else:
if any(dataset_abbr in parsed_results[model_abbr] and metric in parsed_results[model_abbr][dataset_abbr] for model_abbr in self.model_abbrs):
row = [dataset_abbr, 'a39421', metric, dataset_eval_mode.get(dataset_abbr, 'gen')]
if has_total_count:
total_count = '-'
for model_abbr in self.model_abbrs:
if dataset_abbr in raw_results.get(model_abbr, {}) and 'total_count' in raw_results[model_abbr][dataset_abbr]:
total_count = raw_results[model_abbr][dataset_abbr]['total_count']
break
row.insert(4, total_count)
for model_abbr in self.model_abbrs:
row.append(parsed_results.get(model_abbr, {}).get(dataset_abbr, {}).get(metric, '-'))
table.append(row)
for sg in self.summary_groups:
if any(sg['name'] in parsed_results[model_abbr] for model_abbr in self.model_abbrs):
row = [sg['name'], sg.get('version', '-'), sg.get('metric', 'naive_average'), dataset_eval_mode.get(sg['name'], 'gen')]
if has_total_count:
row.insert(4, len(sg['subsets']))
row.extend([parsed_results[m].get(sg['name'], {}).get(sg.get('metric', 'naive_average'), '-') for m in self.model_abbrs])
table.append(row)There was a problem hiding this comment.
[review] 当前表格行构建的实现方式是循环遍历 self.model_abbrs,并将单个模型的得分添加到新行,然后将该行添加到表格中。然而,表格标题包含所有模型的列。这会导致行格式错误,列与标题不对齐(例如,第二个模型的得分会显示在第一个模型的列下,并且行长度与标题长度不匹配)
| summary_dir = osp.join(self.work_dir, 'summary') | ||
| mmengine.mkdir_or_exist(summary_dir) | ||
|
|
||
| time_str = time_str or mmengine.utils.TimeStub.now().time_str |
There was a problem hiding this comment.
mmengine.utils does not contain a TimeStub class or attribute. Attempting to call mmengine.utils.TimeStub.now() will raise an AttributeError and crash the summarizer. Use the standard library datetime module instead.
| time_str = time_str or mmengine.utils.TimeStub.now().time_str | |
| from datetime import datetime | |
| time_str = time_str or datetime.now().strftime('%Y%m%d_%H%M%S') |
There was a problem hiding this comment.
[review]mmengine.utils 不包含 TimeStub 类或属性。尝试调用 mmengine.utils.TimeStub.now() 将引发 AttributeError 并导致汇总程序崩溃。请改用标准库的 datetime 模块。
| print(f'write csv to {summary_csv}') | ||
| with open(summary_csv, 'w', encoding='utf-8') as out: | ||
| out.write(tabulate.tabulate(table[1:], headers=table[0], tablefmt='csv')) |
There was a problem hiding this comment.
tabulate does not support csv as a table format. Attempting to use tablefmt='csv' will raise a ValueError: unknown table format: csv and crash the summarizer. Write the CSV file manually or use a standard CSV writer.
| print(f'write csv to {summary_csv}') | |
| with open(summary_csv, 'w', encoding='utf-8') as out: | |
| out.write(tabulate.tabulate(table[1:], headers=table[0], tablefmt='csv')) | |
| print(f'write csv to {summary_csv}') | |
| with open(summary_csv, 'w', encoding='utf-8') as out: | |
| out.write('\\n'.join([','.join(map(str, row)) for row in table]) + '\\n') |
There was a problem hiding this comment.
[review] tabulate 函数不支持 csv 作为表格格式。尝试使用 tablefmt='csv' 会引发 ValueError: unknown table format: csv 错误,并导致汇总程序崩溃。请手动写入 CSV 文件或使用标准 CSV 写入器。
| def _set_api_key(self): | ||
| api_key = self.model_cfg.get("api_key") | ||
| if api_key is None: | ||
| api_key = DEFAULT_FAKE_API_KEY | ||
| os.environ["OPENAI_API_KEY"] = api_key |
There was a problem hiding this comment.
If api_key is not specified in model_cfg, the code currently overwrites os.environ["OPENAI_API_KEY"] with DEFAULT_FAKE_API_KEY ("fake_api_key"). This will break evaluations for users who have already set a valid OPENAI_API_KEY in their environment. We should check if the environment variable is already set before defaulting to the fake key.
| def _set_api_key(self): | |
| api_key = self.model_cfg.get("api_key") | |
| if api_key is None: | |
| api_key = DEFAULT_FAKE_API_KEY | |
| os.environ["OPENAI_API_KEY"] = api_key | |
| def _set_api_key(self): | |
| api_key = self.model_cfg.get("api_key") | |
| if api_key is None: | |
| api_key = os.environ.get("OPENAI_API_KEY", DEFAULT_FAKE_API_KEY) | |
| os.environ["OPENAI_API_KEY"] = api_key |
There was a problem hiding this comment.
[review] 如果 model_cfg 中未指定 api_key,则当前代码会将 os.environ["OPENAI_API_KEY"] 覆盖为 DEFAULT_FAKE_API_KEY("fake_api_key"))。这将导致已在其环境中设置有效 OPENAI_API_KEY 的用户无法进行评估。我们应该在默认使用伪造密钥之前,检查环境变量是否已设置。
| def _handle_sigterm(signum, frame): | ||
| stop_event.set() | ||
| raise KeyboardInterrupt | ||
|
|
||
| signal.signal(signal.SIGTERM, _handle_sigterm) |
There was a problem hiding this comment.
In Python, signal.signal can only be called from the main thread. If this task is executed in a non-main thread (e.g., as part of a multi-threaded pipeline or background worker), calling signal.signal will raise a ValueError and crash the task. Wrap the call in a try-except ValueError block to make it safe.
| def _handle_sigterm(signum, frame): | |
| stop_event.set() | |
| raise KeyboardInterrupt | |
| signal.signal(signal.SIGTERM, _handle_sigterm) | |
| def _handle_sigterm(signum, frame): | |
| stop_event.set() | |
| raise KeyboardInterrupt | |
| try: | |
| signal.signal(signal.SIGTERM, _handle_sigterm) | |
| except ValueError: | |
| pass |
There was a problem hiding this comment.
[review]在 Python 中,signal.signal 只能从主线程调用。如果此任务在非主线程中执行(例如,作为多线程管道或后台工作线程的一部分),调用 signal.signal 将引发 ValueError 并导致任务崩溃。为了安全起见,请将调用包装在 try-except ValueError 代码块中。
| if args.get("verifier_env"): | ||
| env_list = args["verifier_env"] | ||
| if isinstance(env_list, list): | ||
| config.verifier.env.update({k: v for k, v in (e.split("=", 1) for e in env_list if "=" in e)}) |
There was a problem hiding this comment.
If config.verifier.env is None (which can happen depending on how the Pydantic model is initialized or configured), calling .update() on it will raise an AttributeError. Ensure it is initialized to an empty dictionary before updating.
| if args.get("verifier_env"): | |
| env_list = args["verifier_env"] | |
| if isinstance(env_list, list): | |
| config.verifier.env.update({k: v for k, v in (e.split("=", 1) for e in env_list if "=" in e)}) | |
| if args.get("verifier_env"): | |
| env_list = args["verifier_env"] | |
| if isinstance(env_list, list): | |
| if config.verifier.env is None: | |
| config.verifier.env = {} | |
| config.verifier.env.update({k: v for k, v in (e.split("=", 1) for e in env_list if "=" in e)}) |
There was a problem hiding this comment.
[review] 如果 config.verifier.env 为 None(这取决于 Pydantic 模型的初始化或配置方式),则对其调用 .update() 会引发 AttributeError。请确保在更新之前将其初始化为空字典。
| if has_total_count: | ||
| row.insert(4, len(sg['subsets'])) | ||
| row.extend([parsed_results[m].get(sg['name'], {}).get(sg.get('metric', 'naive_average'), '-') for m in self.model_abbrs]) | ||
| table.append(row) |
There was a problem hiding this comment.
【review】mmengine.utils does not contain a TimeStub class or attribute. Attempting to call mmengine.utils.TimeStub.now() will raise an AttributeError and crash the summarizer. Use the standard library datetime module instead.
| row = [sg['name'], sg.get('version', '-'), sg.get('metric', 'naive_average'), dataset_eval_mode.get(sg['name'], 'gen')] | ||
| if has_total_count: | ||
| row.insert(4, len(sg['subsets'])) | ||
| row.extend([parsed_results[m].get(sg['name'], {}).get(sg.get('metric', 'naive_average'), '-') for m in self.model_abbrs]) |
There was a problem hiding this comment.
【review】The current implementation of table row construction loops over self.model_abbrs and appends a single model's score to a new row, then appends that row to the table. However, the table header contains columns for all models. This results in malformed rows where the columns do not align with the header (e.g., a row for the second model will have its score displayed under the first model's column, and the row length will not match the header length). Additionally, the summary groups loop will add duplicate rows for each model that has results. We should construct a single row per metric/summary group and populate the scores for all models in that row.
| f.write(tabulate.tabulate(table[1:], headers=table[0], tablefmt='grid')) | ||
|
|
||
| print(f'write csv to {summary_csv}') | ||
| with open(summary_csv, 'w', encoding='utf-8') as out: |
There was a problem hiding this comment.
【review】tabulate does not support csv as a table format. Attempting to use tablefmt='csv' will raise a ValueError: unknown table format: csv and crash the summarizer. Write the CSV file manually or use a standard CSV writer.
| config.verifier.disable = True | ||
| if args.get("verifier_env"): | ||
| env_list = args["verifier_env"] | ||
| if isinstance(env_list, list): |
There was a problem hiding this comment.
【review】If config.verifier.env is None (which can happen depending on how the Pydantic model is initialized or configured), calling .update() on it will raise an AttributeError. Ensure it is initialized to an empty dictionary before updating.
| stop_event.set() | ||
| raise KeyboardInterrupt | ||
|
|
||
| signal.signal(signal.SIGTERM, _handle_sigterm) |
There was a problem hiding this comment.
【reivew】In Python, signal.signal can only be called from the main thread. If this task is executed in a non-main thread (e.g., as part of a multi-threaded pipeline or background worker), calling signal.signal will raise a ValueError and crash the task. Wrap the call in a try-except ValueError block to make it safe.
Thanks for your contribution; we appreciate it a lot. The following instructions will make your pull request healthier and help you get feedback more easily. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
感谢您的贡献,我们非常重视。以下说明将使您的拉取请求更健康,更易于获得反馈。如果您不理解某些项目,请不要担心,只需提交拉取请求并从维护人员那里寻求帮助即可。
PR Type / PR类型
Related Issue | 关联 Issue
Fixes #(issue ID / issue 编号) / Relates to #(issue ID / issue 编号)
🔍 Motivation / 变更动机
Please describe the motivation of this PR and the goal you want to achieve through this PR.
请描述您的拉取请求的动机和您希望通过此拉取请求实现的目标。
#314
📝 Modification / 修改内容
Please briefly describe what modification is made in this PR.
请简要描述此拉取请求中进行的修改。
📐 Associated Test Results / 关联测试结果
Please provide links to the related test results, such as CI pipelines, test reports, etc.
请提供相关测试结果的链接,例如 CI 管道、测试报告等。
Does the modification introduce changes that break the backward compatibility of the downstream repositories? If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
是否引入了会破坏下游存储库向后兼容性的更改?如果是,请描述它如何破坏兼容性,以及下游项目应该如何修改其代码以保持与此 PR 的兼容性。
If the modification introduces performance degradation, please describe the impact of the performance degradation and the expected performance improvement.
如果引入了性能下降,请描述性能下降的影响和预期的性能改进。
🌟 Use cases (Optional) / 使用案例(可选)
If this PR introduces a new feature, it is better to list some use cases here and update the documentation.
如果此拉取请求引入了新功能,最好在此处列出一些用例并更新文档。
✅ Checklist / 检查列表
Before PR:
After PR:
👥 Collaboration Info / 协作信息
🌟 Useful CI Command / 实用的CI命令
/gemini review/gemini summary/gemini help/readthedocs build