Skip to content

fix: let macOS launch with ready credentials when the PostgreSQL secret is unavailable - #202102

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/macos-postgres-credential-startup
Nov 20, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/macos-postgres-credential-startup

Conversation

@VACInc

@VACInc VACInc commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

The macOS app could quit during launch when its bundled CLI could not resolve the Gateway's PostgreSQL connection secret. The CLI now prepares local runtime pins without looking up that secret when client credentials are ready.

What Problem This Solves

A launch from the desktop can inherit a different environment from the Gateway service. If an env SecretRef is provided only to the service, the app's launch-time Doctor command fails and the app asks the user to recover already-usable credentials.

User Impact

A profile with ready credentials can finish launch preparation even when the PostgreSQL secret is available only to the Gateway service. If the credential receipt needs recovery, the operator still needs access to the matching shared state store.

Root Cause

doctor --client-credentials --fix --non-interactive asked for a fully resolved database selection before it checked whether credential work was needed. The PostgreSQL engine resolver threw on the missing environment variable. The real command returned exit 1 with The CLI command failed. on the baseline.

Why This Change Was Made

The runtime pin owner only needs the configured shared-state engine to determine whether a legacy SQLite pin source exists. The ready path passes that engine to the existing pin owner under the service operation lock. Required credential recovery still resolves the database connection and runs through the existing Doctor maintenance path.

Evidence

Real behavior proof

The regression boots a disposable PostgreSQL 17 fixture with ready local credentials. It replaces the config's connection string with an env SecretRef and withholds that variable from the built CLI subprocess. The app's exact doctor --client-credentials --fix --non-interactive command exits 0, completes the local pin receipt, and preserves the device identity. Replacing the anchor makes the credential receipt stale. The same Doctor path in JSON mode then exits 2 and reports Configure a resolvable PostgreSQL DSN.

node scripts/test-database-conformance.mjs --engine postgres --connection "$TEST_DSN" -- \
  src/commands/startup-client-credentials.postgres.test.ts \
  -t 'prepares native runtime pins' --maxWorkers=1

Before: expected 1 to be +0. After: prepares native runtime pins without the PostgreSQL secret when credentials are ready passed in 6.3 s.

What was not tested

Signed macOS app launch, macOS launch latency, a latest-stable macOS app upgrade, and native exec approvals during a PostgreSQL outage were outside the Linux CLI proof. No paid model calls were used for the product test.

Verification

  • 99 tests passed in the focused credential, runtime pin, and CLI registration run. One legacy PostgreSQL migration test hit the disposable server's default lock table limit. The same test passed after matching the CI setting of max_locks_per_transaction=512.
  • Targeted commands typecheck, lint on the four touched TypeScript files, formatting, and git diff --check passed.
  • Autoreview found no actionable P0–P2 findings on the change from the pinned main revision. The simplification pass kept the existing pin migration, lock, and recovery owners. Production TypeScript changed by +37/-16 lines. The regression adds 35 lines to the existing subprocess suite.
  • GitHub CI passed at 6a2dee198389520cccbab4dc50141820178fe9e5, including all four PostgreSQL conformance shards and the PostgreSQL 16 smoke.
  • PostgreSQL conformance (3/4) recorded the built CLI regression as passing in 6.163 s.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: S labels Nov 19, 2026
@VACInc
VACInc marked this pull request as ready for review November 19, 2026 22:36
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets native startup prepare runtime pins without resolving the PostgreSQL secret when local client credentials are already ready.

Example: The Gateway service has OPENCLAW_TEST_NATIVE_CREDENTIALS_DSN, but the desktop-launched app does not.

  • Before: The app's credential-preparation command fails while resolving the secret despite ready local credentials.
  • After: The ready path completes local runtime-pin preparation; stale credentials still require a resolvable PostgreSQL connection.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and appears correct, but the supplied validation does not satisfy the required real-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The macOS app rejects already-usable local credentials when its desktop environment lacks the Gateway service's PostgreSQL secret.
Reason: The maintainer-authored direction restores launch preparation using the established local-storage contract without adding configuration or changing recovery consent.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a source-verifiable launch failure still present on main, and no actionable code defect was found.

Priority: P1
Reviewed head: 6a2dee198389520cccbab4dc50141820178fe9e5

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide terminal screenshots or redacted live output of the shipped native preparation command with ready credentials and the PostgreSQL secret withheld, plus a latest-stable upgrade preserving settings, credentials, and runtime pins; redact keys, IP addresses, and non-public endpoints.
Agent review details

How this fits together

The macOS app invokes its bundled Doctor command before admitting native credential consumers; that command checks local credential readiness and delegates runtime-pin preparation to the daemon's existing local SQLite owner.

flowchart TD
  A[macOS app launch] --> B[Bundled Doctor command]
  B --> C[Local credential readiness]
  C -->|Ready| D[Configured state engine]
  D --> E[Daemon service operation lock]
  E --> F[Local runtime pin store]
  C -->|Recovery required| G[Resolved database and Doctor maintenance]
Loading

Technical review

Best possible solution:

Keep the ready path local while preserving the existing service lock, runtime-pin migration owner, and database-backed credential recovery path.

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

Current main resolves PostgreSQL connection secrets before returning from the native ready-credential path, and the app treats that command's failure as failed credential preparation; the PR reports a matching red/green subprocess regression, which was inspected but not rerun.

Is this the best way to solve the issue?

The change repairs the unnecessary secret dependency at the existing owner boundary, preserves required recovery, and adds one regression covering both successful local preparation and refusal when recovery actually needs shared state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f91bc9900e81.

Provenance checked

  • Ready native credential preparation keeps the original intent (8910654: Native startup must settle runtime intent after credential migration so the app does not launch an obsolete Gateway.)
  • PostgreSQL runtime-pin receipt completion keeps the original intent (b87a1ab: Runtime intent is fixed-local, and PostgreSQL has no shipped legacy shared-state pin source to migrate.)
  • Prepared runtime-pin store and migration lifecycle keeps the original intent (6a15410: Prepare the target before shared-source transactions while preserving cancellation, exact values, and target-first completion ordering.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit 5f40d22 adds src/commands/startup-client-credentials.ts:162 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5f40d22a366d; files: src/commands/startup-client-credentials.ts)

PR surface

Source +21, Tests +35, Docs +3. Total +59 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 37 16 +21
Tests 1 35 0 +35
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 75 16 +59

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P1: A desktop-launched macOS app can fail launch preparation for an otherwise usable PostgreSQL-backed profile when only the Gateway service receives the connection secret.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: A desktop-launched macOS app can fail launch preparation for an otherwise usable PostgreSQL-backed profile when only the Gateway service receives the connection secret.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 19, 2026, 5:52 PM ET / 22:52 UTC.

@VACInc
VACInc merged commit 6594caf into openclaw:main Nov 20, 2026
230 checks passed
@VACInc

VACInc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

@VACInc
VACInc deleted the fix/macos-postgres-credential-startup branch November 20, 2026 16:23
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
Keep already-ready local credential preparation independent from PostgreSQL
connection resolution, while retaining the existing pin migration owner and
full connection requirements for credential recovery.

From 5e2f35e7a4158b7596549db65bec9e4f26057259
(original 6594caf).

Co-authored-by: VACInc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit f022591638c8f555e4d3634c339eb274cf02d361)
(cherry picked from commit 384759cd29ab46fc52fc8b22fb6c933cddba26ac)
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…law#194384)

* docs: clarify PostgreSQL conformance coverage

* fix(cron): keep one-shot finalization working on PostgreSQL 16

* test(database): reuse cron conformance for JSON conversion regression

* test(postgres): accept fractional explain row counts

(cherry picked from commit 7ab0143)

Release adaptation: Only engine-owned jsonValue and retained cron enabled JSON replacement; preserve native boolean type with PG16 explicit ::json and SQLite json(). Omit unrelated PG docs/EXPLAIN test edits; retained one-shot enabled-transition caller present on baseline.

Follow-up dispositions: e029e18 docs: document isolated PostgreSQL restore drills (openclaw#202704); 49f0740 fix(database): report disabled memory after a port (openclaw#202630); a80b564 fix: keep database workers healthy after silent connection loss (openclaw#201856); 3d91af2 fix(config): reject reserved PostgreSQL schema prefixes (openclaw#202097); 835d722 fix: catch incompatible ownership before porting to SQLite (openclaw#202101); 67796a6 fix: keep scheduled Git backups current on PostgreSQL (openclaw#201870); cc849dd fix: recover lease heartbeats after a PostgreSQL connection loss (openclaw#201858); 6594caf fix: prepare macOS runtime pins without the PostgreSQL secret (openclaw#202102); 6ca56cd docs: clarify PostgreSQL storage and backup coverage (openclaw#202086); a079190 fix(postgres): chat history slows under concurrent reads (openclaw#190129); 2ff4256 feat(database): keep PostgreSQL rollback captures in PostgreSQL (openclaw#196236); 96c685b feat(backup): restore PostgreSQL stores into a staging database for restore drills (openclaw#194808); fb83d65 fix: reduce transcript allocation when preparing native context seeds; 71ec4d2 fix(config): keep Workboard PostgreSQL upgrades readable (openclaw#194648); b6ed907 perf(sessions): persist active transcript facts for hydration (openclaw#193682)

Validation: Baseline cron generated json(bound text) on PostgreSQL where json(text) is unavailable; helper and focused boolean regression retained. Exact PostgreSQL16 server proof unavailable; focused SQLite/helper tests queued. diff check passed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 38fdd9b52704d588d9ca24ef8e391d644961c985)
(cherry picked from commit fb935e6912388314851b05cb698ef038b83bbd07)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

1 participant