Skip to content

refactor(sdk): await session and preference preparation - #169122

Merged
steipete merged 92 commits into
mainfrom
dbasync/sdkasync-session
Oct 11, 2026
Merged

steipete merged 92 commits into
mainfrom
dbasync/sdkasync-session

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Ordinary session and TTS preparation still reached SQLite on the Gateway thread through synchronous Plugin SDK and owner APIs. This moves those callers to the existing session/shared-state workers and keeps released synchronous SDK signatures as deprecated compatibility APIs, with warnings and documented async replacements.

User Impact

Session metadata, model menus, voice consults, and speech preparation use asynchronous storage reads. Existing plugin signatures remain available, with documented replacements. No schema or update migration is required. An in-flight same-session history fetch may retain its captured history across a concurrent reset; authorization and abort checks remain.

Why This Change Was Made

Design and caller cutover

Blocked callers Synchronous contract Awaited replacement
Discord, Feishu, iMessage, Matrix, Mattermost, Slack, Telegram, WhatsApp, Voice Call, and Codex preparation getSessionEntry / readSessionUpdatedAt Existing getSessionEntryAsync / readSessionUpdatedAtAsync
Native command model inheritance and reply-policy preparation resolveStoredModelOverride resolveStoredModelOverrideAsync with an awaited parent loader
Discord, Slack, and Telegram native verbose menus resolveCommandArgMenu resolveCommandArgMenuAsync
Slack initial stop/title target resolution getConversationSession getConversationSessionAsync
Telegram ambient transcript context readAmbientTranscriptWatermark readAmbientTranscriptWatermarkAsync
Discord thread-close enumeration and Codex pre-archive enumeration listSessionEntries listSessionEntriesAsync through the existing session-summary worker
Gateway TTS, native TTS commands, CLI, synthesis, persona, and status preparation resolveTtsPrefsPath resolveTtsPrefsPathAsync or existing prepared preference facts
Talk consult and initial-history lookup, pending-delivery notice lookup, cron delivery-context lookup, goal/name refresh, ACP transcript preparation, queued transcript target, archive restoration, paired-node skill preparation, and heartbeat publication preparation Internal native session reads Existing worker reads; internal preparation becomes async

The new SDK peers are documented in docs/plugins. Compatibility keeps the existing return types until the next Plugin SDK major. No schema, retained-data, config, update, or service-lifecycle change.

listSessionEntriesAsync is available on session-store-runtime and api.runtime.agent.session. It requires an explicit agentId, accepts optional storePath and env, and always performs a read-only metadata listing. It retains session identity, initialization status, plugin metadata, and derived participants without loading detached saved prompts and other snapshots. Callers needing a complete entry use getSessionEntryAsync. Missing stores remain absent. The released synchronous listing keeps its full contract, with deprecation annotations and a one-time warning; its synchronous hydration/source-capture options are not added to the new metadata API.

The final follow-up closes all five ordinary-read gaps found in the caller census: Discord thread-close listing, Codex pre-archive listing, pending-delivery notice lookup, cron delivery-context lookup, and Talk's initial-history session-ID lookup. Discord retains its expected-session-ID and update-time deletion predicates. Codex retains initialization, pending-supervision, ownership, descendant, and final archive checks. Pending-notice settlement retains its session/intent checks.

Final tool execution, model-lock, command/stop, disclosure, mutation ownership, and deletion checks retain their synchronous authority boundary. In particular, Talk's control callback still reads current policy immediately before execution; asynchronous consultation preparation does not replace that final check. Incognito-owned paths remain with their owner. Remaining live verbose callbacks (agent-runner-helpers and followup-turn-execution) need a separate callback/owner cutover and are not claimed as removed. Deprecated external SDK implementations and real final authority reads also remain; this PR does not claim lexical T1 is zero. The last verified lexical inventory was 215 T1 files / 612 call expressions before and after on the prior source pins; refreshed inventory on this replacement head remains pending. Ordinary remaining owner work is explicit: live verbose callbacks need async callbacks or receipt-updated state; placement recovery needs an awaited construction-time census through listAsync; config health/observation recovery needs its remaining callers to await existing health read/patch operations; raw auth batch upsert needs a physical-target atomic batch with conditional rollback. These are owner-operation gaps, not schema blockers or security exemptions.

Removed duplicate checks and accepted edges

  • Discord/Slack history no longer rereads session identity, lifecycle revision, start time, and tombstone state during recovery. A reset concurrent with recovery can leave the already captured history in that turn; the next turn sees the new session. Abort and live channel policy checks remain.
  • Discord picker pinning no longer repeats its session read. The existing mutation owner decides whether the prepared selection can commit.
  • Slack model-menu preparation no longer runs a synchronous resolution pass to capture the parent key before resolving again. The awaited owner loads the parent directly; a concurrent parent-model edit may appear on the next menu preparation.
  • Telegram no longer rereads a missing row or takes a second plugin-command snapshot. A concurrently created row is observed on the next owner read.
  • TTS no longer repeats admission validation, pending-read currency checks, or file identity capture around an ordinary cached path. An in-flight turn may finish with its already selected preference path; committed owner receipts govern subsequent reads.
  • Name-command projection consumes its committed result instead of rereading the row. The result is the authoritative postimage.
  • Talk routing reuses the prepared source row and delivery context instead of repeating the same preparation. A concurrent routing edit is observed by subsequent preparation.

Evidence

Final committed source is cc7d775616ab507e11ef9244a566d5cc44523cf3, compared with stacked auth base 8286e5eeae59170f5a8fcc091e8d8db34275c5ce (main through 2c543afc5ec2f8aea8ad9753f9a06d941967fdca). Auth and skill-discovery changes in that base are outside this PR's delta. The final five-read follow-up was committed as 136f0a71925ca before integrating the auth base. The merge preserves main's extracted Slack slash-menu-model-context owner and command-history recording. Async stored-model resolution now lives in that owner, with the two-pass parent-key capture removed. It also retains the explicit routed agent ID in Discord picker reads and the async in-process-write regression; main's intentionally removed duplicate parent-pin test stays removed.

Two Codex autoreview rounds completed on the implementation. The first raised the explicitly accepted same-session history edge above; the second found no actionable P0/P1 issues in its reviewed scope. Later changes repair fixtures, close the five ordinary-read gaps through the async metadata listing and existing readers, and integrate the auth base. The reviews remain evidence for their reviewed scopes; no third round or fresh final-head review is claimed.

Owner regressions cover committed parent-model changes, verbose-menu replacement, conversation binding updates and rollback, watermark updates/reset isolation, Talk routing changes, and TTS committed preference updates while checking caller-thread SQL remains absent. The listing regression covers metadata after an owner write, missing-store absence, initialization metadata, omitted saved prompts/private fields, and no host-thread SQL. Discord's stale-list deletion and pending-notice replacement retain their safety assertions.

Focused behavior proof

Remote proof at 05aabfb4b1a63cbe8a9ddb5c5d9b40c418a16987 passed 78 files / 1,311 tests in 1,086.77 seconds, plus three fixture files / 30 tests in 81.40 seconds, with no skips or failures. Both used pnpm test <explicit file list> --maxWorkers=1. Logs, exact commands, source pins, results, and manifests are retained in session-final-remaining and session-final-fixtures. Final-head source-equivalence attribution is being completed; these results are not relabeled as runs of the final commit.

The three fixture replays resolve the concrete failures from session CI: pending-notice tests now wait for actual send entry and reset one-shot mocks; session SDK tests drain each completed case's owned database scopes; cron cancellation waits for the existing onQueued lifecycle event. Assertions, product behavior, timeouts, and worker capacity are unchanged. The other fixture repairs supply the awaited exports and let the Telegram hot-reloaded model-pin case read its real session store. The final Telegram lint correction uses the existing disposable-spy convention and typed async fixture mock; its validation is tracked with final static proof.

Earlier successful files and groups remain proof only where their tests, owning code, and fixture inputs are unchanged. The prior 428-file census is historical evidence. The narrowed replay supplements successful agent.test.ts (57 cases), session-store-runtime.recovery.test.ts (three cases), and session-store-runtime.test.ts (15 cases) from completed CI groups. Auth-only passes do not count as session proof. Two E2E files and final static/API verification remain with the remote proof lane.

The Codex run-attempt.steering.test.ts visible-output/steering failures occur in both auth-base CI and session CI; that test and owner are unchanged by this PR. The 05aab static run passed production types, source contracts, baseline ratchets, general test types, and core test-type groups 1/3/4/5. Its core-2 type failure is the inherited ui/src/components/session-background.browser.test.ts:42 configObject mismatch; its Telegram lint failures were corrected afterward. These are exact-head evidence and named failures, not a claim that every enclosing job passed.

Final measurements and static proof

The expected SDK surface is 3,695 public exports / 2,156 callables / 183 deprecated exports, versus 3,688 / 2,149 / 176 on the auth base: seven session additions/deprecations, including the listing pair. These are the documented deprecate-and-replace allowances; final compiler/API verification is tracked below.

Required evidence Result
Scoped T1 before/after Prior-pin lexical census: 215 files / 612 call expressions → 215 / 612; replacement-head inventory pending. Retained compatibility and the ordinary owner gaps mean this is not a zero-T1 claim
Warmed all-thread statements and requests, median [min–max], three alternating pairs Pending proof-lane result
MAIN statements and per-operation subsystem deltas Pending proof-lane result
Focused tests and affected mock consumers 05aab: 81 files / 1,341 tests passed, zero skips/failures; final reuse attribution and two E2E files pending
Test wall time 78-file replay 1,086.77 s; three-file fixture replay 81.40 s; CI job seconds tracked with final proof
check:changed, type-aware lint, export/source contracts, Madge, Knip Pending final-head result; prior-head results described above
Database-worker T1 and dialect ratchets Pending replacement-head result; prior-pin lexical T1 was unchanged
SDK surface/API diff and runtime API guardrails Pending final compiler/API result

Final tests, static checks, and measurements on the replacement head remain pending. No warmed-turn saving or final-head static pass is claimed before those results arrive. There is no schema, migration, update, plugin-loading, or service-lifecycle change requiring a published-driver update cell.

LOC against the exact auth base: 147 files, +1,362/−854: production/tooling 94 files, +742/−570; tests/support 49 files, +552/−270; docs four files, +68/−14. Test/support totals include the test-mock export baseline.

Expose async skill-command preparation through the existing SDK entries and migrate bundled Discord, Mattermost, Slack, and Telegram callers. Retain deprecated synchronous SDK methods through the next Plugin SDK major with bounded warnings.
Route bundled credential discovery, capability selection, profile writes,
OAuth preparation, and setup reads through the existing auth worker owner.
Preserve canonical versus runtime-overlay selection and current credential
checks at effects. Profile upserts preserve neighboring committed profiles.

Add async SDK peers and migrate bundled callers together. Retain deprecated
synchronous APIs and required legacy provider hooks for external consumers.
Prepare Discord voice provider facts once per room so per-speaker bridge
creation still precedes first-audio capture.

Remove duplicated native-search auth checks, xAI fallback store rereads,
and auth-owner currency checks already covered by prepared read ownership.
Document the accepted snapshot lifetimes and retained native owner gaps.

Release-note context: plugin authors should await the documented async auth,
provider-selection, and TTS APIs; synchronous contracts remain compatible
through the next Plugin SDK major. No schema or retention changes.

Validation so far: two Codex review rounds with compatibility and fixture
findings addressed; formatting and diff checks. Remote behavior/static proof
and alternating SQL measurements follow on this committed head.
Move bundled session, native command, Talk, and TTS preparation through existing worker readers. Add deprecated async replacement pairs for released SDK callers and reuse committed/prepared results instead of repeated bookkeeping reads.

Accept the narrow same-session reset-during-history-fetch edge: an in-flight turn can retain its captured history. Channel policy and abort checks still apply. No schema or update behavior change.
@clawsweeper

clawsweeper Bot commented Oct 11, 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: discord Channel integration: discord channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling channel: feishu Channel integration: feishu extensions: codex labels Oct 11, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Reused prior owner, SDK API, and update-cell proof after conflict-only integration; final static gates passed on c04b8b5. Landed under RELAXED LANDING v4 with hosted CI pending: 2665147fc1c2de4814606c7674e7014d1317ad8d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: codex gateway Gateway runtime 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL 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.

1 participant