Repository navigation
fix(local): show why the app could not start when the API does not #2438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MODSetter
merged 1 commit into
MODSetter:dev
from
officialasishkumar:feat/show-why-the-api-did-not-start
Nov 14, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
surfsense_local/electron/src/main/startup-failure/describe-startup-failure.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import assert from "node:assert/strict" | ||
| import test from "node:test" | ||
|
|
||
| import { describeStartupFailure } from "./describe-startup-failure.ts" | ||
|
|
||
| test("names why startup failed", () => { | ||
| const { title, detail } = describeStartupFailure( | ||
| new Error("sidecar exited during startup"), | ||
| [] | ||
| ) | ||
|
|
||
| assert.equal(title, "SurfSense could not start") | ||
| assert.match(detail, /^sidecar exited during startup/) | ||
| }) | ||
|
|
||
| test("quotes the end of the API's output, where a failed migration is named", () => { | ||
| const { detail } = describeStartupFailure(new Error("sidecar exited during startup"), [ | ||
| "10:00:00 [api] Traceback (most recent call last):", | ||
| '10:00:00 [api] File "main.py", line 5, in lifespan', | ||
| '10:00:00 [api] File "migrations.py", line 30, in upgrade_to_head', | ||
| '10:00:00 [api] File "migration_snapshot.py", line 36, in snapshot_before_upgrade', | ||
| "10:00:00 [llamacpp] loading model", | ||
| "10:00:00 [api] RuntimeError: could not write a database snapshot to ~/backups/0030-0032.db before migrating: database or disk is full", | ||
| ]) | ||
|
|
||
| assert.match(detail, /RuntimeError: could not write a database snapshot/) | ||
| assert.match(detail, /line 36, in snapshot_before_upgrade/) | ||
| assert.doesNotMatch(detail, /llamacpp|\[api\]/) | ||
| assert.doesNotMatch(detail, /Traceback/) | ||
| }) | ||
|
|
||
| test("says nothing about the API when it wrote nothing", () => { | ||
| const { detail } = describeStartupFailure("boom", ["10:00:00 [llamacpp] hi"]) | ||
|
|
||
| assert.match(detail, /^boom/) | ||
| assert.doesNotMatch(detail, /last output/) | ||
| }) |
28 changes: 28 additions & 0 deletions
28
surfsense_local/electron/src/main/startup-failure/describe-startup-failure.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // A Python traceback ends with the error, so its last lines say what went wrong. | ||
| const API_TAIL_LINES = 3 | ||
|
|
||
| export type StartupFailure = { title: string; detail: string } | ||
|
|
||
| /** | ||
| * What the dialog says when the API did not start: why Electron gave up, and | ||
| * the last of the API's own output, where a refused migration or a full disk | ||
| * is named. `logLines` is the session log, oldest first. | ||
| */ | ||
| export function describeStartupFailure( | ||
| error: unknown, | ||
| logLines: readonly string[] | ||
| ): StartupFailure { | ||
| const reason = error instanceof Error ? error.message : String(error) | ||
| const apiTail = logLines | ||
| .filter((line) => line.includes(" [api] ")) | ||
| .slice(-API_TAIL_LINES) | ||
| .map((line) => line.slice(line.indexOf(" [api] ") + " [api] ".length)) | ||
| const parts = [reason] | ||
| if (apiTail.length > 0) { | ||
| parts.push(`The API's last output:\n${apiTail.join("\n")}`) | ||
| } | ||
| parts.push( | ||
| "Start SurfSense again. If it keeps failing, include this message in a report." | ||
| ) | ||
| return { title: "SurfSense could not start", detail: parts.join("\n\n") } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: MODSetter/SurfSense
Length of output: 4451
Script executed:
Repository: MODSetter/SurfSense
Length of output: 26281
Web query:
Node.js child_process exit close event stdio streams may still be open exit event Node documentationResult:
Script executed:
Repository: MODSetter/SurfSense
Length of output: 12261
Script executed:
Repository: MODSetter/SurfSense
Length of output: 6526
Wait for API output before building the failure dialog.
If the API exits before its output streams finish, the snapshot can omit its final error lines. Wait for bounded output completion on the API-exit path before reading the session log. Keep the shutdown guard and avoid waiting indefinitely.