Repository navigation
fix(whatsapp): write creds.json atomically - #63577
Conversation
Greptile SummaryThis PR replaces the in-place WhatsApp Confidence Score: 5/5Safe to merge — the atomic write logic is correct and the only findings are minor style issues. All findings are P2 (redundant chmod, duplicate log warnings on failure). The core fix — temp-file + rename atomicity, same-filesystem guarantee, queue preservation, and 0o600 permissions — is implemented correctly. Tests cover the unit path, the serialization invariant, and the multi-authDir case. No files require special attention.
|
| } catch (err) { | ||
| try { | ||
| await fs.rm(tempPath, { force: true }); | ||
| } catch { | ||
| // best-effort cleanup | ||
| } | ||
| logger.warn({ error: String(err) }, "failed atomic WhatsApp creds write"); | ||
| throw err; | ||
| } |
There was a problem hiding this comment.
Duplicate log entries on failure
When the write fails, writeCredsJsonAtomically logs "failed atomic WhatsApp creds write" then rethrows, and safeSaveCreds catches that same error and logs "failed saving WhatsApp creds". Every creds-write failure produces two distinct warnings for one root cause, which can look like two separate failures in production logs.
Consider removing the logger.warn here and letting safeSaveCreds own the single error log, or suppress the outer one.
| } catch (err) { | |
| try { | |
| await fs.rm(tempPath, { force: true }); | |
| } catch { | |
| // best-effort cleanup | |
| } | |
| logger.warn({ error: String(err) }, "failed atomic WhatsApp creds write"); | |
| throw err; | |
| } | |
| } catch (err) { | |
| try { | |
| await fs.rm(tempPath, { force: true }); | |
| } catch { | |
| // best-effort cleanup | |
| } | |
| throw err; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/whatsapp/src/session.ts
Line: 58-66
Comment:
**Duplicate log entries on failure**
When the write fails, `writeCredsJsonAtomically` logs `"failed atomic WhatsApp creds write"` then rethrows, and `safeSaveCreds` catches that same error and logs `"failed saving WhatsApp creds"`. Every creds-write failure produces two distinct warnings for one root cause, which can look like two separate failures in production logs.
Consider removing the `logger.warn` here and letting `safeSaveCreds` own the single error log, or suppress the outer one.
```suggestion
} catch (err) {
try {
await fs.rm(tempPath, { force: true });
} catch {
// best-effort cleanup
}
throw err;
}
```
How can I resolve this? If you propose a fix, please make it concise.f4e708d to
70ef5b3
Compare
|
Merged via squash.
Thanks @OwenYWT! |
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Merged via squash. Prepared head SHA: 70ef5b3 Co-authored-by: OwenYWT <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
Summary
Stop WhatsApp web credential updates from rewriting
creds.jsonin-place by switching the queued save path to an atomic temp-file rename.Changes
writeCredsJsonAtomically()helper for WhatsApp auth statecreds.updatepath, but swap the final write to temp-file + renameBufferJSONTest Plan
pnpm --dir /Users/wentao/Desktop/openclaw exec vitest run extensions/whatsapp/src/session.test.tsNODE_OPTIONS=--max-old-space-size=8192 pnpm --dir /Users/wentao/Desktop/openclaw exec tsc --noEmit --pretty false