Skip to content

fix(whatsapp): restore malformed credentials from backup - #99070

Merged
steipete merged 4 commits into
openclaw:mainfrom
LeonidasLux:fix/whatsapp-json-parse-try-catch
Jul 5, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
LeonidasLux:fix/whatsapp-json-parse-try-catch

Conversation

@LeonidasLux

@LeonidasLux LeonidasLux commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A malformed primary WhatsApp credentials file could prevent startup even when the atomic-write backup still contained valid linked-device credentials.

Why This Change Was Made

The repaired branch validates credential JSON at the auth-store owner boundary. When the primary file is malformed and its backup is valid, startup restores the backup atomically; when both are malformed, it preserves the existing failure instead of guessing or deleting user state.

User Impact

WhatsApp can recover automatically from an interrupted or corrupted credential write when the valid backup is available, without requiring a new QR pairing.

Evidence

  • WhatsApp auth-store suite: 18 tests passed after the final rebase.
  • Build, vet-equivalent changed checks, formatting, and diff checks passed on the prepared patch.
  • Fresh Codex autoreview: clean, no accepted/actionable findings.
  • Exact prepared head: 09b0d55c163fa7a2c800f1344311e40ee6d73724.
  • Exact-head hosted CI passed: Actions run 28742714587.

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: XS labels Jul 2, 2026
@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 5, 2026, 9:22 AM ET / 13:22 UTC.

Summary
The PR changes WhatsApp auth-store credential recovery so malformed primary creds can be replaced from a valid atomic-write backup while malformed backups are ignored.

PR surface: Source +4, Tests +10. Total +14 across 2 files.

Reproducibility: yes. by source inspection rather than a local run. On current main, a multi-byte malformed creds.json value like {x is returned by the raw read helper, reaches JSON.parse(raw), and prevents the valid backup restore path from running.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/whatsapp/src/auth-store.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Gate final merge on required checks for head 4510d3633e3af8455c27e71b93a4df4c9dd74057 because the full CI link in discussion is for an earlier head.

Risk before merge

  • [P1] The full hosted CI link in the discussion is for head 0940aed6babf50fff1c7e167df9648386d02bc7a; the current head is 4510d3633e3af8455c27e71b93a4df4c9dd74057, so final merge should rely on current-head required checks even though the later change only removes the changelog hunk.

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrowed WhatsApp auth-store recovery after current-head required checks, keeping release-note context in the PR body or squash message rather than CHANGELOG.md.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair remains: the prior changelog blocker is gone, and the remaining action is normal maintainer review plus current-head merge gating.

Security
Cleared: The diff changes local WhatsApp credential JSON validation and focused tests only; it adds no dependency, CI, permission, package, secret-handling expansion, or new code-execution surface.

Review details

Best possible solution:

Land the narrowed WhatsApp auth-store recovery after current-head required checks, keeping release-note context in the PR body or squash message rather than CHANGELOG.md.

Do we have a high-confidence way to reproduce the issue?

Yes, by source inspection rather than a local run. On current main, a multi-byte malformed creds.json value like {x is returned by the raw read helper, reaches JSON.parse(raw), and prevents the valid backup restore path from running.

Is this the best way to solve the issue?

Yes. The PR fixes the owner-boundary restore helper, preserves valid primary creds, restores only parseable backups through the existing atomic write helper, and avoids a broader doctor/config migration for a startup recovery path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against f9e194e4a122.

Label changes

Label justifications:

  • P2: This is a normal-priority WhatsApp credential recovery bug fix with limited blast radius around local auth startup state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Contributor comments describe terminal proof using the exported restore helper with real filesystem objects, and the current head's Real behavior proof check passed.
  • proof: sufficient: Contributor real behavior proof is sufficient. Contributor comments describe terminal proof using the exported restore helper with real filesystem objects, and the current head's Real behavior proof check passed.
Evidence reviewed

PR surface:

Source +4, Tests +10. Total +14 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 7 +4
Tests 1 12 2 +10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 23 9 +14

What I checked:

  • Repository policy applied: Root AGENTS.md and extensions/AGENTS.md were read; the relevant guidance is plugin-boundary review plus release-owned CHANGELOG handling for normal PRs. (AGENTS.md:238, f9e194e4a122)
  • Current main failure path: On current main, restoreCredsFromBackupIfNeeded parses any non-null primary creds before checking the backup, so multi-byte malformed JSON throws through the outer catch and returns false. (extensions/whatsapp/src/auth-store.ts:80, f9e194e4a122)
  • Credential read contract: readWebCredsJsonRawSync returns file contents when the regular file is larger than one byte, so a value like {x reaches JSON.parse in the restore helper. (extensions/whatsapp/src/creds-files.ts:52, f9e194e4a122)
  • Runtime callers: Login and session startup both call restoreCredsFromBackupIfNeeded before using Baileys auth state, so the fix is placed on the startup recovery path rather than a test-only helper. (extensions/whatsapp/src/login.ts:26, f9e194e4a122)
  • PR head fix path: The latest PR head adds isValidJson, returns early only for valid primary creds, rejects invalid backups, and restores valid backups through the existing atomic write helper. (extensions/whatsapp/src/auth-store.ts:70, 4510d3633e3a)
  • Regression coverage: The latest PR head covers restoring malformed primary creds from a valid backup and preserving malformed primary creds when the backup is also malformed. (extensions/whatsapp/src/auth-store.test.ts:79, 4510d3633e3a)

Likely related people:

  • steipete: Recent GitHub history shows steipete touching auth-store credential checks, plugin boundary docs, and the narrowed PR-head rewrite after assignment; local blame for the current restore helper also points to a recent steipete main snapshot. (role: recent area contributor; confidence: high; commits: 9ec9fbf58d86, 58912f8fd842, 4510d3633e3a; files: extensions/whatsapp/src/auth-store.ts, extensions/whatsapp/src/auth-store.test.ts, extensions/whatsapp/src/session.ts)
  • mcaxtr: mcaxtr authored the merged WhatsApp auth stabilization and symlink/atomic credential write hardening that created the backup recovery and credential persistence context this PR uses. (role: adjacent auth-state contributor; confidence: medium; commits: aa76cf43f011, de743c5a543e, 194f0786d4e9; files: extensions/whatsapp/src/auth-store.ts, extensions/whatsapp/src/creds-persistence.ts, extensions/whatsapp/src/session.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (4 earlier review cycles)
  • reviewed 2026-07-03T03:27:58.918Z sha 0ad13183219e21aaf5feed72e8261e6cf58def13 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-05T11:15:52.804Z sha 0940aed6babf50fff1c7e167df9648386d02bc7a :: needs changes before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T12:39:26.340Z sha 4cdfea2b9eb43ba20dae01c61e5ff0339580e32a :: needs changes before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-05T13:17:03.884Z sha 069070ac573005c2117361a14efb0f55bd74d11c :: needs changes before merge. :: [P3] Remove the release-owned changelog entry

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 2, 2026
@LeonidasLux

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Changes made:

  • Added focused regression test for malformed creds.json longer than one byte ({x, 2 bytes) — the exact case where readWebCredsJsonRawSync returns content (passes stat.size > 1) but JSON.parse fails
  • Updated PR body with L2 real behavior evidence: real function call with real filesystem objects, showing backup restoration succeeds for multi-byte malformed JSON
  • All 18 auth-store tests pass, including the new regression test

@clawsweeper

clawsweeper Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 2, 2026
@LeonidasLux

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 🔁 re-review loop A fresh ClawSweeper review was explicitly requested after the latest review. labels Jul 3, 2026
@LeonidasLux

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the PR body with L2 real behavior proof:

  • Standalone npx tsx script (non-test) that calls the actual exported restoreCredsFromBackupIfNeeded with real filesystem objects
  • Before/after comparison showing the fix restores corrupted creds.json from backup
  • Full terminal output included in the Real behavior proof section

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 3, 2026
@steipete steipete self-assigned this Jul 5, 2026
@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 0ad1318 to 0d6678d Compare July 5, 2026 10:53
@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 0d6678d to 0940aed Compare July 5, 2026 11:09
@steipete steipete changed the title fix(whatsapp): wrap JSON.parse with try-catch in auth store and test helpers fix(whatsapp): restore malformed credentials from backup Jul 5, 2026
@steipete

steipete commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 09b0d55c163fa7a2c800f1344311e40ee6d73724:

Known local full-suite noise was unrelated process-cleanup timing and Mattermost watchdog behavior; the exact-head hosted matrix is green.

@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 0940aed to 4cdfea2 Compare July 5, 2026 12:30
@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 4cdfea2 to 3631f06 Compare July 5, 2026 12:42
@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 3631f06 to 069070a Compare July 5, 2026 12:58
@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 069070a to 4510d36 Compare July 5, 2026 13:18
LeonidasLux and others added 4 commits July 5, 2026 14:40
…helpers

Add defensive try-catch around JSON.parse calls in WhatsApp extension
to prevent crashes from corrupted state files.

- restoreCredsFromBackupIfNeeded: wrap creds.json/backup validation
  JSON.parse with try-catch; corrupted creds.json now properly falls
  through to backup restoration instead of skipping it entirely
- updateLastRouteMock: wrap JSON.parse with try-catch, initialize
  empty store on corrupted file
…han one byte

- Add a focused regression test for the exact case ClawSweeper
  flagged: readWebCredsJsonRawSync returns non-null content for
  files with stat.size > 1, so malformed JSON like "{x" (2 bytes)
  reaches JSON.parse — the inner try-catch now catches the parse
  failure and falls through to backup restoration
- Without this patch, JSON.parse("{x") throws to the outer catch
  and restoreCredsFromBackupIfNeeded returns false, skipping backup

🦞 diamond lobster: L2 evidence (real function call + real filesystem objects)

Ref. openclaw#99070
@steipete
steipete force-pushed the fix/whatsapp-json-parse-try-catch branch from 4510d36 to 09b0d55 Compare July 5, 2026 13:40
@steipete
steipete merged commit 42464de into openclaw:main Jul 5, 2026
74 checks passed
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
)

* fix(whatsapp): wrap JSON.parse with try-catch in auth store and test helpers

Add defensive try-catch around JSON.parse calls in WhatsApp extension
to prevent crashes from corrupted state files.

- restoreCredsFromBackupIfNeeded: wrap creds.json/backup validation
  JSON.parse with try-catch; corrupted creds.json now properly falls
  through to backup restoration instead of skipping it entirely
- updateLastRouteMock: wrap JSON.parse with try-catch, initialize
  empty store on corrupted file

* test(whatsapp): add regression test for malformed creds.json longer than one byte

- Add a focused regression test for the exact case ClawSweeper
  flagged: readWebCredsJsonRawSync returns non-null content for
  files with stat.size > 1, so malformed JSON like "{x" (2 bytes)
  reaches JSON.parse — the inner try-catch now catches the parse
  failure and falls through to backup restoration
- Without this patch, JSON.parse("{x") throws to the outer catch
  and restoreCredsFromBackupIfNeeded returns false, skipping backup

🦞 diamond lobster: L2 evidence (real function call + real filesystem objects)

Ref. openclaw#99070

* fix(whatsapp): restore malformed creds from backup

Co-authored-by: LeonidasLux <[email protected]>

* docs(changelog): defer credential recovery entry to aggregate

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: LeonidasLux <[email protected]>
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Jul 15, 2026
)

* fix(whatsapp): wrap JSON.parse with try-catch in auth store and test helpers

Add defensive try-catch around JSON.parse calls in WhatsApp extension
to prevent crashes from corrupted state files.

- restoreCredsFromBackupIfNeeded: wrap creds.json/backup validation
  JSON.parse with try-catch; corrupted creds.json now properly falls
  through to backup restoration instead of skipping it entirely
- updateLastRouteMock: wrap JSON.parse with try-catch, initialize
  empty store on corrupted file

* test(whatsapp): add regression test for malformed creds.json longer than one byte

- Add a focused regression test for the exact case ClawSweeper
  flagged: readWebCredsJsonRawSync returns non-null content for
  files with stat.size > 1, so malformed JSON like "{x" (2 bytes)
  reaches JSON.parse — the inner try-catch now catches the parse
  failure and falls through to backup restoration
- Without this patch, JSON.parse("{x") throws to the outer catch
  and restoreCredsFromBackupIfNeeded returns false, skipping backup

🦞 diamond lobster: L2 evidence (real function call + real filesystem objects)

Ref. openclaw#99070

* fix(whatsapp): restore malformed creds from backup

Co-authored-by: LeonidasLux <[email protected]>

* docs(changelog): defer credential recovery entry to aggregate

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: LeonidasLux <[email protected]>
(cherry picked from commit 42464de)
zeekay pushed a commit to hanzoai/bot that referenced this pull request Sep 11, 2026
* fix(whatsapp): wrap JSON.parse with try-catch in auth store and test helpers

Add defensive try-catch around JSON.parse calls in WhatsApp extension
to prevent crashes from corrupted state files.

- restoreCredsFromBackupIfNeeded: wrap creds.json/backup validation
  JSON.parse with try-catch; corrupted creds.json now properly falls
  through to backup restoration instead of skipping it entirely
- updateLastRouteMock: wrap JSON.parse with try-catch, initialize
  empty store on corrupted file

* test(whatsapp): add regression test for malformed creds.json longer than one byte

- Add a focused regression test for the exact case ClawSweeper
  flagged: readWebCredsJsonRawSync returns non-null content for
  files with stat.size > 1, so malformed JSON like "{x" (2 bytes)
  reaches JSON.parse — the inner try-catch now catches the parse
  failure and falls through to backup restoration
- Without this patch, JSON.parse("{x") throws to the outer catch
  and restoreCredsFromBackupIfNeeded returns false, skipping backup

🦞 diamond lobster: L2 evidence (real function call + real filesystem objects)

Ref. openclaw/openclaw#99070

* fix(whatsapp): restore malformed creds from backup

Co-authored-by: LeonidasLux <[email protected]>

* docs(changelog): defer credential recovery entry to aggregate

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: LeonidasLux <[email protected]>
zeekay pushed a commit to hanzoai/bot that referenced this pull request Sep 11, 2026
* fix(whatsapp): wrap JSON.parse with try-catch in auth store and test helpers

Add defensive try-catch around JSON.parse calls in WhatsApp extension
to prevent crashes from corrupted state files.

- restoreCredsFromBackupIfNeeded: wrap creds.json/backup validation
  JSON.parse with try-catch; corrupted creds.json now properly falls
  through to backup restoration instead of skipping it entirely
- updateLastRouteMock: wrap JSON.parse with try-catch, initialize
  empty store on corrupted file

* test(whatsapp): add regression test for malformed creds.json longer than one byte

- Add a focused regression test for the exact case ClawSweeper
  flagged: readWebCredsJsonRawSync returns non-null content for
  files with stat.size > 1, so malformed JSON like "{x" (2 bytes)
  reaches JSON.parse — the inner try-catch now catches the parse
  failure and falls through to backup restoration
- Without this patch, JSON.parse("{x") throws to the outer catch
  and restoreCredsFromBackupIfNeeded returns false, skipping backup

🦞 diamond lobster: L2 evidence (real function call + real filesystem objects)

Ref. openclaw/openclaw#99070

* fix(whatsapp): restore malformed creds from backup

Co-authored-by: LeonidasLux <[email protected]>

* docs(changelog): defer credential recovery entry to aggregate

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: LeonidasLux <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants