Skip to content

fix(clickclack): discussion rooms fail to open when plugin state runs on PostgreSQL - #188643

Merged
steipete merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/clickclack-postgres-revoked-channel-key
Oct 30, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/clickclack-postgres-revoked-channel-key

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #188642

What Problem This Solves

Fixes: opening a ClickClack discussion room fails with "PostgreSQL plugin state keys cannot contain NUL characters" when the state database family runs on PostgreSQL, after the remote channel has already been created.

User Impact

User impact: on PostgreSQL state, ClickClack discussion rooms open, close and clean up as they do on SQLite. SQLite installs keep every revoked-channel marker they already hold; nothing needs to be done after the update.

Why This Change Was Made

The revoked discussion channel store keyed its markers by the server URL and channel id joined with a NUL character, which the PostgreSQL plugin state kernel refuses. Following #184919 (the same rule for the iMessage plugin), the key is now a hex sha256 prefix of the JSON-encoded pair, with the same trailing-slash normalization as before.

Markers written under the NUL key exist only on SQLite and are authority evidence (they keep released channels revoked), so they are re-keyed once per runtime: registration starts adoption immediately, and async store operations await the same adoption before proceeding. Adoption lists the namespace and moves each NUL-keyed marker with registerIfAbsent and delete. Synchronous authorization checks deny access until adoption succeeds; on failure they keep denying while the next async operation retries. PostgreSQL never held one, so the listing finds nothing there. The adoption can be removed once no supported stable release writes the NUL key. A Doctor migration was the alternative, but plugin state markers are plugin-owned, and the in-plugin adoption matches the merged iMessage fix.

Accepted edge cases:

  • An upgraded SQLite namespace already at its 100,000-marker limit cannot insert the re-keyed copy. The adoption then fails on every async revoked-channel store operation, so revocation calls and inbound ClickClack channel routing fail until markers are removed.

Evidence

Final-head CI run 41126484646 passed, including all three PostgreSQL conformance shards, changed tests, baseline ratchets, security-fast, and the effective CI gate. The initial maintainer run caught a missing allocation for the full test delta; the dedicated allocation now covers all 103 added regression lines.

Maintainer hardening at 7370123ad73ba18f3f814d21d9afdf17566fce41 closes the synchronous startup authorization gap. The extended SQLite legacy-marker regression checks denial for both revoked and unrevoked channels before adoption completes, then verifies that the legacy-revoked channel stays revoked and the unrevoked channel is allowed. The full 103-line regression growth has a dedicated allocation.

The maintainer edit passes static formatting and diff checks. Independent Codex reviews of the repair and the complete final branch at 0febd35184fad1d985a38551ee0c7b2399b11e58 against merge-base 83064b3ae1155f0c6c96081c863e7db4bd4451f4 found no accepted P0/P1 findings. No contributor runtime code or tests were executed locally during maintainer landing; new-head runtime validation uses PR CI.

Tested at c980afaf3dc (base upstream/main 83064b3ae115).

An isolated Gateway (own state directory and port) with database.families.state.engine: "postgres" against a throwaway postgres:17-alpine container, the ClickClack plugin pointed at a local fake ClickClack server, and a synthetic bot token. Both sides ran sessions.create for agent:main:dashboard:proof-room, then the Gateway method the Control UI's discussion panel calls:

Before (base 83064b3ae115):

$ openclaw gateway call session.discussion.open --params {"sessionKey":"agent:main:dashboard:proof-room"} --json
{
  "ok": false,
  "error": {
    "type": "gateway_request_error",
    "code": "UNAVAILABLE",
    "message": "PostgreSQL plugin state keys cannot contain NUL characters.",
    "retryable": false
  }
}

# fake ClickClack server log
  CREATE CHANNEL chn_room1 name=proof-room

# Gateway log
  [ws] ⇄ res ✗ session.discussion.open 57ms errorCode=UNAVAILABLE errorMessage=PostgreSQL plugin state keys cannot contain NUL characters.
  [ws] ⇄ res ✗ session.discussion.open 13ms errorCode=UNAVAILABLE errorMessage=PostgreSQL plugin state keys cannot contain NUL characters.

After (this PR):

$ openclaw gateway call session.discussion.open --params {"sessionKey":"agent:main:dashboard:proof-room"} --json
{
  "state": "open",
  "embedUrl": "http://127.0.0.1:19397/embed/channel/team/room1?openclawHostTheme=1",
  "openUrl": "http://127.0.0.1:19397/app/team/room1"
}

# fake ClickClack server log
  CREATE CHANNEL chn_room1 name=proof-room

# Gateway log lines mentioning NUL characters
  0

Observed result: on the base the channel is created and the open fails, again on retry; with the fix the room opens, and session.discussion.info reports state: open.

Full captures: before, after.

Upgrade from the latest stable on SQLite state: openclaw v2026.10.9 with @openclaw/[email protected] opened the session's room (chn_room1), and a bot token rotation in config made the binding stale, so the release revoked the channel and session.discussion.info reported state: available. On the same state directory, openclaw doctor --fix from this branch, then this branch's Gateway:

# openclaw.sqlite, namespace discussion-revoked-channels, after the stable Gateway stopped
key "http://127.0.0.1:19399\0chn_room1"  {"channelId":"chn_room1","revokedAt":1793387539338,...}

# after this branch's first session.discussion.open (state: open, new channel chn_room2)
key "204cca07efa178e408ff40df5a242550"   {"channelId":"chn_room1","revokedAt":1793387539338,...}

# key this branch computes for chn_room1
204cca07efa178e408ff40df5a242550

The NUL-keyed row is gone and no Gateway log line mentions NUL characters. Full capture: upgrade.

Tests: revoked-channel-store.postgres.test.ts (mark, read and clear a revoked channel on PostgreSQL state, run through node scripts/test-database-conformance.mjs --engine postgres) fails on the base with the same NUL error and passes with the fix. adopts a revocation stored under the NUL-joined SQLite key once in service-state-persistence.test.ts fails on the base and passes with the fix; the other 21 tests in that file pass on both.

Checks: the touched tests (pnpm test <file> --maxWorkers=1, wall time per file below; the PostgreSQL file skips without a connection there and took 31.0 s through the conformance lane, 0.5 s of it the test), the extension test typecheck (pnpm tsgo:extensions:test), oxlint and the formatter on the changed files, and the test-line ratchet; the broad suites run in this PR's CI.

Test file --maxWorkers=1 wall
extensions/clickclack/src/discussions/service-state-persistence.test.ts 16.1 s
extensions/clickclack/src/discussions/revoked-channel-store.postgres.test.ts 8.1 s (skipped without a connection)

Not covered: the proof uses a fake ClickClack server rather than a real one, and drives the Gateway method directly rather than through the Control UI panel. On PostgreSQL, the conformance test covers identity marking, the async read and clear; room close (the binding-conditioned mark) and the inbound prepared read use the same key but were not run there. The upgrade run shows the marker re-keyed and kept, not a revoked channel refusing an inbound message: the fake server has no event stream, so inbound routing was not driven.

The revoked discussion channel store keyed markers by the server URL and
channel id joined with NUL. PostgreSQL plugin state rejects NUL in keys, so
opening a discussion room failed with PLUGIN_STATE_INVALID_INPUT after the
room was created, and close and cleanup failed the same way. Key markers by a
sha256 prefix of the encoded pair, and adopt markers still stored under the NUL
key (SQLite only) once per runtime by listing the namespace.
@clawsweeper

clawsweeper Bot commented Oct 30, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR hashes ClickClack revoked-channel keys and migrates existing SQLite markers to the new keys.

Example: Open a discussion for agent:main:dashboard:proof-room with PostgreSQL state.

  • Before: The remote channel is created, then opening fails because the plugin-state key contains NUL.
  • After: The Gateway returns state: open with the room URLs.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful producer-level fix with credible Gateway and upgrade captures, held back by a concrete migration regression and incomplete authority proof.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: ClickClack discussion rooms fail to open on PostgreSQL state after creating the remote channel.
Reason: Restoring an existing bundled-plugin workflow has clear value and requires no new option or public API.

Merge readiness

⛔ Blocked before merge - 5 items remain

This PR fixes a verified PostgreSQL failure, but its migration breaks routing when the existing marker store is full and needs further authority-boundary validation.

Priority: P2
Reviewed head: c980afaf3dc0b34386be96a6e7c4733cf9718e69

Before merge

  • Add real behavior proof - Authority-chain proof required: inspected captures demonstrate PostgreSQL discussion-open recovery through the real Gateway and preservation of a v2026.10.9 SQLite marker, but do not show a revoked discussion denied before session disclosure or send effects, including before adoption completes; provide redacted production-path logs or terminal output with an active-room control and revoked-room rejection. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Migrate full namespaces without requiring an extra marker slot (P2) - An existing SQLite namespace containing 100,000 legacy markers cannot execute this registerIfAbsent: the store uses reject-new and rejects the temporary 100,001st row before the old row is deleted. Adoption then rejects on every retry. Because every asynchronous revocation read awaits adoption, resolveClickClackDiscussionRoute catches that rejection and returns revoked even for ordinary unbound channels. Reads worked on the base at the same capacity. Re-key without requiring spare capacity and without deleting authority before its replacement is durable, and cover the full-namespace upgrade case.
  • Add the required scoped allocation for regression-test growth (P3) - The patch adds net 98 test lines without a config/test-lines-allocations entry, contrary to the applicable test-authoring rule. The exact-head baseline check also identifies test-lines as failing. Add a justified allocation for these distinct PostgreSQL and upgrade regressions while leaving the shared scalar unchanged.
  • Resolve security concern: Validate authority before legacy adoption completes - The synchronous scoped-access provider consults the new key immediately, while legacy adoption begins only through asynchronous store operations. A leftover binding plus its legacy revocation marker is a documented crash-recovery state. The asynchronous access paths await adoption, so this review does not establish a reachable disclosure bypass; the supplied upgrade capture establishes storage preservation only.
  • Resolve merge risk - Before merge, the contributor must establish that synchronous scoped access cannot authorize an upgraded revoked discussion while legacy-marker adoption is pending.

Findings

  • [P2] Migrate full namespaces without requiring an extra marker slot — extensions/clickclack/src/discussions/revoked-channel-store.ts:61-62
  • [P3] Add the required scoped allocation for regression-test growth — extensions/clickclack/src/discussions/revoked-channel-store.postgres.test.ts:21
  • [medium] Validate authority before legacy adoption completes — extensions/clickclack/src/discussions/revoked-channel-store.ts:43

Tests

  • Missing end-to-end proof: Add production-path proof that an upgraded revoked room is denied routing and session access before final effects, including access before adoption completes, with an active room as the allowed control.
Agent review details

How this fits together

ClickClack discussion operations and message routing consult plugin-owned revocation markers before using a bound channel or granting access to its attached session.

flowchart TD
  A[Discussion panel or channel message] --> B[ClickClack discussion service]
  B --> C[Revocation store]
  C --> D[Plugin state worker]
  D --> E[SQLite or PostgreSQL]
  B --> F[Channel operations and session access]
Loading

Technical review

Best possible solution:

Keep portable hashed keys in the existing revocation owner, migrate markers without requiring spare capacity, and preserve revocation at every access boundary.

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

Current-main source establishes the NUL-key rejection, and inspected contributor captures demonstrate it through the Gateway; no target code was executed during this review.

Is this the best way to solve the issue?

Portable hashing fixes the producer and the added tests cover distinct storage boundaries, but adoption must preserve authority and work without temporary spare capacity.

Full review comments:

  • [P2] Migrate full namespaces without requiring an extra marker slot — extensions/clickclack/src/discussions/revoked-channel-store.ts:61-62
    An existing SQLite namespace containing 100,000 legacy markers cannot execute this registerIfAbsent: the store uses reject-new and rejects the temporary 100,001st row before the old row is deleted. Adoption then rejects on every retry. Because every asynchronous revocation read awaits adoption, resolveClickClackDiscussionRoute catches that rejection and returns revoked even for ordinary unbound channels. Reads worked on the base at the same capacity. Re-key without requiring spare capacity and without deleting authority before its replacement is durable, and cover the full-namespace upgrade case.
    Confidence: 0.99
  • [P3] Add the required scoped allocation for regression-test growth — extensions/clickclack/src/discussions/revoked-channel-store.postgres.test.ts:21
    The patch adds net 98 test lines without a config/test-lines-allocations entry, contrary to the applicable test-authoring rule. The exact-head baseline check also identifies test-lines as failing. Add a justified allocation for these distinct PostgreSQL and upgrade regressions while leaving the shared scalar unchanged.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Preserve denial throughout adoption (recommended)
    The contributor should ensure legacy revocation remains effective before adoption completes and demonstrate denial at the final session-access effect.

Provenance checked

  • Revoked-channel key encoding changes intended behavior with a stated reason (5420c5c: The original discussion implementation retained revoked-channel evidence to distinguish released managed rooms from ordinary channels.)
  • Published revocation authority keeps the original intent (ad76238: Bound-message and tool guards consume owner-published facts while retaining denial during pending and unknown writes.)
  • Persistence regression fixture keeps the original intent (1e7da04: The earlier test consolidation retained distinct authority and persistence assertions; replacing a hard-coded key write with the production operation preserves the rename-revocation scenario.)

Testing

Proof path: shipped entry point.

Security

Needs attention: The persisted revocation-key cutover needs final-effect denial proof for revoked discussions.

Evidence

Security concerns:

  • [medium] Validate authority before legacy adoption completes — extensions/clickclack/src/discussions/revoked-channel-store.ts:43
    The synchronous scoped-access provider consults the new key immediately, while legacy adoption begins only through asynchronous store operations. A leftover binding plus its legacy revocation marker is a documented crash-recovery state. The asynchronous access paths await adoption, so this review does not establish a reachable disclosure bypass; the supplied upgrade capture establishes storage preservation only.
    Confidence: 0.93

What I checked:

  • Current main retains the failing key: The current-main revocation owner joins the normalized server URL and channel ID with NUL; the PostgreSQL kernel explicitly rejects NUL-containing keys. (extensions/clickclack/src/discussions/revoked-channel-store.ts:40, f4c7eb489a1f)
  • Introduced migration and capacity failure: Adoption inserts each replacement before deleting its legacy row. The namespace has a 100,000-row reject-new limit, and assertCanInsertPluginStateEntry rejects the temporary extra row. All asynchronous revocation operations await adoption; routing catches its failure and returns revoked. (extensions/clickclack/src/discussions/revoked-channel-store.ts:61, c980afaf3dc0)
  • Authority consumers: The synchronous scoped-access provider reads the hashed key without awaiting adoption. The asynchronous tool-access, routing, and history paths prepare revocation facts first; no final-effect bypass was established by inspection. (extensions/clickclack/src/discussions/register.ts:60, c980afaf3dc0)
  • Inspected product and upgrade captures: The linked before.txt and after.txt captures show the real Gateway discussion-open method failing on base and succeeding on head against PostgreSQL with a fake ClickClack server. upgrade.txt shows v2026.10.9 creating a SQLite marker and the head preserving its value under the hashed key. The captures do not exercise denied access from the revoked room. (20261030-184919-clickclack-revoked-channel-nul-key/upgrade.txt)
  • Failing test-line gate: Exact-head check annotations identify test-lines as the failing baseline ratchet. The patch adds net 98 test lines without the scoped allocation required by the test-authoring guide. Downloading the full job log was blocked by the network allowlist. Public docs: docs/help/testing/writing-tests.md. (docs/help/testing/writing-tests.md:34, c980afaf3dc0)
  • Feature history and intent: History traces the key to the original discussion implementation and subsequent worker-state and published-authority work. The published-authority change explicitly preserves denial during pending or unknown writes. Some service and routing blame reads encountered unavailable historical blobs; introduction claims are limited to the independently verified revocation-store history. (extensions/clickclack/src/discussions/revoked-channel-store.ts:40, 5420c5c409cd)

Likely related people:

  • Peter Steinberger: Raw commit 5420c5c adds extensions/clickclack/src/discussions/revoked-channel-store.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5420c5c409cd; files: extensions/clickclack/src/discussions/revoked-channel-store.ts)

PR surface

Source +34, Tests +99, Other +1. Total +134 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 35 1 +34
Tests 3 111 12 +99
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 5 147 13 +134

Labels

Label changes:

  • add P2: The PR repairs discussion-room operations for PostgreSQL state, a bounded plugin workflow.
  • add merge-risk: 🚨 compatibility: The migration changes persisted marker keys and fails for a valid full SQLite namespace.
  • add merge-risk: 🚨 security-boundary: Revocation markers govern session access, and synchronous access switches to the new key before migration is guaranteed complete.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: The PR repairs discussion-room operations for PostgreSQL state, a bounded plugin workflow.
  • merge-risk: 🚨 compatibility: The migration changes persisted marker keys and fails for a valid full SQLite namespace.
  • merge-risk: 🚨 security-boundary: Revocation markers govern session access, and synchronous access switches to the new key before migration is guaranteed complete.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Add final-effect proof that an upgraded revoked discussion cannot read or send to its former attached session before or during adoption.

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 October 30, 2026, 3:48 PM ET / 19:48 UTC.

Start legacy marker adoption during registration and keep synchronous authorization closed until it succeeds. Preserve async retry after failed adoption and cover the pending-to-complete transition.
@steipete
steipete merged commit 5905912 into openclaw:main Oct 30, 2026
141 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
… on PostgreSQL (openclaw#188643)

* fix(clickclack): use a PostgreSQL-safe revoked-channel key

The revoked discussion channel store keyed markers by the server URL and
channel id joined with NUL. PostgreSQL plugin state rejects NUL in keys, so
opening a discussion room failed with PLUGIN_STATE_INVALID_INPUT after the
room was created, and close and cleanup failed the same way. Key markers by a
sha256 prefix of the encoded pair, and adopt markers still stored under the NUL
key (SQLite only) once per runtime by listing the namespace.

* fix(clickclack): deny access until revocation adoption completes

Start legacy marker adoption during registration and keep synchronous authorization closed until it succeeds. Preserve async retry after failed adoption and cover the pending-to-complete transition.

* test(clickclack): allocate the full revocation regression coverage

---------

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

Labels

extensions: clickclack merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClickClack discussion rooms fail to open with "PostgreSQL plugin state keys cannot contain NUL characters" when plugin state runs on PostgreSQL

2 participants