Skip to content

Persistent service worker logs#254

Open
expede wants to merge 1 commit into
studiofrom
persist-logs
Open

Persistent service worker logs#254
expede wants to merge 1 commit into
studiofrom
persist-logs

Conversation

@expede

@expede expede commented Mar 30, 2026

Copy link
Copy Markdown
Member

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.slog in the SW, but it has some convenience functions like printLogs(howManyLines).

Because the SW doesn't have access to localStorage, it uses IDB

Here's a screenshot of two of the interfaces that you get in the main thread:

Screenshot 2026-03-30 at 11 48 38

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.

@netlify

netlify Bot commented Mar 30, 2026

Copy link
Copy Markdown

Deploy Preview for gaios-sgai ready!

Name Link
🔨 Latest commit e83ab88
🔍 Latest deploy log https://app.netlify.com/projects/gaios-sgai/deploys/69cacdec573dd1000864bfbb
😎 Deploy Preview https://deploy-preview-254--gaios-sgai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Mar 30, 2026

Copy link
Copy Markdown

Deploy Preview for tinypatchwork ready!

Name Link
🔨 Latest commit e83ab88
🔍 Latest deploy log https://app.netlify.com/projects/tinypatchwork/deploys/69cacdecb7a4260008f180c6
😎 Deploy Preview https://deploy-preview-254--tinypatchwork.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Mar 30, 2026

Copy link
Copy Markdown

Deploy Preview for tenfoldinkandswitch ready!

Name Link
🔨 Latest commit e83ab88
🔍 Latest deploy log https://app.netlify.com/projects/tenfoldinkandswitch/deploys/69cacdec946c5500086e6346
😎 Deploy Preview https://deploy-preview-254--tenfoldinkandswitch.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@expede
expede marked this pull request as ready for review March 30, 2026 18:52
Copilot AI review requested due to automatic review settings March 30, 2026 18:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and SwLogReader (reader) with tail/export/clear helpers backed by a capped IDB store.
  • Integrates the logger into the bootloader service worker and exposes self.slog plus console helpers (printLogs, tailLogs, etc.).
  • Exposes equivalent SW log-reading helpers on window.patchwork.sw and 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.

Comment thread core/bootloader/src/sw-logger.ts
Comment thread core/bootloader/src/service-worker.ts Outdated
Comment thread core/bootloader/src/service-worker.ts
Comment thread core/bootloader/src/service-worker.ts Outdated
Comment thread core/bootloader/src/sw-logger.ts Outdated
Comment thread sites/tiny-patchwork/src/main.ts
Comment thread core/bootloader/src/sw-logger.ts Outdated
Comment thread core/bootloader/src/sw-logger.ts Outdated
@expede
expede requested review from chee, Copilot and paulsonnentag and removed request for chee, Copilot and paulsonnentag March 30, 2026 19:24
@expede
expede requested a review from chee March 30, 2026 19:25
@chee
chee force-pushed the main branch 2 times, most recently from 5397807 to 6542dc4 Compare June 30, 2026 19:19
@chee
chee changed the base branch from main to studio July 18, 2026 08:07
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