Skip to content

Add opt-in default CPT conversation store (closes #235)#242

Merged
lezama merged 2 commits into
mainfrom
add/opt-in-default-conversation-store
May 29, 2026
Merged

Add opt-in default CPT conversation store (closes #235)#242
lezama merged 2 commits into
mainfrom
add/opt-in-default-conversation-store

Conversation

@lezama
Copy link
Copy Markdown
Contributor

@lezama lezama commented May 29, 2026

Summary

Ships a WordPress-native default conversation store inside canonical, dormant behind a single filter, resolving the zero-store cold-start friction from #235.

Enable it with one line:

add_filter( 'agents_api_enable_default_conversation_store', '__return_true' );

When enabled, WP_Agent_Cpt_Conversation_Store registers the agents_api_session CPT and provides itself as a fallback on wp_agent_conversation_store at low priority (5) — any host store at the default priority still wins. When not enabled, nothing registers and a vanilla install is unchanged.

Why in canonical behind a flag (not a separate package)

This supersedes the earlier separate-companion direction, per maintainer consensus (@chubes4, @lezama) on the #235 thread:

  • Easier to consume. One composer require wordpress/agents-api + one filter, instead of installing and version-tracking a second tiny plugin.
  • No CPT shipped to every site. The store is dormant by default — a vanilla install has no post type and still returns the no-store error. An off-by-default dormant class is a far smaller WP-core concern than a mandatory session post type, so the core landing path (Convergence audit: merge parallel WordPress agents-api extractions #77) stays clean.
  • No extra package to maintain for ~400 lines.

The store

WP_Agent_Cpt_Conversation_Storewp_posts + wp_postmeta backed (no custom tables), generalized from the openclawp reference. Implements WP_Agent_Principal_Conversation_Store (and therefore WP_Agent_Conversation_Store) plus WP_Agent_Conversation_Lock. Ownership is keyed by (owner_type, owner_key) so audience/token principals are first-class; the int-user methods delegate to the _for_owner variants. Messages JSON in post_content, ownership/workspace/provider-continuity/context in meta, title in post_title. Single-writer lock via atomic add_post_meta($unique) + compare-and-swap reclaim.

Retention is intentionally not shipped — it stays a consumer responsibility so the substrate doesn't become a product runtime.

Changes

  • src/Transcripts/class-wp-agent-cpt-conversation-store.php — the store.
  • src/Transcripts/register-default-conversation-store.php — opt-in registration (CPT on init + filter fallback, both gated on agents_api_enable_default_conversation_store).
  • agents-api.php — require both.
  • register-agents-conversation-session-abilities.php — no-store error now points at the opt-in filter.
  • docs/default-stores-companion.md — records the decision, marks the separate-package direction superseded.
  • tests/cpt-conversation-store-smoke.php — 38 assertions via an in-memory WP shim.

Test plan

  • php tests/cpt-conversation-store-smoke.php — 38 assertions: contract implementation, full CRUD round-trip, user/audience owner isolation, pending-session dedup, lock acquire/release/contention/CAS reclaim.
  • composer test — full suite green (incl. bootstrap source-tree + no-product-prose checks).
  • Reviewer: a wp-env pass on the meta_query/date_query list + dedup paths is worth doing before relying on it in production, since the smoke shims WP_Query.

Closes #235.

lezama and others added 2 commits May 29, 2026 11:48
Ships a WordPress-native default conversation store inside canonical,
dormant behind a single filter, resolving the zero-store cold-start gap
from #235 without imposing a session post type on installs that don't ask
for it.

Enable with:

    add_filter( 'agents_api_enable_default_conversation_store', '__return_true' );

When enabled, WP_Agent_Cpt_Conversation_Store registers the agents_api_session
CPT and provides itself as a fallback on wp_agent_conversation_store at low
priority (5) — any host store at the default priority still wins. When not
enabled, nothing registers and a vanilla install is unchanged, preserving the
contracts-only default and the WP-core landing path: an off-by-default dormant
class is not a mandatory post type.

The store is wp_posts + wp_postmeta backed (no custom tables), generalized
from the openclawp reference. It implements WP_Agent_Principal_Conversation_Store
(and therefore WP_Agent_Conversation_Store) plus WP_Agent_Conversation_Lock;
ownership is keyed by (owner_type, owner_key) so audience/token principals are
first-class, with the int-user methods delegating to the _for_owner variants.

Also updates the no-store error to point at the opt-in filter and records the
decision in docs/default-stores-companion.md (superseding the earlier separate
companion-package direction per maintainer consensus: easier to consume, no
second package to maintain).

Adds tests/cpt-conversation-store-smoke.php: 38 assertions against the canonical
interfaces via an in-memory WP shim — full CRUD round-trip, user/audience owner
isolation, pending-session dedup, and lock acquire/release/CAS reclaim.

Closes #235.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lezama lezama merged commit 244f63f into main May 29, 2026
2 checks passed
@lezama lezama deleted the add/opt-in-default-conversation-store branch May 29, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider a WordPress-native default conversation session store

1 participant