Repository navigation
[PM-45308] perf(cli): Exit once a command has finished - #23953
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## cli-perf/00-harness #23953 +/- ##
====================================================
Coverage 59.29% 59.29%
====================================================
Files 4698 4699 +1
Lines 148683 148700 +17
Branches 23712 23713 +1
====================================================
+ Hits 88164 88175 +11
- Misses 54357 54364 +7
+ Partials 6162 6161 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Looks like this will solve this ticket: https://bitwarden.atlassian.net/browse/PM-22141 and the associated GH issue #14976 |
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE I reviewed the new |
8a0ede1 to
ae27c97
Compare
dani-garcia
left a comment
There was a problem hiding this comment.
The exit looks like a reasonable solution to me, but the handling of long running commands seems more complicated than it needs to be.
Instead of the LONG_RUNNING_COMMANDS allowlist, could serve stay pending until the server stops? Then every command exits the same way: the action resolves, then the CLI flushes and exits.
// serve.command.ts
/** Resolves when the server stops, so `serve` stays pending while it is serving. */
export function untilStopped(source: EventEmitter, description: string): Promise<Response> {
return new Promise((resolve) => {
source.once("error", (error: Error) =>
resolve(Response.error(`Cannot serve on ${description}: ${error.message}`)),
);
source.once("close", () => resolve(Response.success()));
});
}
// in run(): fd+connected ends with its connection
return await untilStopped(socket, hostname);
// other branches: keep the http.Server that koa's listen() returns
const httpServer = server.listen(port, hostname === "all" ? null : hostname);
httpServer.once("listening", () => {
this.serviceContainer.logService.info("Listening on " + description);
});
return await untilStopped(httpServer, description);// serve.program.ts
const response = await command.run(cmd);
this.processResponse(response);The forced exit also could be problematic if there are any unawaited floating promises. I've found these two which now will might not be done on time:
export.command.ts:89:eventCollectionService.collect(...).import.command.ts:140:syncService.fullSync(true).
|
@dani-garcia Makes sense; updated. I also simply awaited the two floating promises. It seems reasonable in the context to await these. |
harr1424
left a comment
There was a problem hiding this comment.
Changes to Tools Team owned files look good. Thank you for addressing this!
After printing its output, every command left the process idle until leftover timers expired: the desktop IPC discovery timeout and RxJS intervals kept the event loop alive for ~1.7 s per invocation. Exit explicitly after the command's action resolves, except for serve, which keeps running. stdout and stderr are flushed first, since a pipe is asynchronous on macOS and exiting straight away could truncate large output.
Replace the LONG_RUNNING_COMMANDS allowlist. serve now resolves when its server closes or errors, so every command exits the same way: the action resolves, then the CLI flushes and exits. Await the export event collection and the import sync. The forced exit could otherwise cut them short.
An earlier commit overwrote the existing serve.command spec. Restore it and move the untilStopped tests to their own spec.
78a3af5 to
a4008c0
Compare
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-45308
📔 Objective
After printing its output, every command idled until leftover timers expired (the desktop IPC discovery timeout and RxJS intervals), ~1.7 s per invocation. The CLI now exits once the command's action resolves, except
serve, which keeps running. stdout and stderr are flushed first: a pipe is asynchronous on macOS, and exiting straight away could truncate large output such aslist items.Fixes #14976
⏱️ Benchmark
Before = the previous PR in this stack, after = this PR.
bw get item <id>bw get password <id>bw list itemsbw statusProd build (
npm run build:oss:prod) run asnode build/bw.js, Node 25.9.0, Apple M5 Pro. Account with 11,996 items on vault.usdev.bitwarden.pw (data.json ~19 MB), Bitwarden Desktop running. Harnessapps/cli/perf/bench.mjs: 3 interleaved rounds of 1 warmup + 5 runs per command; fastest run per round, median across rounds. Every run's output is checked.