Skip to content

fix(zalouser): avoid Gateway stalls during credential persistence - #156003

Merged
steipete merged 6 commits into
mainfrom
codex/zalouser-credential-worker-20260922
Sep 23, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/zalouser-credential-worker-20260922

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Zalo QR login and logout can block other Gateway work while reading or writing credentials.

User Impact

Credential persistence runs on SQLite workers while preserving the existing credential format and logout markers. Delayed QR writes stop when their hosted setup wizard closes, and a waiting restore keeps the state directory it originally selected.

Why This Change Was Made

The registered login/logout callers now await the asynchronous keyed-store owner. The old synchronous logout already completed persistence before returning; this change preserves that durability while moving SQL off the Gateway thread. Logout keeps atomic revocation and presence reporting, and replacement login and restore wait for pending revocation. A focused credential persistence owner retains the existing refresh currentness checks. Hosted setup supplies a pure session-lifetime assertion through the existing preparation flow and into the final worker write grant.

No configuration, schema, protocol, or credential migration is required. Existing external setup preparation callbacks and the published older-host capability fallback remain supported. Current hosts use the worker path; runtime errors do not trigger a synchronous fallback.

Evidence

On the combined current-main source, 207 focused tests passed across seven credential, Doctor, registered setup, hosted wizard, session lifecycle, and channel-add files. The strengthened real-worker QR test calibrates all eight native SQLite observers, then verifies zero parent-thread constructors, closes, prepares, executions, or statement reads/writes through cold QR login, credential readback, durable logout, and worker teardown. Restoring the original synchronous logout makes that test fail with seven parent-thread database constructors, including in-memory databases. The candidate bytes were restored and the full focused selection passed.

Earlier regression controls also detect missing final setup-lifetime enforcement and state-root drift while waiting for logout. Prior send/listener sibling proof is reused only where the source is unchanged. Current main's asynchronous account resolver and assertion-baseline reductions are preserved.

Fresh independent P2 review is clean. Thirty-seven selected repository checks passed before the latest main composition, including core and extension types, typed lint, formatting, three ratchets, and all unused-export scans. The remaining UI chat typecheck initially failed on an unchanged main-branch fixture. After incorporating its canonical repair, that typecheck passed. All 22 feature files retained their reviewed bytes across this composition; the unaffected runtime and static proof was reused. The proof uses real SQLite workers and synthetic SDK transport without an authenticated Zalo account or operator Gateway state. No full local build was run; exact-head hosted CI and both required gates passed before the native merge.

The first refreshed CI run exposed an activity-recap fixture that polled sessions.describe after the model result, before the owning write and publication necessarily settled. That fixture now waits for the next existing publication without filtering successful states, checks the captured state, and then asserts a single direct describe result. Its original durable-watermark and model-call assertions remain. All 22 cases passed with this correction on the exact CI merge source using local Node 24.21; hosted CI uses Linux/Node 24.19. A real writer-queue probe also verified that model completion leaves the old durable recap updating until the write is released. The fixture change passed its own P2 review, owning typecheck, typed lint, and formatting. No production recap code or test timeout changed. The final exact-head required CI passed before landing.

The next hosted run passed the recap shard and exposed a Discord policy fixture that activated unrelated plugins during each real reload. Its synthetic configuration now allows the Discord plugin, and the reload result must explicitly be applied. The original admission, held lookup, revocation, and active-turn assertions and the 120-second timeout are unchanged. This fixture passed on the exact failing CI merge source in 15.3 seconds locally, with 24 KiB of temporary growth; its owning root typecheck, typed lint, formatting, and independent P2 review passed. No production Discord code changed. The same hosted run also found three Session Share fixture failures from an omitted registered-service startup; that fixture lifecycle was repaired separately on main in #156464 (d7b45d7e76c6).

Recorded test cost

The three previously missing standalone process-wall measurements are now captured on the exact, unchanged reviewed head 6c2a541265b9. These three measurements were captured after the PR merged, against the retained reviewed commit; they supplement the original pre-merge evidence. Each file ran separately and sequentially with /usr/bin/time -p pnpm test <file> --maxWorkers=1, on macOS/Node 24.21 after a frozen dependency restore. Filesystem module caching was disabled. All three commands exited successfully; no test source, timeout, or assertion changed.

Standalone file Passing cases Process wall (time real) Vitest duration
extensions/zalouser/src/zalo-js.credentials.test.ts 19 92.86 s 81.50 s
src/system-agent/hosted-setup.runtime.test.ts 18 102.74 s 74.12 s
src/wizard/session.test.ts 43 10.76 s 5.75 s

Process wall includes the repository wrapper, worker preparation/verification, imports, execution, and teardown. It excludes the outer resource-accounting observer. The credential run had a cold worker-artifact cache and reported 40.873 s of worker preparation; the hosted-setup run reused worker outputs but reported 45.45 s of Vitest transformation work. Those phases are included in the totals, not added to them. These are single-run cost observations, not a performance-regression comparison.

The credential suite retains the actual worker-store path, durable logout, final setup-owner enforcement, and calibrated zero-parent-SQL observation. The hosted suite retains config publication and wizard/session lifecycle behavior. Mocking away those owners would remove the boundaries these regressions protect; much of the measured wall cost belongs to preparation and transforms rather than additional waits in the cases. Wizard-session remains the smaller direct owner suite. No other already-qualified proof was rerun for this timing follow-up.

Earlier successful measurements remain separate: the 207-case credential/setup/wizard batch took 133.596 s end to end. Its credential and Doctor files shared a 31.76 s Vitest invocation; that combined duration was never claimed as either file's independent wall time. Earlier single-file Vitest durations were 33.86 s for chat-wizard-host, 20.24 s for channels.add, and 12.67 s for Zalo setup-surface. The activity-summary command took 63.529 s end to end (55.36 s Vitest); Discord took 48.398 s end to end (41.39 s Vitest; 15.313 s test body). Those two fixture proofs ran on their exact failing CI merge source plus the reviewed correction, using macOS/Node 24.21; hosted CI uses Linux/Node 24.19.

On published head 6c2a541265b9, CI run 35869185534 passed 149 jobs (16 skipped). Available GitHub timestamps give 538 s for the activity-summary shard, 365 s for the Discord policy shard, and 416 s for the Session Share shard. These are complete multi-file job durations, including setup and other tests, not per-file times or billed CPU seconds. Both required CI gates passed before the native merge.

Move QR credential saves and logout revocation onto the shared SQLite worker,
await their durable completion, and keep restoration behind pending revocation
on its originally selected state directory. Preserve the credential format,
revocation markers, refresh CAS, and named older-host capability fallback.

Carry a live hosted-wizard assertion through setup and into the final write
grant so a detached QR login cannot persist after its owner is retired.

Validation: 172 focused tests across worker storage, registered setup, synthetic
SDK transport, and core wizard lifecycle; complete independent P2 review clean.
Repository gates: 34 passed, 3 unchanged core gates reused. The inherited unused
TSGO_CORE_TEST_MAX_ROOTS export is the sole remaining gate failure on this base;
canonical fix 1619aff supplies its repair.

Regression controls prove the former host-SQL logout path, a missing final
wizard-lifetime guard, and state-root drift across a pending logout. No live
provider account, operator Gateway restart, schema change, or protocol bump.
@clawsweeper

clawsweeper Bot commented Sep 22, 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 channel: zalouser Channel integration: zalouser gateway Gateway runtime commands Command implementations size: L maintainer Maintainer-authored PR labels Sep 22, 2026
@steipete
steipete marked this pull request as ready for review September 22, 2026 23:06
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed September 23, 2026, 11:18 AM ET / 15:18 UTC (Revision 4).

ClawSweeper review

What this changes

Moves Zalo Personal credential persistence onto SQLite workers, prevents retired setup wizards from saving credentials, and updates related regression fixtures.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This remains a useful fix: current main still performs synchronous QR credential saves and logout. No introduced correctness defect was found; the previous test-cost follow-up is partially satisfied.

Priority: P2
Reviewed head: 6c2a541265b904ce09575ecee85abe89323e80c0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound, focused reliability patch with meaningful storage-boundary proof and successful published-head CI; remaining follow-up concerns test-cost reporting.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): Recorded production-storage boundary runs exercise QR persistence, durable logout, and owner closure using real SQLite workers with synthetic Zalo transport, including no-write rejection after closure and a failing synchronous-logout control. This proves the changed storage path, not authenticated Zalo service behavior; no stored-data contract changes require migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): Recorded production-storage boundary runs exercise QR persistence, durable logout, and owner closure using real SQLite workers with synthetic Zalo transport, including no-write rejection after closure and a failing synchronous-logout control. This proves the changed storage path, not authenticated Zalo service behavior; no stored-data contract changes require migration.
Evidence reviewed 9 items Still necessary on main and latest release: Both fetched main and the supplied latest-release commit retain synchronous saveStoredZaloCredentials and clearStoredZaloCredentials through openSyncKeyedStore. Existing asynchronous refresh support does not cover these operations.
Release comparison: The v2026.9.5 source also contains synchronous credential saves and logout; this branch’s central change is not already shipped there.
Durable storage and compatibility: Credential saves await worker registration with the live assertion. Logout uses observation and atomic comparison, retaining the named older-host atomic-update fallback. Namespace, hashed keys, credential fields, and revocation representation remain unchanged; no stored-data migration is introduced.
Findings None None.
Security None None.

How this fits together

Zalo Personal setup supplies login credentials to OpenClaw’s plugin-state storage. Credential persistence connects QR login, session restoration, and logout to the shared SQLite worker while the Gateway continues handling other work.

flowchart TD
  A[QR login or logout] --> B[Zalo credential owner]
  C[Hosted setup lifetime] --> D[Current authority check]
  B --> D
  D --> E[SQLite worker]
  E --> F[Credentials or revocation marker]
  F --> G[Session restoration]
Loading

Before merge

  • Complete next step (P2) - Record per-file process wall times for extensions/zalouser/src/zalo-js.credentials.test.ts, src/system-agent/hosted-setup.runtime.test.ts, and src/wizard/session.test.ts using the prescribed single-worker invocation. Reuse the already recorded activity-summary, Discord, and CI timings.
Agent review details

Security

None.

PR surface

Source +135, Tests +254, Docs +9, Other 0. Total +398 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 10 373 238 +135
Tests 12 315 61 +254
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 24 698 300 +398

Review metrics

Metric Value Why it matters
Production versus test growth Production net +135 lines; tests and test support net +254 lines Production growth supports credential sequencing and lifetime enforcement; the accompanying tests exercise persistence, cancellation, and compatibility.
Public setup contract 1 optional callback added; 0 config options or schema changes The lifetime assertion extends the existing preparation contract without making existing callers source-incompatible.

Technical review

Best possible solution:

Keep credential persistence on the existing worker-backed storage owner while preserving durable logout, stored credentials, and setup-lifetime enforcement.

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

Yes, source establishes that current-main QR saves and logout enter synchronous SQLite storage on the calling thread. The reported negative control detects that path; this review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes, reusing the existing asynchronous store and carrying live setup authority to its final write grant addresses the blocking operations without changing credential representation or introducing a competing storage path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Zalo Personal reliability fix for Gateway stalls during credential operations.
  • merge-risk: 🚨 compatibility: The setup API gains an optional lifetime callback; the documented compatibility scope preserves existing preparation callbacks and older-host storage behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Recorded production-storage boundary runs exercise QR persistence, durable logout, and owner closure using real SQLite workers with synthetic Zalo transport, including no-write rejection after closure and a failing synchronous-logout control. This proves the changed storage path, not authenticated Zalo service behavior; no stored-data contract changes require migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded production-storage boundary runs exercise QR persistence, durable logout, and owner closure using real SQLite workers with synthetic Zalo transport, including no-write rejection after closure and a failing synchronous-logout control. This proves the changed storage path, not authenticated Zalo service behavior; no stored-data contract changes require migration.

Evidence

What I checked:

  • Still necessary on main and latest release: Both fetched main and the supplied latest-release commit retain synchronous saveStoredZaloCredentials and clearStoredZaloCredentials through openSyncKeyedStore. Existing asynchronous refresh support does not cover these operations. (extensions/zalouser/src/session-state.ts:103, 645f1bc4ef49)
  • Release comparison: The v2026.9.5 source also contains synchronous credential saves and logout; this branch’s central change is not already shipped there. (extensions/zalouser/src/session-state.ts:103, ec9c1a13db89)
  • Durable storage and compatibility: Credential saves await worker registration with the live assertion. Logout uses observation and atomic comparison, retaining the named older-host atomic-update fallback. Namespace, hashed keys, credential fields, and revocation representation remain unchanged; no stored-data migration is introduced. (extensions/zalouser/src/session-state.ts:134, 6c2a541265b9)
  • Authority reaches final write admission: The setup owner’s lifetime assertion flows through QR persistence to register options. The existing worker client composes it with lifecycle authority, and SQLite write admission checks it at both transaction and commit grants. Logout binds the same assertion through withCurrent. (src/plugin-state/plugin-state-worker-client.ts:69, 6c2a541265b9)
  • Production storage boundary proof: The captured PR body reports real SQLite-worker execution with synthetic Zalo transport: cold QR login, credential readback, durable logout, and teardown produce zero parent-thread SQLite operations across eight calibrated observers. Restoring synchronous logout fails that control. The registered setup regression closes its owner while persistence is held and confirms that no credentials are stored; separate hosted tests reject retained callbacks after disposal and completion. (extensions/zalouser/src/zalo-js.credentials.test.ts:286, 6c2a541265b9)
  • Documented SDK compatibility scope: The PR body explicitly preserves existing preparation callbacks and older-host capability fallback. The added setup lifetime callback is optional and documented as complementary to asynchronous preparation, with current hosted callers supplying it. Public docs: docs/plugins/sdk-setup.md. (docs/plugins/sdk-setup.md:559, 6c2a541265b9)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the remaining standalone wall-time measurements for credential persistence, hosted setup, and wizard-session tests without relabeling combined or Vitest-only durations.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-22T23:14:37.431Z sha aef684a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-23T12:19:32.992Z sha dc3a687 :: needs changes before merge. :: none
  • reviewed 2026-09-23T13:53:34.238Z sha 6c2a541 :: needs changes before merge. :: none

Compose current main while preserving the asynchronous channel-account resolver
and the Zalo setup-lifetime assertion. Strengthen the existing QR regression to
calibrate all eight native SQLite counters, then cover cold login, credential
readback, durable logout, and awaited worker teardown without parent SQL.

Validation: 207 cases across seven lifecycle and channel files; fresh P2 review
clean; 37 of 38 selected repository gates pass. Restoring the original synchronous
logout fails the regression with seven parent database constructors, including
in-memory databases. Candidate source was restored and the full selection passed.

The remaining gate is an unchanged main-branch chat-scroll fixture type error at
chat-transcript-scroll-ownership.test.ts:210-211. Its canonical repair and a fresh
ui-chat typecheck remain required before landing. No full local build was run.
Preserve all 22 reviewed feature postimages while incorporating current main,
including the canonical chat-scroll pane identity correction. The previously
failing UI chat type graph now passes. The 207 focused lifecycle cases, clean
P2 review, and 37 unaffected selected checks remain valid for unchanged source.

No dependency reconciliation or full local build was needed for this carry.
Exact-head hosted CI remains required before landing.
Wait for the existing owner's next publication after releasing the model result,
assert its captured state without filtering successful outcomes, and check one
direct describe response. Preserve the durable watermark and model-call assertions.
No production logic or test deadline changes.

Validation: 22 cases on the exact tested CI merge with Node 24.21; real writer
queue probe preserves the old updating recap until write settlement, then exposes
the published current recap. Owning type graph, typed lint, formatting, and P2
review pass. The initial CI log redacts the returned summary, so the change does
not claim that its historical failure was proved timing-only.
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 23, 2026
Limit the synthetic policy fixture to its Discord plugin so real reloads do
not cold-load unrelated runtime plugins. Require the reload to report
applied while preserving the active-turn, held lookup and revocation flow.

Exact CI merge-source proof passed locally in 15.3s. Root fixture types,
typed lint, formatting and independent review passed. No production code
or test timeout changed.
@steipete
steipete merged commit 4e9e681 into main Sep 23, 2026
229 of 230 checks passed
@steipete
steipete deleted the codex/zalouser-credential-worker-20260922 branch September 23, 2026 15:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 24, 2026
…enclaw#156003)

* fix(zalouser): avoid Gateway stalls during credential persistence

Move QR credential saves and logout revocation onto the shared SQLite worker,
await their durable completion, and keep restoration behind pending revocation
on its originally selected state directory. Preserve the credential format,
revocation markers, refresh CAS, and named older-host capability fallback.

Carry a live hosted-wizard assertion through setup and into the final write
grant so a detached QR login cannot persist after its owner is retired.

Validation: 172 focused tests across worker storage, registered setup, synthetic
SDK transport, and core wizard lifecycle; complete independent P2 review clean.
Repository gates: 34 passed, 3 unchanged core gates reused. The inherited unused
TSGO_CORE_TEST_MAX_ROOTS export is the sole remaining gate failure on this base;
canonical fix 802e512 supplies its repair.

Regression controls prove the former host-SQL logout path, a missing final
wizard-lifetime guard, and state-root drift across a pending logout. No live
provider account, operator Gateway restart, schema change, or protocol bump.

* test(gateway): await recap publication before projection assertion

Wait for the existing owner's next publication after releasing the model result,
assert its captured state without filtering successful outcomes, and check one
direct describe response. Preserve the durable watermark and model-call assertions.
No production logic or test deadline changes.

Validation: 22 cases on the exact tested CI merge with Node 24.21; real writer
queue probe preserves the old updating recap until write settlement, then exposes
the published current recap. Owning type graph, typed lint, formatting, and P2
review pass. The initial CI log redacts the returned summary, so the change does
not claim that its historical failure was proved timing-only.

* test(discord): scope policy reload fixture activation

Limit the synthetic policy fixture to its Discord plugin so real reloads do
not cold-load unrelated runtime plugins. Require the reload to report
applied while preserving the active-turn, held lookup and revocation flow.

Exact CI merge-source proof passed locally in 15.3s. Root fixture types,
typed lint, formatting and independent review passed. No production code
or test timeout changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: zalouser Channel integration: zalouser commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: L 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