Skip to content

fix(commands): bound unknown verb suggestions - #3954

Merged
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-unbounded-command-suggestion
Jul 7, 2026
Merged

fix(commands): bound unknown verb suggestions#3954
JSONbored merged 1 commit into
mainfrom
codex/propose-fix-for-unbounded-command-suggestion

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent an availability regression where unbounded did‑you‑mean distance calculations allocate a quadratic matrix for attacker-controlled long @gittensory verbs and can exhaust worker CPU/heap.
  • Add lightweight guards so webhook rendering no longer performs expensive work for oversized or obviously-out-of-range suggestions.

Description

  • Introduce COMMAND_SUGGEST_MAX_VERB_LENGTH = 64 and short‑circuit suggestions for unknown verbs longer than that limit.
  • Replace the full‑matrix levenshteinDistance implementation with a bounded rolling‑row implementation boundedLevenshteinDistance(left, right, maxDistance) that early‑exits when the distance cannot be within maxDistance, and preserve levenshteinDistance as a wrapper.
  • In suggestCommand skip targets whose length delta exceeds COMMAND_SUGGEST_MAX_DISTANCE and use the bounded distance function with the max threshold to avoid heavy work on each catalog entry.
  • Add a unit regression asserting that oversized unknown verbs produce no suggestion and update formatting/imports in the related test file.

Testing

  • Ran npx vitest run test/unit/command-suggest.test.ts, and the unit suite for the changed file passed.
  • Ran npm run typecheck, which succeeded with no type errors.
  • Attempted coverage run npx vitest run --coverage --pool=forks test/unit/command-suggest.test.ts, where tests passed but coverage remapping failed with TypeError: jsTokens is not a function.
  • Attempted the full gate with npm run test:ci, which progressed through early lint/type checks but was stopped during the repository's test:coverage stage due to pre‑existing unrelated RangeError: Maximum call stack size exceeded output from the larger test suite, so the full CI gate was not completed here.

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 7, 2026
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.66%. Comparing base (1ce4364) to head (01ee744).
⚠️ Report is 16 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/github/command-suggest.ts 91.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3954      +/-   ##
==========================================
- Coverage   93.66%   93.66%   -0.01%     
==========================================
  Files         372      372              
  Lines       34856    34867      +11     
  Branches    12743    12747       +4     
==========================================
+ Hits        32649    32658       +9     
- Misses       1588     1589       +1     
- Partials      619      620       +1     
Files with missing lines Coverage Δ
src/github/command-suggest.ts 95.55% <91.30%> (-4.45%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb

loopover-orb Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review result - fixes required

Review updated: 2026-07-07 09:14:48 UTC

2 files · 1 AI reviewer · 3 blockers · readiness 93/100 · CI failing · unstable

🛑 Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
  • AI reviewers agree on a likely critical defect: This PR does not close or clearly link an eligible open issue as required by repo convention — the only issue reference in the file is the pre-existing `(feat(commands): unknown-@gittensory-verb suggestion (did-you-mean) in the help fallback #2170)` doc comment, not a tracked issue for this specific hardening fix, so it isn't merge-ready without one. — Resolve the flagged defect, or override if the AI reviewers are mistaken, then re-run the gate.

Review summary
This bounds the previously quadratic-time levenshteinDistance behind a rolling-array implementation with an early distance-cutoff, adds a 64-char verb-length short-circuit, and skips catalog targets whose length delta already exceeds the suggestion threshold in suggestCommand (src/github/command-suggest.ts). The bounded-distance algorithm itself is a correct, standard rolling-row Levenshtein-with-cutoff (verified by hand-tracing 'ab'/'ba' against maxDistance=1), and the wrapper preserves the old unbounded levenshteinDistance behavior for existing callers/tests. The PR's description does not link or close any tracked issue for this fix, and codecov/patch failed at 91.30% vs the repo's 99% target because the internal length-delta guard inside boundedLevenshteinDistance (command-suggest.ts) is now dead code for every real caller.

Blockers

Nits — 5 non-blocking
  • boundedLevenshteinDistance's internal `Math.abs(left.length - right.length) > maxDistance` guard (src/github/command-suggest.ts) is now unreachable: suggestCommand already filters targets on the same condition before calling it, and the exported `levenshteinDistance` wrapper always passes `Number.MAX_SAFE_INTEGER`, so this branch is dead in both callers — likely the source of the codecov/patch shortfall (91.30% vs 99%), worth removing the duplicate guard or covering it with a direct unit test on `boundedLevenshteinDistance` if you want it kept for defense-in-depth.
  • No test directly exercises `boundedLevenshteinDistance`'s mid-loop `rowMin > maxDistance` early-return with a case where the bail happens partway through a row rather than on the first row — consider a targeted case (e.g. long-but-equal-length strings that diverge early) to pin down that optimization.
  • `COMMAND_SUGGEST_MAX_VERB_LENGTH = 64` is a reasonable but unexplained magic number relative to `COMMAND_SUGGEST_MAX_DISTANCE = 2` and real catalog entries — a one-line comment on why 64 (vs. e.g. longest catalog name + max distance) would help future maintainers reason about the bound.
  • Link this PR to the tracking issue for the availability/DoS concern (or open one) so the fix has a documented motivation beyond the PR description.
  • Since the outer length-delta check in suggestCommand (src/github/command-suggest.ts) already makes boundedLevenshteinDistance's internal length-delta guard dead, either delete the internal check (simpler, DRY) or add a unit test that calls it in a context where the outer guard doesn't apply, to close the coverage gap codecov flagged.

Why this is blocked

  • This PR does not close or clearly link an eligible open issue as required by repo convention — the only issue reference in the file is the pre-existing `(feat(commands): unknown-@gittensory-verb suggestion (did-you-mean) in the help fallback #2170)` doc comment, not a tracked issue for this specific hardening fix, so it isn't merge-ready without one.
  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

CI checks failing

  • codecov/patch — 91.30% of diff hit (target 99.00%)
Signal Result Evidence
Code review ❌ 3 blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 51 registered-repo PR(s), 43 merged, 569 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 569 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 51 PR(s), 569 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 7, 2026
@JSONbored
JSONbored merged commit b60f0d7 into main Jul 7, 2026
9 of 10 checks passed
@JSONbored
JSONbored deleted the codex/propose-fix-for-unbounded-command-suggestion branch July 7, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant