Skip to content

fix: prevent GitHub work item identity collisions - #3588

Merged
haelyra merged 1 commit into
affaan-m:mainfrom
shoyann:fix/github-work-item-identities
Oct 29, 2026
Merged

haelyra merged 1 commit into
affaan-m:mainfrom
shoyann:fix/github-work-item-identities

Conversation

@shoyann

@shoyann shoyann commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

What Changed

Prevent work-items sync-github from overwriting another repository's work item when repository names produce the same slug. For example, acme/tool-kit#1 and acme/tool_kit#1 now remain separate records for both issues and PRs.

New IDs encode the case-normalized repository name without discarding punctuation or the owner/repository boundary. Existing imported IDs are retained only when their repository, source, source number, and sync marker match. An existing canonical ID takes precedence, and a conflicting canonical record produces an error instead of being overwritten. Stale-item matching uses the same case-insensitive repository identity.

No schema migration or bulk ID rewrite is required; existing matching records retain their IDs and creation timestamps. Other sync field-update behavior is unchanged.

Why This Change

The previous slug collapsed /, -, _, and . into -. The resulting primary-key collision caused SQLite's upsert to silently replace the first repository's record with the second repository's data.

Testing Done

  • Added 17 passing regressions using the real CLI and SQLite store with mocked GitHub responses: punctuation and owner/repository boundary collisions, issues and PRs, legacy compatibility, repeated sync, casing, malformed legacy metadata, occupied IDs, isolated stale closure, and a display/claim/close lifecycle for encoded IDs.
  • Existing state-store suite: 20 passed. Existing work-item claim suite: 7 passed.
  • All changed production lines and all 22 branch locations in the changed identity/stale-matching regions are covered. Whole work-items.js coverage: 86.26% lines, 76.81% branches, 95.83% functions.
  • ESLint: no errors, three existing complexity warnings. git diff --check passes. Independent code review found no actionable issues.
  • Full npm test: validators pass; 419 test files pass and two fail (install-guided.test.js and setup.test.js, 13 failing PTY cases). The same failing cases were reproduced on unmodified base commit b92f181b; no additional failures appear with this change.

Type of Change

  • fix: Bug fix

Security & Quality Checklist

  • No secrets or API keys committed
  • No sensitive data exposed in logs or output
  • Follows conventional commits format

@shoyann
shoyann requested a review from affaan-m as a code owner October 15, 2026 10:51
@ecc-tools

ecc-tools Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: 932aa393c1f54dea868ebda9cefb54072feb2dfe

Security evidence gate passed (success)

No security-sensitive scanner-evidence gap detected.

Mode: enforce

Scanned 3 changed file(s). No missing scanner-evidence signal was detected.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: 932aa393c1f54dea868ebda9cefb54072feb2dfe

PR taxonomy review recommended (neutral)

Detected 1 PR taxonomy bucket(s): CI/CD Recommendation.

Scanned 3 changed file(s).

Roadmap taxonomy buckets:

CI/CD Recommendation

CI, dependency, coverage, and contract signals should be routed into follow-up checks or verification work.

Signals:

  • 2 CI or workflow path(s) changed

Paths:

  • tests/lib/state-store.test.js
  • tests/scripts/work-items-identity.test.js

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: 932aa393c1f54dea868ebda9cefb54072feb2dfe

Reference set readiness gaps detected (neutral)

Reference evidence present for 0/7 areas (0%) across 3 changed file(s).

This check is based on files changed in this PR. Repository-level readiness is still reported by /ecc-tools analyze comments and generated manifests.

Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: 932aa393c1f54dea868ebda9cefb54072feb2dfe

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 3 changed file(s); 0 corpus scenarios had matching evidence.

This check compares PR file changes against the evaluator/RAG promotion corpus in src/analyzers/fixtures/evaluator-rag-corpus.ts.
Hosted output scoring inspected 0 completed cached hosted job results.

No evaluator corpus scenarios matched this PR.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: affaan-m/ECC/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: dd727db6-ab0c-4807-8c9f-ff54407b3c7d
📥 Commits

Reviewing files that changed from the base of the PR and between b92f181 and 932aa39.

📒 Files selected for processing: 3
  • scripts/work-items.js
  • tests/lib/state-store.test.js
  • tests/scripts/work-items-identity.test.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

⏰ Context from checks skipped due to timeout: 1
  • GitHub Check: Greptile Review
🧰 Additional context used
📚 Code guidelines: 4
.cursor/rules/typescript-security.md — auto-discovered
.cursor/rules/common-hooks.md — auto-discovered
.cursor/rules/typescript-coding-style.md — auto-discovered
.cursor/rules/typescript-hooks.md — auto-discovered
📓 Path-based instructions: 5
Focus on command injection, unsafe subprocess usage, path traversal, SSRF, secret exposure, and missing tests for new CLI behavior.

⚙️ CodeRabbit configuration file

Files:

  • scripts/work-items.js
Source excerpt: Source excerpt: Use **security-reviewer** skill for comprehensive security audits

📄 CodeRabbit inference engine (.cursor/rules/typescript-security.md)

Files:

  • tests/lib/state-store.test.js
  • scripts/work-items.js
  • tests/scripts/work-items-identity.test.js
Source excerpt: Use with caution: Source excerpt: Use with caution: Enable for trusted, well-defined plans Source excerpt: Use with caution: Disable for exploratory work Source excerpt: Use with caution: Never use dangerously-skip-permissio...

📄 CodeRabbit inference engine (.cursor/rules/common-hooks.md)

Files:

  • tests/lib/state-store.test.js
  • scripts/work-items.js
  • tests/scripts/work-items-identity.test.js
Source excerpt: Use spread operator for immutable updates: Source excerpt: Use async/await with try-catch: Source excerpt: Use Zod for schema-based validation: Source excerpt: Use proper logging libraries instead

📄 CodeRabbit inference engine (.cursor/rules/typescript-coding-style.md)

Files:

  • tests/lib/state-store.test.js
  • scripts/work-items.js
  • tests/scripts/work-items-identity.test.js
Source excerpt: **console.log audit**: Check all modified files for `console.log` before session ends

📄 CodeRabbit inference engine (.cursor/rules/typescript-hooks.md)

Files:

  • tests/lib/state-store.test.js
  • scripts/work-items.js
  • tests/scripts/work-items-identity.test.js
🪛 ast-grep (0.45.3)
tests/scripts/work-items-identity.test.js

[warning] 7-7: Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: require('node:child_process')
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process)

[warning] 19-23: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(shimPath, [
"const fs = require('node:fs');",
'const response = JSON.parse(fs.readFileSync(process.env.ECC_IDENTITY_RESPONSE, "utf8"));',
'process.stdout.write(JSON.stringify(response[process.argv[2]]));'
].join('\n'))
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

[warning] 34-34: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.writeFileSync(responsePath, JSON.stringify(response))
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

🔇 Additional comments: 5
scripts/work-items.js: 3

179-208: LGTM!

276-276: LGTM!

312-330: LGTM!

tests/scripts/work-items-identity.test.js: 1

1-265: LGTM!

tests/lib/state-store.test.js: 1

983-983: LGTM!

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • GitHub work items are now identified more consistently across repositories, reducing the risk of records being confused when repository names contain punctuation or similar text.
    • Syncing now detects identity conflicts instead of overwriting a different work item.
    • Existing work-item links are preserved where possible, and stale items are matched more reliably when repository name casing differs.

GitHub work-item IDs now encode lowercased repository names. Sync checks canonical IDs for collisions, reuses matching legacy IDs when appropriate, and matches repository names case-insensitively when closing stale items.

Changes: GitHub Work-Item Identity

Layer / File(s) Summary
Resolve and persist GitHub work-item IDs
scripts/work-items.js, tests/scripts/work-items-identity.test.js, tests/lib/state-store.test.js
Sync uses encoded repository names for canonical IDs, checks for conflicting records, and reuses matching legacy IDs when applicable. Tests cover ID uniqueness, legacy-record matching, collision handling, and encoded IDs across CLI commands.
Match stale items by repository
scripts/work-items.js, tests/scripts/work-items-identity.test.js
Stale-item matching ignores repository-name casing. Tests verify that closing stale items affects only the matching repository.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 932aa

GitHub work-item sync now avoids overwriting items when repository names collide, and the supplied evidence shows no outstanding merge-blocking issue.

Security architecture risk: 🔵 Low · up to 932aa

The change prevents repository-name collisions from overwriting unrelated work items and checks record ownership before reuse. Remaining uncertainty concerns concurrent writes, active legacy duplicates, and rollback to an older version; no introduced privilege escalation or independently reachable attack path was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated outcome is integrity of work-item records within the selected local store, which can contain multiple repositories. GitHub fields supply item content and source numbers, while the CLI caller selects the repository and database. The inspected path does not grant those GitHub fields new command-execution or credential authority.

Trust Boundaries and Controls

  • observed — The routed test entrypoints are a changed assertion and a temporary-database CLI fixture with a local GitHub-response shim. They do not themselves introduce a production network entrypoint or authentication bypass; the meaningful contract change is in the existing CLI synchronization path.
  • inferred — Ownership validation and persistence are not one atomic operation: each store call obtains its own snapshot lock, and the SQL upsert remains unconditional on ID conflict. However, distinct legitimate repository identities now have distinct canonical IDs. Creating an unrelated row in the lookup/write window requires another same-store writer, and the existing CLI already permits arbitrary-ID upserts; no increased attacker authority was established.

Resilience and Maintainability Implications

  • observed — A later collision or interruption can leave earlier item writes committed and prevent the stale-closure phase from running. Batch non-atomicity predates this PR; the new collision check stops rather than overwriting the conflicting record. Recovery remains repetition after resolving the collision, not automatic batch rollback.

Hardening Proposals

  • proposed — If stronger shared-store guarantees are required, combine identity validation and persistence in one locked transaction. Define active legacy-duplicate and downgrade behavior explicitly before promising compatibility across concurrent or older writers. These are strengthening proposals, not observed privilege-boundary failures.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing GitHub work-item identity collisions.
Description check Passed The description directly explains the identity-collision fix, implementation behavior, compatibility requirements, and test results.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] Safe to merge within the reviewed scope; no blocking issues were found in repository identity handling, legacy compatibility, stale closure, or the encoded-ID CLI lifecycle.

Summary

Prevents sync-github from overwriting work items from repositories whose names produce the same slug.

  • GitHub issues and pull requests keep distinct IDs across repository names.
  • Stale GitHub items match their repository without regard to letter case.

No actionable issues found. All 14 selected regression tests passed. Additional real-CLI and SQLite checks passed all 65 identity assertions and all 22 stale-closure and lifecycle checks. These checks confirmed that punctuation-distinct repositories retain separate records, mismatched legacy records remain unchanged, stale closure affects only the matching repository, and encoded IDs work through display, claim, and close. Comparisons against the base revision reproduced the earlier repository collisions and case-sensitive stale-closure behavior.

Intentional behavior acknowledged by shoyann: canonical IDs take precedence, and an occupied canonical ID causes an error rather than an overwrite.

The reviewed changes are safe to merge; no blocking issues were found.

Reviews (1) · Last reviewed commit: "fix: prevent GitHub work item identity c..." · Reviewed by Greptile

@haelyra
haelyra merged commit d2c71fd into affaan-m:main Oct 29, 2026
46 checks passed
@haelyra

haelyra commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Thank you for preventing GitHub identity collisions while retaining legacy IDs. This is now merged through #3806, with your contributor head preserved.

The combined integration and exact resulting main passed CI, CodeQL and a fresh supply-chain scan (CI, main 91b5f6a3). We appreciate the focused contribution.

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.

2 participants