Skip to content

Fix AC code export for 5-digit question IDs and UpdateVersion workflow infinite recursion#888

Merged
PythonSmall-Q merged 160 commits intodevfrom
copilot/fix-ac-code-export-issue
Feb 6, 2026
Merged

Fix AC code export for 5-digit question IDs and UpdateVersion workflow infinite recursion#888
PythonSmall-Q merged 160 commits intodevfrom
copilot/fix-ac-code-export-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

AC code export fails for questions with IDs ≥10000 due to hardcoded 4-digit extraction at positions 7-11. Additionally, fixes the UpdateVersion GitHub Action workflow that was creating an infinite loop of commits.

Changes

1. AC Code Export Fix (XMOJ.user.js)

Replaced fixed-position substring extraction with dynamic parsing:

Before:

let CurrentQuestionID = CurrentCode.substring(7, 11);  // Always extracts 4 chars
CurrentCode = CurrentCode.substring(14);

After:

let lineBreakPos = CurrentCode.search(/[\r\n]/);
if (lineBreakPos === -1) continue;
let headerLine = CurrentCode.slice(0, lineBreakPos);
let digitMatch = headerLine.match(/\d+/);
if (!digitMatch) continue;
let CurrentQuestionID = digitMatch[0];  // Extracts variable-length ID
let newlinePos = CurrentCode.indexOf('\n');
CurrentCode = CurrentCode.slice(newlinePos + 1);

Handles question IDs of any length. Adds validation to skip malformed entries.

2. UpdateVersion Workflow Fix (.github/workflows/UpdateVersion.yml)

Fixed infinite recursion caused by the workflow triggering itself:

Added condition:

if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'github-actions[bot]'

This prevents the workflow from running when commits are made by github-actions[bot], breaking the infinite loop that was creating hundreds of duplicate commits.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] 导出AC代码功能只有1000-9999的代码,无法导出10000以上的代码</issue_title>
<issue_description>### 检查项

  • 我已确认了XMOJ增强脚本已为最新版,且最新版未修复这个 Bug 。
  • 我已在 Issues 页面 中搜索,确认了这一 Bug 未被提交过。

描述

今天导出AC代码的时候发现1打头部分和9937(四位数题号中我AC的题号最大一道题)后面都没有五位数题号,但是在个人中心页面显示我AC过五道五位数题号的题目。点进去检查后确认这五道题已经在xmoj上AC过并且代码是正确的。

重现步骤

0.确保AC过一道以上题号10000+的题目
1.导出AC代码
2.查找压缩包中大于9999.cpp的题号,发现没有

控制台错误信息

No response</issue_description>

<agent_instructions>第300行左右的地方有bug,导出的AC代码是硬编码四位数,但是题号已经到了五位数 let CurrentQuestionID = CurrentCode.substring(7, 11); CurrentCode = CurrentCode.substring(14);</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@boomzero 好的,~~竟然还有人用这个~~ @boomzero btw, 我们决定给提issue的人write权限

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Summary by cubic

Fixes the export bug that skipped AC code for problems with IDs above 9999. The exporter now handles variable-length IDs so five-digit problems are included in the ZIP.

  • Bug Fixes
    • Removed 4-digit hardcoding when parsing question IDs; use flexible ID extraction instead of fixed substrings.
    • Added validation to skip malformed entries and support for both \r\n and \n line endings.
    • Updated filename generation and filtering to correctly handle IDs >= 10000.
    • Prevented UpdateVersion workflow loops by skipping runs on bot commits for same-repo PRs.

Written for commit 83609ec. Summary will update on new commits.

Copilot AI and others added 3 commits February 6, 2026 01:05
Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
@pull-request-size pull-request-size bot added size/S and removed size/XS labels Feb 6, 2026
Copilot AI changed the title [WIP] Fix bug in exporting AC codes for topics above 9999 Fix AC code export for 5-digit question IDs Feb 6, 2026
Copilot AI requested a review from PythonSmall-Q February 6, 2026 01:08
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@PythonSmall-Q
Copy link
Member

@boomzero REVIEW

Copy link
Member

@boomzero boomzero left a comment

Choose a reason for hiding this comment

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

Though pls fix CI inf recursion

@PythonSmall-Q
Copy link
Member

@copilot please fix the problem of the updateversion github action flow recuring nonstop

Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot please fix the problem of the updateversion github action flow recuring nonstop

Fixed in commit 83609ec. Added a condition to the UpdateVersion workflow to skip execution when the actor is github-actions[bot], which prevents the bot's commits from triggering the workflow recursively.

Copilot AI changed the title Fix AC code export for 5-digit question IDs Fix AC code export for 5-digit question IDs and UpdateVersion workflow infinite recursion Feb 6, 2026
Copilot AI requested a review from PythonSmall-Q February 6, 2026 14:29
@PythonSmall-Q PythonSmall-Q merged commit 8fd8a9c into dev Feb 6, 2026
3 checks passed
@PythonSmall-Q PythonSmall-Q deleted the copilot/fix-ac-code-export-issue branch February 6, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants