Skip to content

[duplicate-code] refactor: share repeated harness output pattern matchers - #75757

Merged
pelikhan merged 3 commits into
mainfrom
refactor-shared-harness-output-matchers-567820cd9e96f148
Nov 7, 2026
Merged

pelikhan merged 3 commits into
mainfrom
refactor-shared-harness-output-matchers-567820cd9e96f148

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

🔍 Duplicate Code Detected: Harness output-pattern predicates

Analysis of recent Go and CommonJS commits using Serena semantic analysis.

Summary

Recent harness changes left the same three-line regex-predicate wrapper duplicated across the Claude, Codex, and Copilot runtimes. The duplicate pattern appeared six times across three harness files, exceeding the requested threshold and creating parallel maintenance points for shared classification behavior.

Duplication Details

Pattern: return PATTERN.test(output) wrappers

  • Severity: Medium
  • Occurrences: 6 wrapper implementations across 3 runtime harnesses
  • Locations:
    • actions/setup/js/claude_harness.cjs: isRateLimitError, isConnectionRefusedError, and isInvalidModelError
    • actions/setup/js/codex_harness.cjs: isRateLimitError and isInvalidModelError
    • actions/setup/js/copilot_harness.cjs: isConnectionRefusedError
  • Evidence: Each occurrence was a named function whose body only returned PATTERN.test(output), for 18 duplicated wrapper-body lines in total. The provider-specific regular expressions remain intentionally distinct.

Impact Analysis

  • Maintainability: Changes to the common wrapper shape had to be repeated in every engine harness.
  • Bug Risk: One harness could diverge in output-predicate handling while the other harnesses remained unchanged.
  • Code Bloat: Six boilerplate wrappers repeated the same matcher-construction logic.

Implemented Refactoring

  • Added createOutputPatternMatcher to actions/setup/js/harness_error_patterns.cjs.
  • Re-exported it through harness_retry_guard.cjs, preserving the existing harness import boundary.
  • Replaced the six duplicate wrappers with shared matcher construction in the Claude, Codex, and Copilot harnesses.
  • Preserved each engine's existing regular expression and exported predicate name; no classification rule was broadened or removed.
  • No workflow lock files were changed.

Validation

  • ✅ node --check passed for all four changed CommonJS files.
  • ✅ Direct Node smoke checks loaded all three harness modules and verified representative rate-limit, invalid-model, and connection-refused classifications.
  • ✅ git diff --check passed.
  • ⚠️ make fmt-cjs and make lint-cjs could not run to completion because the workspace has no local Prettier binary and npx was blocked by DEPTH_ZERO_SELF_SIGNED_CERT while requesting registry.npmjs.org.
  • ⚠️ The targeted Vitest command for claude_harness.test.cjs, codex_harness.test.cjs, and copilot_harness.test.cjs could not start because vitest is not installed in the workspace. No Vitest results are being claimed.

Analysis Metadata

  • Analyzed recent commits: 119c1ef (documentation-only), dd9fca5 (harness deduplication), dc2578f (runtime/Go fixes), 1f4083e (MCP validation), and b5d8d79 (run artifact processor split).
  • Analyzed files: Changed non-test .go/.cjs files from the recent commits, with primary focus on pkg/ and the three harness runtimes.
  • Detection method: Serena symbol overviews, symbol bodies, references, and pattern searches.
  • Pre-change overlap check: Searched open issues and pull requests for duplicate-code, deduplication, and harness-error work; no active pull request covering this refactoring was found.

References

  • Commit dd9fca59249a92276cfa006ce728d70605bcc576 — Deduplicate JavaScript harness prompt and permission handling
  • Commit b5d8d79195f2849420262cef75a43fb1c8cc0984 — Split run artifact processor into focused files

Generated by 🔍 Duplicate Code Detector · pi · routed: gpt56 max · ~21 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

  • expires on Nov 9, 2026, 2:07 PM UTC-08:00

@github-actions github-actions Bot added automated-analysis code-quality cookie Issue Monster Loves Cookies! labels Nov 7, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 7, 2026 22:11
Copilot AI adaptive review requested due to automatic review settings November 7, 2026 22:11
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75757

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt56 max · ~2 AIC · ⌖ ~1 AIC · ⊞ 118 · ◷

Generated by Ponytail Reviewer for #75757

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed the changed harness matcher refactor and its export path. The shared helper is correctly re-exported through harness_retry_guard.cjs, regexes are non-global, and the replacements preserve behavior. No actionable correctness, performance, or maintainability issues found in the changed lines. Specialist pass completed; its unverified-export and test-coverage concerns were discarded after checking the existing export and scope.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the supplied evidence, and the refactor preserves the existing provider-specific patterns and exported predicates.

No open issues 🎉

What changed in this PR

This pull request removes duplicated output-pattern predicate wrappers from the Claude, Codex, and Copilot harnesses by centralizing matcher construction while preserving existing classification behavior.

Changes:

  • Added and exported createOutputPatternMatcher.
  • Replaced six duplicated predicate implementations across the three harnesses.
  • Preserved provider-specific regular expressions and exported predicate names.
  • No workflow lock files were changed.
File Description
actions/​setup/​js/​harness_error_patterns.cjs Defines and exports the shared output-pattern matcher factory.
actions/​setup/​js/​copilot_harness.cjs Uses the shared matcher for connection-refused detection.
actions/​setup/​js/​codex_harness.cjs Uses the shared matcher for rate-limit and invalid-model detection.
actions/​setup/​js/​claude_harness.cjs Uses the shared matcher for rate-limit, connection-refused, and invalid-model detection.

Review effort: Lite (auto)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /codebase-design and /tdd. Approving: the refactor preserves every classification rule, and the one note left is low severity.

📋 Key Themes & Highlights

Verified

  • ✅ Each pattern constant is declared before its createOutputPatternMatcher(...) call, so the const is not used before initialization. All call sites are inside function bodies.
  • ✅ harness_retry_guard.cjs spreads ...errorPatterns, so the re-export reaches all three harnesses.
  • ✅ node --check passes on all changed files. Plain-Node smoke loads of the three harnesses return the expected classifications.
  • ✅ No test mocks these modules, and no test relies on the old wrapper function .name.
  • ✅ The invalid-model pattern is non-global, so the stateful lastIndex hazard does not apply to any current caller.

Notes

  • [/codebase-design] Low: the helper is stateful for /g and /y patterns. See the inline comment on harness_error_patterns.cjs. Optional guard or JSDoc note.
  • [/tdd] No direct unit test covers createOutputPatternMatcher. A one-case test in harness_retry_guard.test.cjs would lock the contract in, though the harness suites already exercise each predicate indirectly.
  • The .name of the returned matcher is now empty. Nothing in the repo reads it, so this is safe.
  • I could not run the vitest suites: npm ci fails here with DEPTH_ZERO_SELF_SIGNED_CERT, the same blocker the PR notes. CI should run them; the approval assumes they pass.

@copilot please address the low-severity inline note if you agree with it.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 5.4K
Comment /matt to run again

* @returns {(output: string) => boolean}
*/
function createOutputPatternMatcher(pattern) {
return output => pattern.test(output);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/codebase-design] Low severity: pattern.test is stateful for /g and /y regexes, because lastIndex carries across calls. A future global pattern passed here would alternate between true and false. The old per-function wrappers had the same property, so this is not a regression, and all three current patterns are non-global (MODEL_NOT_SUPPORTED_PATTERN only has the i flag).

💡 Optional guard
function createOutputPatternMatcher(pattern) {
  return output => {
    pattern.lastIndex = 0;
    return pattern.test(output);
  };
}

Alternatively, add a JSDoc line stating the pattern must be non-global.

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check lint-js (FAILURE): https://github.com/github/gh-aw/actions/runs/42419480205/job/128544690981.

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: 93b9fde
Sous-chef requested-work: bbcbbd0ca3f44836842efeccbe6ee4e009cf3d5f19a08d57a88ad2789afa0a2e
Sous-chef requested-state: b5820242de48b4e9f7145d59e47e2a8ca7fd620f0768a3cd6b8fe3c07243b726

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~4 AIC · ⌖ ~14 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@copilot

Copilot assignment requested for the following outstanding work:...

Sous-chef requested-head: 93b9fde
Sous-chef requested-work: bbcbbd0ca3f44836842efeccbe6ee4e009cf3d5f19a08d57a88ad2789afa0a2e
Sous-chef requested-state: b5820242de48b4e9f7145d59e47e2a8ca7fd620f0768a3cd6b8fe3c07243b726

Copilot AI and others added 2 commits November 7, 2026 22:54
…ss-output-matchers-567820cd9e96f148

Co-authored-by: gh-aw-bot <[email protected]>
@pelikhan
pelikhan merged commit d998be5 into main Nov 7, 2026
4 checks passed
@pelikhan
pelikhan deleted the refactor-shared-harness-output-matchers-567820cd9e96f148 branch November 7, 2026 23:07
Copilot stopped work on behalf of gh-aw-bot due to an error November 7, 2026 23:07
Copilot AI requested a review from gh-aw-bot November 7, 2026 23:07
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.2

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.

4 participants