Persistent service worker logs#254
Open
expede wants to merge 1 commit into
Open
Conversation
✅ Deploy Preview for gaios-sgai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for tinypatchwork ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for tenfoldinkandswitch ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a persistent (IndexedDB-backed) service worker log cache and exposes read/query helpers from both the SW inspector console and the main thread, enabling post-mortem debugging of SW behavior across restarts.
Changes:
- Introduces
SwLogger(writer) andSwLogReader(reader) with tail/export/clear helpers backed by a capped IDB store. - Integrates the logger into the bootloader service worker and exposes
self.slogplus console helpers (printLogs,tailLogs, etc.). - Exposes equivalent SW log-reading helpers on
window.patchwork.swand adds a package export for./sw-logger.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| sites/tiny-patchwork/src/main.ts | Adds window.patchwork.sw helpers that read/export/clear SW logs from the main thread. |
| core/bootloader/src/sw-logger.ts | Implements the persistent IDB-backed logger, pruning logic, and a read-only accessor. |
| core/bootloader/src/service-worker.ts | Wires up the logger in the SW lifetime and replaces/augments some console logging with persistent logging. |
| core/bootloader/package.json | Exposes the new ./sw-logger entrypoint via exports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
expede
requested review from
chee,
Copilot and
paulsonnentag
and removed request for
chee,
Copilot and
paulsonnentag
March 30, 2026 19:24
chee
force-pushed
the
main
branch
2 times, most recently
from
June 30, 2026 19:19
5397807 to
6542dc4
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds a fixed-size (50k) persistent log store for the service worker. This survives crashes, restarts, etc. It is available directly as
self.slogin the SW, but it has some convenience functions likeprintLogs(howManyLines).Because the SW doesn't have access to
localStorage, it uses IDBHere's a screenshot of two of the interfaces that you get in the main thread:
Was this code primarily machine-generated? Yes. Yes it was.
Caveats
This strategy depends on flushing every 1s or (max) 128 messages. If the SW crashes/sleeps/etc, you will miss up to the last 128 logs or 1 second of logs, whichever happened most recently.