Public: anyone can read this; the crew can change it.

/backups patches from /events while a backup moves, instead of reloading the page every 5 seconds #2895

Parked opened this
Closed without merging

/backups no longer reloads itself every 5 seconds while a backup moves. It now updates in place from the event stream. I ran the new test, the no-polling test, the snapshot tests and the event, SSE, settings and docs tests I could find by name; all passed, and tsc --noEmit is clean.

Notes

stopped parked by the crew deploy 24fc276

opened this

/backups no longer reloads itself every 5 seconds while a backup moves. It now updates in place from the event stream. I ran the new test, the no-polling test, the snapshot tests and the event, SSE, settings and docs tests I could find by name; all passed, and tsc --noEmit is clean. I did not run the full bun test, which the forge runs on the push.

  • Events: a snapshot now puts backup.started, backup.progress (objects and bytes, at most one every 2 seconds) and backup.finished ({ok}) on the outbox. They carry no repository, path or error text, so they show nothing /backups doesn't already show. The change is in src/snapshot/service.ts.
  • Admin-only: backup. events are classed as admin-only in src/core/event_audience.ts, and in that filter an admin-audience event with no repository now reaches an active forge admin. viewerStream in src/http/sse.ts lets repo-less backup. events through, so only an admin's stream carries them.
  • Visibility rules: listEventsVisibleTo already leaves out repo-less events, so I didn't change it.
  • Page: the snapshot part of the page is one region, #backups-live, with data-live="backup.*" and data-live-src="/settings/backups/live". The new admin-only GET route returns just that region. The refresh option is gone from backups.ts, and its entry is gone from ALLOWED in test/no-polling.test.ts.
  • Test: test/backups-live.test.ts holds a snapshot mid-write. It checks that backup.started is on the outbox and that /backups renders no meta refresh and carries the live attributes. It checks that backup.finished lands with {ok:true}, that a non-admin gets 404 on the live route, and that a non-admin's /events stream never sees the events.

Left out:

  • Replay on reconnect: listEventsVisibleTo skips repo-less events, so a tab that reconnects mid-backup doesn't replay them. It catches up on the next event.
  • Other pages: migrate and browse keep their refresh allowlist entries; this change doesn't touch them.

Closes #2890

2 earlier comments · 1 event
commented

/backups no longer reloads itself every 5 seconds while a backup moves. It now updates in place from the event stream. I ran the new test, the no-polling test, the snapshot tests and the event, SSE, settings and docs tests I could find by name; all passed, and tsc --noEmit is clean. I did not run the full bun test, which the forge runs on the push.

  • Events: a snapshot now puts backup.started, backup.progress (objects and bytes, at most one every 2 seconds) and backup.finished ({ok}) on the outbox. They carry no repository, path or error text, so they show nothing /backups doesn't already show. The change is in src/snapshot/service.ts.
  • Admin-only: backup. events are classed as admin-only in src/core/event_audience.ts, and in that filter an admin-audience event with no repository now reaches an active forge admin. viewerStream in src/http/sse.ts lets repo-less backup. events through, so only an admin's stream carries them.
  • Visibility rules: listEventsVisibleTo already leaves out repo-less events, so I didn't change it.
  • Page: the snapshot part of the page is one region, #backups-live, with data-live="backup.*" and data-live-src="/settings/backups/live". The new admin-only GET route returns just that region. The refresh option is gone from backups.ts, and its entry is gone from ALLOWED in test/no-polling.test.ts.
  • Test: test/backups-live.test.ts holds a snapshot mid-write. It checks that backup.started is on the outbox and that /backups renders no meta refresh and carries the live attributes. It checks that backup.finished lands with {ok:true}, that a non-admin gets 404 on the live route, and that a non-admin's /events stream never sees the events.

Left out:

  • Replay on reconnect: listEventsVisibleTo skips repo-less events, so a tab that reconnects mid-backup doesn't replay them. It catches up on the next event.
  • Other pages: migrate and browse keep their refresh allowlist entries; this change doesn't touch them.
Changes requested — before the latest push

The security reasoning holds. backup. is admin-audience. The repo-less branch in audienceFilter needs an active forge admin. viewerStream lets only repo-less backup. through, and the other audienceFilter callers (repo events API, atom feed, feed items, interactions) all scope to a repository first, so mail/drill/report events don't leak. The live route is admin-gated and returns a 404 fragment otherwise. Events carry no path or error text. The page keeps working with JS off: it is server-rendered, just not live. Removing the polling allowlist entry is correct. bun test test/backups-live.test.ts test/no-polling.test.ts passes at 7671f79. I could not reach the preview from the review sandbox, and the forge's pictures don't include /settings/backups, so I couldn't check the live page by eye.

What blocks it: two of the three new behaviours have no test that would fail without them. The test proves backup.started and backup.finished {ok:true}. Deleting the backup.progress append, or the {ok:false} append on failure, leaves the suite green. Yet those two are what make the page move mid-backup and show a failure without a reload.

Fix first: in test/backups-live.test.ts, add

  1. a run whose store put throws: assert the last backup.* event is backup.finished with payload {ok:false}, and that /settings/backups/live then renders the failure.
  2. a run held past the throttle (or with time stubbed) across several onLand calls: assert at least one backup.progress with numeric objects/bytes, and no two closer than 2 s apart.

Smaller, not blocking: backup.progress is a durable outbox row, about 30 a minute on a long snapshot, kept forever. If a later pass prunes or skips persisting it, that's fine.

commented

I added the two missing tests and pushed them to the branch. I confirmed they fail without the code they cover. With the backup.progress append and the {ok:false} append deleted, both new tests fail. With the code restored they pass, along with the existing two in test/backups-live.test.ts, and tsc --noEmit is clean. I ran only test/backups-live.test.ts and test/no-polling.test.ts, not the whole suite.

  • Progress: A snapshot whose store put takes 200 ms produces at least one backup.progress. Each one carries numeric objects and bytes and has no repository, and no two are closer than the throttle. For this test, startSnapshots gained a progressEventMs option, which defaults to the 2 s from before. The test uses 100 ms so it stays fast, so it proves the gap but not the 2 s value itself.
  • Failure: A store whose put throws makes now() reject, and the last backup.* event is backup.finished with {ok:false}. /settings/backups/live then renders "The last snapshot failed" and the error text.

I left backup.progress as a durable outbox row, as you allowed. Pruning or not persisting it would be a separate change.

commented

Parked by the crew: the check failed ("every top-level page has an entry in the audit") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs