From 759a7a83e6423d9535809421683e5b15a1cde28c Mon Sep 17 00:00:00 2001
From: Rui Maduro
Date: Sat, 28 Nov 2026 14:54:29 +0000
Subject: [PATCH 1/2] feat: suggest similar open issues while drafting /feature
and /bug
---
KNOWLEDGE_BASE.md | 2 +-
.../Controllers/SimilarIssueController.php | 17 ++
.../Requests/ListSimilarIssuesRequest.php | 25 +++
app/Providers/AppServiceProvider.php | 8 +
app/Queries/SimilarIssuesQuery.php | 56 ++++++
resources/js/components/commit-composer.tsx | 2 +
resources/js/components/issue-command.tsx | 86 ++++++++-
resources/js/lib/issue-commands.ts | 10 +
routes/web.php | 4 +
.../SimilarIssueControllerTest.php | 177 ++++++++++++++++++
tests/Unit/IssueCommands.test.ts | 22 +++
11 files changed, 407 insertions(+), 2 deletions(-)
create mode 100644 app/Http/Controllers/SimilarIssueController.php
create mode 100644 app/Http/Requests/ListSimilarIssuesRequest.php
create mode 100644 app/Queries/SimilarIssuesQuery.php
create mode 100644 tests/Feature/Controllers/SimilarIssueControllerTest.php
diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md
index 4cf327f296..2da60d4a6d 100644
--- a/KNOWLEDGE_BASE.md
+++ b/KNOWLEDGE_BASE.md
@@ -650,7 +650,7 @@ Sources: [notification pushes](app/Jobs/SendNotificationPush.php), [Remotes push
### Bug reports and feature requests
-Start a fresh commit draft with **`/bug `** or **`/feature `** to switch it into an issue draft. Submitting opens a **public GitHub issue** on `dev-null-sh/dev-null.sh` through /dev/null's GitHub App, crediting you and labelled **bug** or **enhancement**, rather than posting a normal commit. The issue includes your browser and screen details (browser, OS, viewport, pixel ratio, language, color scheme, and the current page) in a collapsed Environment section. The composer offers command suggestions and a way to cancel back to a commit. Issue drafts are text-only and accept 3–4,000 characters.
+Start a fresh commit draft with **`/bug `** or **`/feature `** to switch it into an issue draft. Submitting opens a **public GitHub issue** on `dev-null-sh/dev-null.sh` through /dev/null's GitHub App, crediting you and labelled **bug** or **enhancement**, rather than posting a normal commit. The issue includes your browser and screen details (browser, OS, viewport, pixel ratio, language, color scheme, and the current page) in a collapsed Environment section. The composer offers command suggestions and a way to cancel back to a commit. While you write the title, up to three open issues with similar titles appear beneath the draft, linking to GitHub, so you can add to one that already exists instead of opening a duplicate. Only a few words of the title are searched on GitHub, without your name. Issue drafts are text-only and accept 3–4,000 characters.
Empty issue drafts show a short Markdown template: steps and expected versus actual behavior for bugs, or the problem and proposal for features. The first top-level `# Heading` becomes the issue title and is removed from the body; the remaining Markdown is preserved. Without a heading, the first line is used as the title and the full draft remains in the body.
diff --git a/app/Http/Controllers/SimilarIssueController.php b/app/Http/Controllers/SimilarIssueController.php
new file mode 100644
index 0000000000..765433f9c7
--- /dev/null
+++ b/app/Http/Controllers/SimilarIssueController.php
@@ -0,0 +1,17 @@
+json(['issues' => $issues->get($request->string('q')->value())]);
+ }
+}
diff --git a/app/Http/Requests/ListSimilarIssuesRequest.php b/app/Http/Requests/ListSimilarIssuesRequest.php
new file mode 100644
index 0000000000..854825f83b
--- /dev/null
+++ b/app/Http/Requests/ListSimilarIssuesRequest.php
@@ -0,0 +1,25 @@
+>
+ */
+ public function rules(): array
+ {
+ return [
+ 'q' => ['required', 'string', 'max:256'],
+ ];
+ }
+}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 179d2b4be6..b2ccb85aab 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -257,6 +257,14 @@ private function bootRateLimitingDefaults(): void
Limit::perDay(300)->by('day:'.$this->userId($request)),
]);
+ // GitHub allows the app about 30 searches a minute in all, shared with repository insights, so one person typing an
+ // issue title must not spend it for everyone...
+ RateLimiter::for('similar-issues', fn (Request $request): array => [
+ Limit::perMinute(10)->by($this->userId($request)),
+ Limit::perDay(100)->by('day:'.$this->userId($request)),
+ Limit::perMinute(20)->by('app'),
+ ]);
+
// Every commit search pays for an embedding and a relevance verdict, so it gets a budget of its own...
RateLimiter::for('search', fn (Request $request): Limit => Limit::perMinute(15)
->by($this->userId($request))
diff --git a/app/Queries/SimilarIssuesQuery.php b/app/Queries/SimilarIssuesQuery.php
new file mode 100644
index 0000000000..ce8045032a
--- /dev/null
+++ b/app/Queries/SimilarIssuesQuery.php
@@ -0,0 +1,56 @@
+
+ */
+ public function get(string $title): array
+ {
+ $words = Str::of($title)->lower()->matchAll('/[\p{L}\p{N}]{3,}/u')->diff(self::COMMON_WORDS)->unique()->take(5);
+
+ if ($words->isEmpty()) {
+ return [];
+ }
+
+ $query = 'repo:'.config()->string('services.github.repository').' is:issue is:open in:title '.$words->implode(' OR ');
+
+ try {
+ /** @var list */
+ return Cache::remember('similar-issues:'.hash('xxh128', $query), 300, fn (): array => collect($this->github->searchIssues($query, 3, null)['items'])
+ ->mapInto(Fluent::class)
+ ->map(fn (Fluent $issue): array => [
+ 'number' => $issue->integer('number'),
+ 'title' => $issue->string('title')->value(),
+ 'url' => $issue->string('html_url')->value(),
+ ])
+ ->all());
+ } catch (HttpClientException) {
+ return [];
+ }
+ }
+}
diff --git a/resources/js/components/commit-composer.tsx b/resources/js/components/commit-composer.tsx
index 1fd8cc5d82..881a0bd9ed 100644
--- a/resources/js/components/commit-composer.tsx
+++ b/resources/js/components/commit-composer.tsx
@@ -32,6 +32,7 @@ import {
IssueCommandBadge,
IssueCommandHint,
IssueCommandSuggestions,
+ SimilarIssues,
useIssueCommand,
} from '@/components/issue-command';
import { LinkCardPicker } from '@/components/link-card-picker';
@@ -375,6 +376,7 @@ function CommitComposerBody({
Posted to this guild, not your profile log.
)}
+ {isIssue && }
{issue.hint && (
);
}
+
+type SimilarIssue = { number: number; title: string; url: string };
+
+/**
+ * The open issues whose titles share words with the draft's, shown while it is written, so its author can join an
+ * existing issue instead of opening a duplicate. The last matches stay until the next ones arrive, and the slot keeps
+ * the height of three, so matches arriving after a pause never move the page.
+ */
+export function SimilarIssues({ body }: { body: string }) {
+ const title = issueTitle(body);
+ const [issues, setIssues] = useState([]);
+ const matches = title.length < 3 ? [] : issues;
+
+ useEffect(() => {
+ if (title.length < 3) {
+ return;
+ }
+
+ const controller = new AbortController();
+ const timeout = setTimeout(() => {
+ void fetch(similarIssues.url({ query: { q: title } }), {
+ headers: { Accept: 'application/json' },
+ signal: controller.signal,
+ })
+ .then(async (response) => {
+ const data = response.ok
+ ? ((await response.json()) as {
+ issues: SimilarIssue[];
+ })
+ : { issues: [] };
+
+ if (!controller.signal.aborted) {
+ setIssues(data.issues);
+ }
+ })
+ .catch(() => undefined);
+ }, 500);
+
+ return () => {
+ clearTimeout(timeout);
+ controller.abort();
+ };
+ }, [title]);
+
+ return (
+
+
+ {matches.length > 0
+ ? 'Already asked? Similar open issues:'
+ : 'Similar open issues show here as you write the title.'}
+
+
+
+ );
+}
diff --git a/resources/js/lib/issue-commands.ts b/resources/js/lib/issue-commands.ts
index 81947133be..d21af5062e 100644
--- a/resources/js/lib/issue-commands.ts
+++ b/resources/js/lib/issue-commands.ts
@@ -66,3 +66,13 @@ export function hintedCommand(body: string): IssueCommand | null {
return issueCommands.find((command) => command.kind === kind) ?? null;
}
+
+/**
+ * The title an issue draft opens with, as the server picks it: its first top-level heading, or else its first line, cut
+ * to GitHub's 256 characters.
+ */
+export function issueTitle(body: string): string {
+ const heading = /^ {0,3}# +(.+?)(?: +#+)? *$/m.exec(body);
+
+ return (heading ? heading[1] : body.split('\n', 1)[0]).trim().slice(0, 256);
+}
diff --git a/routes/web.php b/routes/web.php
index e4b8c6961f..9db8b97536 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -135,6 +135,7 @@
use App\Http\Controllers\ScheduledCommitSubmissionController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\SessionController;
+use App\Http\Controllers\SimilarIssueController;
use App\Http\Controllers\SiteActivityController;
use App\Http\Controllers\SitemapController;
use App\Http\Controllers\StarredCommitController;
@@ -686,6 +687,9 @@
Route::get('search/issues', [IssueSuggestionController::class, 'index'])
->middleware('throttle:issue-suggestions')
->name('issue-suggestion.index');
+ Route::get('search/similar-issues', [SimilarIssueController::class, 'index'])
+ ->middleware('throttle:similar-issues')
+ ->name('similar-issue.index');
// User Profile...
Route::get('settings', fn () => to_route('user-profile.edit'));
diff --git a/tests/Feature/Controllers/SimilarIssueControllerTest.php b/tests/Feature/Controllers/SimilarIssueControllerTest.php
new file mode 100644
index 0000000000..3b2e49adec
--- /dev/null
+++ b/tests/Feature/Controllers/SimilarIssueControllerTest.php
@@ -0,0 +1,177 @@
+ false, 'total' => 2, 'items' => [
+ ['number' => 1539, 'title' => '[Feature] Add dark theme to android', 'html_url' => 'https://github.com/dev-null-sh/dev-null.sh/issues/1539', 'state' => 'open'],
+ ['number' => 1581, 'title' => 'Explore mode', 'html_url' => 'https://github.com/dev-null-sh/dev-null.sh/issues/1581', 'state' => 'open'],
+ ]];
+}
+
+it('finds the open issues whose titles share words with the draft, best match first', function (): void {
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')
+ ->with('repo:dev-null-sh/dev-null.sh is:issue is:open in:title dark OR mode OR android', 3, null)
+ ->once()
+ ->andReturn(similarIssueResults());
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => 'Dark mode on Android']))
+ ->assertOk()
+ ->assertExactJson(['issues' => [
+ ['number' => 1539, 'title' => '[Feature] Add dark theme to android', 'url' => 'https://github.com/dev-null-sh/dev-null.sh/issues/1539'],
+ ['number' => 1581, 'title' => 'Explore mode', 'url' => 'https://github.com/dev-null-sh/dev-null.sh/issues/1581'],
+ ]]);
+});
+
+it('searches the configured repository', function (): void {
+ config(['services.github.repository' => 'example/upstream']);
+
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')
+ ->with('repo:example/upstream is:issue is:open in:title dark OR mode', 3, null)
+ ->once()
+ ->andReturn(['incomplete' => false, 'total' => 0, 'items' => []]);
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => 'Dark mode']))
+ ->assertExactJson(['issues' => []]);
+});
+
+it('searches by the first five words that are not short or common, once each', function (): void {
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')
+ ->with('repo:dev-null-sh/dev-null.sh is:issue is:open in:title heic OR photos OR upload OR iphone OR mac', 3, null)
+ ->once()
+ ->andReturn(['incomplete' => false, 'total' => 0, 'items' => []]);
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => 'Feature: please add HEIC photos upload from the iPhone and the Mac, photos too, and videos']))
+ ->assertOk();
+});
+
+it('asks GitHub nothing for a title without a word to search', function (string $title): void {
+ $this->mock(GitHubProvider::class)->shouldNotReceive('searchIssues');
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => $title]))
+ ->assertOk()
+ ->assertExactJson(['issues' => []]);
+})->with(['Bug', 'Add a UI', '!!!', 'the and for']);
+
+it('asks GitHub once for the same search until it expires', function (): void {
+ $github = $this->mock(GitHubProvider::class);
+ $github->shouldReceive('searchIssues')->andReturn(similarIssueResults(), ['incomplete' => false, 'total' => 0, 'items' => []]);
+
+ $this->actingAs(User::factory()->create());
+
+ foreach (range(1, 2) as $attempt) {
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode on Android']))->assertJsonCount(2, 'issues');
+ }
+
+ $github->shouldHaveReceived('searchIssues')->once();
+
+ $this->travel(6)->minutes();
+
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode on Android']))->assertExactJson(['issues' => []]);
+});
+
+it('finds nothing when GitHub cannot search', function (Throwable $exception): void {
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')->andThrow($exception);
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => 'Dark mode']))
+ ->assertOk()
+ ->assertExactJson(['issues' => []]);
+})->with([
+ 'forbidden' => fn (): RequestException => new RequestException(new Response(new Psr7Response(403))),
+ 'rate limited' => fn (): RequestException => new RequestException(new Response(new Psr7Response(429))),
+ 'server error' => fn (): RequestException => new RequestException(new Response(new Psr7Response(500))),
+ 'unreachable' => fn (): ConnectionException => new ConnectionException('timed out'),
+]);
+
+it('requires authentication to find similar issues', function (): void {
+ $this->mock(GitHubProvider::class)->shouldNotReceive('searchIssues');
+
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode']))->assertUnauthorized();
+});
+
+it('rejects a missing, too long or malformed title before contacting GitHub', function (mixed $title): void {
+ $this->mock(GitHubProvider::class)->shouldNotReceive('searchIssues');
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => $title]))
+ ->assertUnprocessable()
+ ->assertJsonValidationErrors('q');
+})->with([null, '', str_repeat('a', 257), [['Dark mode']]]);
+
+it('limits how many searches each person may run in a minute', function (): void {
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')->andReturn(['incomplete' => false, 'total' => 0, 'items' => []]);
+
+ $this->actingAs(User::factory()->create());
+
+ foreach (range(1, 10) as $attempt) {
+ $this->getJson(route('similar-issue.index', ['q' => "Dark mode {$attempt}"]))->assertOk();
+ }
+
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode']))->assertTooManyRequests();
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => 'Dark mode']))
+ ->assertOk();
+});
+
+it('limits how many searches everyone together may run in a minute', function (): void {
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')->andReturn(['incomplete' => false, 'total' => 0, 'items' => []]);
+
+ foreach (range(1, 2) as $person) {
+ $this->actingAs(User::factory()->create());
+
+ foreach (range(1, 10) as $attempt) {
+ $this->getJson(route('similar-issue.index', ['q' => "Dark mode {$person} {$attempt}"]))->assertOk();
+ }
+ }
+
+ $this->actingAs(User::factory()->create())
+ ->getJson(route('similar-issue.index', ['q' => 'Dark mode']))
+ ->assertTooManyRequests();
+
+ $this->travel(1)->minute();
+
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode']))->assertOk();
+});
+
+it('limits how many searches each person may run in a day', function (): void {
+ $this->mock(GitHubProvider::class)->shouldReceive('searchIssues')->andReturn(['incomplete' => false, 'total' => 0, 'items' => []]);
+
+ $this->actingAs(User::factory()->create());
+
+ foreach (range(1, 100) as $attempt) {
+ if ($attempt % 10 === 0) {
+ $this->travel(1)->minute();
+ }
+
+ $this->getJson(route('similar-issue.index', ['q' => "Dark mode {$attempt}"]))->assertOk();
+ }
+
+ $this->travel(1)->minute();
+
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode']))->assertTooManyRequests();
+});
+
+it('asks GitHub again after a search it could not run', function (): void {
+ $github = $this->mock(GitHubProvider::class);
+ $github->shouldReceive('searchIssues')->andThrow(new ConnectionException('timed out'))->once()->ordered();
+ $github->shouldReceive('searchIssues')->andReturn(similarIssueResults())->once()->ordered();
+
+ $this->actingAs(User::factory()->create());
+
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode on Android']))->assertExactJson(['issues' => []]);
+ $this->getJson(route('similar-issue.index', ['q' => 'Dark mode on Android']))->assertJsonCount(2, 'issues');
+});
diff --git a/tests/Unit/IssueCommands.test.ts b/tests/Unit/IssueCommands.test.ts
index 82f553b67f..9f8ce453bd 100644
--- a/tests/Unit/IssueCommands.test.ts
+++ b/tests/Unit/IssueCommands.test.ts
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
import { test } from 'node:test';
import {
hintedCommand,
+ issueTitle,
suggestedCommands,
typedCommand,
} from '../../resources/js/lib/issue-commands.ts';
@@ -46,3 +47,24 @@ test('hints the command a plain draft mentions', () => {
assert.equal(name('/bug already a command'), null);
assert.equal(name('Shipped the parser'), null);
});
+
+test('titles an issue draft as the server does: its first heading, or else its first line', () => {
+ assert.equal(
+ issueTitle('# Dark mode\n\n## Problem\nToo bright'),
+ 'Dark mode',
+ );
+ assert.equal(
+ issueTitle('Some context first\n# Dark mode #\nToo bright'),
+ 'Dark mode',
+ );
+ assert.equal(
+ issueTitle('Dark mode on Android\n## Problem'),
+ 'Dark mode on Android',
+ );
+ assert.equal(issueTitle('#123 is broken'), '#123 is broken');
+ assert.equal(issueTitle('\nDark mode'), '');
+});
+
+test('cuts the title of an issue draft to the 256 characters GitHub keeps', () => {
+ assert.equal(issueTitle('a'.repeat(4000)).length, 256);
+});
From 27586154d172ed74721ed4ef91ed54c629b17535 Mon Sep 17 00:00:00 2001
From: Rui Maduro
Date: Sat, 28 Nov 2026 15:36:49 +0000
Subject: [PATCH 2/2] fix: clear similar issues after a failed search and skip
headings in fenced code
---
resources/js/components/issue-command.tsx | 6 +++++-
resources/js/lib/issue-commands.ts | 26 +++++++++++++++++++----
tests/Unit/IssueCommands.test.ts | 14 ++++++++++++
3 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/resources/js/components/issue-command.tsx b/resources/js/components/issue-command.tsx
index 7043103820..af5f0e3f66 100644
--- a/resources/js/components/issue-command.tsx
+++ b/resources/js/components/issue-command.tsx
@@ -388,7 +388,11 @@ export function SimilarIssues({ body }: { body: string }) {
setIssues(data.issues);
}
})
- .catch(() => undefined);
+ .catch(() => {
+ if (!controller.signal.aborted) {
+ setIssues([]);
+ }
+ });
}, 500);
return () => {
diff --git a/resources/js/lib/issue-commands.ts b/resources/js/lib/issue-commands.ts
index d21af5062e..842ac16e73 100644
--- a/resources/js/lib/issue-commands.ts
+++ b/resources/js/lib/issue-commands.ts
@@ -68,11 +68,29 @@ export function hintedCommand(body: string): IssueCommand | null {
}
/**
- * The title an issue draft opens with, as the server picks it: its first top-level heading, or else its first line, cut
- * to GitHub's 256 characters.
+ * The title an issue draft opens with, as the server picks it: its first top-level heading outside fenced code, or else
+ * its first line, cut to GitHub's 256 characters.
*/
export function issueTitle(body: string): string {
- const heading = /^ {0,3}# +(.+?)(?: +#+)? *$/m.exec(body);
+ let fence: string | null = null;
- return (heading ? heading[1] : body.split('\n', 1)[0]).trim().slice(0, 256);
+ for (const line of body.split('\n')) {
+ const marker = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1];
+
+ if (fence !== null) {
+ if (marker?.[0] === fence[0] && marker.length >= fence.length) {
+ fence = null;
+ }
+ } else if (marker !== undefined) {
+ fence = marker;
+ } else {
+ const heading = /^ {0,3}# +(.+?)(?: +#+)? *$/.exec(line);
+
+ if (heading) {
+ return heading[1].trim().slice(0, 256);
+ }
+ }
+ }
+
+ return body.split('\n', 1)[0].trim().slice(0, 256);
}
diff --git a/tests/Unit/IssueCommands.test.ts b/tests/Unit/IssueCommands.test.ts
index 9f8ce453bd..281ac0a932 100644
--- a/tests/Unit/IssueCommands.test.ts
+++ b/tests/Unit/IssueCommands.test.ts
@@ -65,6 +65,20 @@ test('titles an issue draft as the server does: its first heading, or else its f
assert.equal(issueTitle('\nDark mode'), '');
});
+test('skips heading-like lines inside fenced code, as the server does', () => {
+ assert.equal(
+ issueTitle(
+ 'Android crash\n\n```\n# install dependencies\n```\n\n# Camera upload fails',
+ ),
+ 'Camera upload fails',
+ );
+ assert.equal(
+ issueTitle('~~~~\n# not a title\n~~~\n# still code\n~~~~\n# Title'),
+ 'Title',
+ );
+ assert.equal(issueTitle('Steps\n```\n# never closed'), 'Steps');
+});
+
test('cuts the title of an issue draft to the 256 characters GitHub keeps', () => {
assert.equal(issueTitle('a'.repeat(4000)).length, 256);
});