Stop SIGKILLing the provisioning browser, and say why auto-sync failed
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
release-apk / release (APK) (push) Waiting to run

Two fixes found while verifying the desktop actually reaches Firebase rather
than trusting an exit code.

`--virtual-time-budget` makes headless Chrome SIGKILL itself when the budget
expires: the run reported exit -9 and could cut a sync short mid-flight. It
now gets a real wall-clock window and is closed cleanly, so the exit code
means what it says.

`_autoSync` caught `on Exception` and ignored it entirely — the exact
silent-failure shape screen-locker's CLAUDE.md bans ("an invisible log is a
silent failure with extra steps"). It now catches broadly and logs at error
level with the stack trace, so the next failure is diagnosable instead of
looking identical to "nothing to sync". `--enable-logging=stderr` on the
provisioning run surfaces that in the terminal that started it.

Verified end to end, which is what settled it: the desktop appears in the
RTDB as c891b813 with all four documents and a revs entry, and its food_log
holds 359 records — identical to the PC daemon's, 0 missing either way. An
earlier check read as "not pushing" because it ran before the push landed.

522 tests, analyzer and pre-commit clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177xwzcpfpWG2qca8Mr39q9
This commit is contained in:
Krzysztof Rudnicki 2026-08-09 22:15:34 +02:00
parent c093c22ae0
commit d388f90ed4
2 changed files with 22 additions and 10 deletions

View File

@ -104,14 +104,17 @@ Future<bool> _provisionSyncAccount(String home, int port) async {
'--disable-gpu',
'--user-data-dir=${_profileDir(home)}',
'--virtual-time-budget=45000',
'--dump-dom',
// Surface the page's own log() output, so a failure inside the app
// is visible in the terminal that started the provisioning run.
'--enable-logging=stderr',
'http://localhost:$port',
]);
final code = await process.exitCode;
if (code != 0) {
stderr.writeln('Headless provisioning run exited with $code.');
return false;
}
// No --virtual-time-budget: it makes Chrome SIGKILL itself when the budget
// expires, which both reads as a failure and can cut the sync short. Give
// the page a real window of wall-clock time instead, then close it.
await Future<void>.delayed(const Duration(seconds: 40));
process.kill();
await process.exitCode;
stdout.writeln(
'Provisioning run complete. Launch normally to confirm it is connected.',
);

View File

@ -2,8 +2,9 @@
/// screen: "I can open the diet app on my phone and fill meal I ate."
library;
import 'dart:async';
import 'dart:async';
import 'dart:developer';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:diet_guard_app/models/food_entry.dart';
import 'package:diet_guard_app/models/food_suggestion.dart';
@ -136,9 +137,17 @@ class _LogMealScreenState extends State<LogMealScreen>
}
if (!mounted) return;
await _refreshSlots();
} on Exception {
// Best-effort: ignore (offline, transient GitHub errors, unmocked
// platform channels under test, etc.).
} on Object catch (error, stackTrace) {
// Best-effort, but never silent: this swallowed the reason a desktop
// install could not publish at all, which looked identical to "nothing
// to sync". Offline and unmocked-platform-channel-under-test both land
// here too, so it stays non-fatal -- it just says why now.
log(
'diet_guard auto-sync failed',
level: 1000,
error: error,
stackTrace: stackTrace,
);
} finally {
_autoSyncing = false;
}