Repository navigation
refactor(pairing): store channel pairing state in SQLite - #105802
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73c74b1d8b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const matchingAccountIds = (accountIds[channel] ?? []).filter( | ||
| (accountId) => safeAccountKey(accountId) === accountKey, | ||
| ); |
There was a problem hiding this comment.
Import default-scoped legacy allowlists
When a legacy file is already account-scoped as <channel>-default-allowFrom.json, this resolver only accepts it if default appears in accountIds[channel]. Env-only/default-account installs can have no cfg.channels.<channel> account list even though the runtime still uses the default account, so startup migration leaves the file “unresolved”; since the new runtime no longer reads legacy JSON files, those previously approved senders lose access after upgrade. Treat the default account key as DEFAULT_ACCOUNT_ID for known channels even when it is not configured explicitly.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. Reviewed July 12, 2026, 9:44 PM ET / July 13, 2026, 01:44 UTC. Summary PR surface: Source -9, Tests -354, Docs +5. Total -358 across 17 files. Reproducibility: yes. from source, but not by a live run in this review: current main writes pairing requests and approvals through the legacy JSON store despite existing SQLite tables and the documented database-first boundary. Review metrics: 3 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Make SQLite the sole runtime owner while preserving each recognized legacy request and approval under the exact channel/account identity, leaving ambiguous files untouched, and prove fresh pairing plus representative upgrade cases on a real gateway before merge. Do we have a high-confidence way to reproduce the issue? Yes from source, but not by a live run in this review: current main writes pairing requests and approvals through the legacy JSON store despite existing SQLite tables and the documented database-first boundary. Is this the best way to solve the issue? Yes in direction: moving the canonical runtime state into the existing typed SQLite tables with doctor-owned migration is the narrowest repository-aligned fix, but the exact upgrade implementation still needs real behavior proof before it is safe to merge. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 43901be298b3. Label changesLabel justifications:
Evidence reviewedPR surface: Source -9, Tests -354, Docs +5. Total -358 across 17 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (3 earlier review cycles)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6725971e29
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| (binding) => | ||
| normalizeAgentId(binding.agentId) === targetAgentId && | ||
| binding.match?.channel === channelId && | ||
| typeof binding.match.accountId === "string", | ||
| )?.match.accountId; | ||
| if (typeof boundAccountId === "string" && boundAccountId.trim()) { | ||
| return [[channelId, boundAccountId.trim()]]; |
There was a problem hiding this comment.
Ignore wildcard bindings for default pairing imports
When a config has a channel-wide route binding such as bindings[].match.accountId: "*", this new default-account resolver treats "*" as a concrete account and imports the legacy unscoped <channel>-allowFrom.json rows into SQLite account "*". Wildcard bindings are routing-only channel matches (src/routing/resolve-route.ts:792) and Telegram account selection explicitly ignores them (extensions/telegram/src/account-selection.ts:60), so the gateway still starts/reads the real account such as default; after this migration the approved DM senders sit under an account id runtime never reads and lose access. Skip wildcard/empty binding matches here and fall through to the plugin/default-account resolver.
Useful? React with 👍 / 👎.
|
Land-ready at exact head Proof:
Known proof gaps: none. |
|
Merged via squash.
|
…5802) * refactor(pairing): move channel state to SQLite * fix(pairing): preserve doctor and SDK contracts * fix(pairing): break SQLite storage import cycle * fix(pairing): keep SQLite types outside SDK graph
…ovider headers (R-3)
An unset OPENCLAW_ORGANIZATION_ID makes the config-interpolation path re-emit the
literal ${OPENCLAW_ORGANIZATION_ID} placeholder, which would then ship verbatim
in the cf-aig-metadata header to Cloudflare.
Closes R-3 with a plugin-owned doctor health check registered via
openclaw/plugin-sdk/health — the same seam the policy plugin uses — so it adds
zero core conflict surface. It walks models.providers.*.headers.* and
*.request.headers.* for values referencing an env var that is absent or empty,
and emits an error finding naming the path and the variable. Proven against the
real spawn-seed: org id unset yields one error on the cf-aig-metadata header,
org id set yields none. Registration is unit-tested since no plugin doctor
checks run on a bare dev box to exercise it end to end.
Also adds the first coverage for the spawn-seed itself (5 invariants: main is the
sole agent and the pinned default, the default survives a seat add, every nabu
skill token is an env SecretRef, and the org id reaches Cloudflare only through a
placeholder). Located in the nabu-gateway extension lane, which is already
routed, rather than adding a nabu-integration test project.
Ledger: R-3 fixed; Job 2 measured — upstream is ~20,283 commits ahead with all
38 fork files also changed upstream, so the catch-up is a scheduled merge; and
paired.json->SQLite must NOT be built on our side because upstream already
migrated it (openclaw#105802), so we adopt theirs on catch-up.
Closes #105761
What Problem This Solves
Resolves a problem where channel pairing requests and approved-sender allowlists remained live JSON state under the credentials directory. Runtime reads also continued merging a legacy unscoped allowlist, so pairing was the remaining non-migration exception to SQLite-only runtime state.
Why This Change Was Made
Pairing requests and account-scoped allowlists now use the existing shared SQLite tables and synchronous write transactions. Startup migration and
openclaw doctor --fiximport recognizable legacy JSON files, resolve effective channel defaults through channel contracts, and remove a source only after a successful transactional merge; unreadable, unresolved, or ambiguous files remain in place with a warning. The deprecated SDK path helper remains available only for migration compatibility.User Impact
Pairing approvals and pending requests now have one canonical SQLite owner. Existing recognized JSON state migrates automatically without losing concurrent changes or crossing channel/account boundaries, while ambiguous legacy filenames fail closed for operator review.
Evidence
tbx_01kxcbbnmwqvtr6kwevbqsdcsv(swift-lobster-1c1c)pnpm test src/pairing/pairing-store.test.ts src/infra/state-migrations.channel-pairing.test.ts src/infra/state-migrations.test.ts src/commands/doctor-state-migrations.test.ts— 141 tests passedpnpm test src/pairing/pairing-store-keys.test.ts src/plugins/contracts/plugin-sdk-subpaths.test.ts src/plugin-sdk/channel-pairing.test.ts extensions/telegram/src/state-migrations.test.ts— 32 tests passedpnpm check:changed -- <touched files>— formatting, SDK API/export gates, core/test/extension typechecks, full core/extension lint, database-first guard, import-cycle checks, and pairing guards passed