Close the provisioning browser cleanly instead of letting it SIGKILL

--virtual-time-budget makes headless Chrome SIGKILL itself when the budget
expires: the run exits -9, which reads as a failure, and it can cut a sync
short mid-flight. Found while debugging diet-guard's provisioning; todo
carried the same flag.

The page now gets a real wall-clock window and is closed deliberately, so a
non-zero exit means something actually went wrong. --enable-logging=stderr
surfaces the page's own log() output in the terminal that started the run,
which is what makes an in-app failure visible at all.

Re-verified after the change: provisioning exits 0 and todo-sync still holds
the desktop (b58facc7) alongside the live device.

256 tests, analyzer 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:18:24 +02:00
parent 042d68b237
commit 59899f7eba

View File

@ -181,15 +181,17 @@ Future<bool> _provisionSyncAccount(String home) async {
'--headless=new',
'--disable-gpu',
'--user-data-dir=${_profileDir(home)}',
'--virtual-time-budget=15000',
'--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 (exit -9) and can cut the sync
// short. Give the page a real window of wall-clock time, then close it.
await Future<void>.delayed(const Duration(seconds: 30));
process.kill();
await process.exitCode;
stdout.writeln(
'Provisioning run complete. Launch normally to confirm it is connected.',
);