Content Guardian Content Guardian
Navigation
← CGS3 AI Portal Overview Features Architecture & CAS Developer Guide Security Model Testing & QA Matrix User Documentation Downloads (Pending)
CGS3 Portal / Content Guardian / Architecture

System Architecture

In-depth technical analysis of byte-exact Compare-And-Swap (CAS), lifecycle decoupling, and guaranteed recovery workflows.

1. Execution Flow & Lifecycle

When an administrator initiates a post cleanup or health audit, the request travels through a strictly ordered pipeline designed to guarantee zero data loss:

END-TO-END TRANSACTION PIPELINE
1. Admin Request → Password Guard Verification (Bcrypt)
2. Capability Check (manage_options) & WP Nonce Verification
3. Single-Use Action Token Validation & Replay Invalidation
4. Acquire Owner-Bound Post Lock (_sl3cg_lock_user_id & timestamp)
5. Revalidate Current DB Content Inside Lock
6. Persist Verifiable Snapshot to Post Meta (_sl3cg_backup_*)
7. Verify Meta Persistence → Fail Closed if unverified
8. Execute Byte-Exact CAS UPDATE query
9. Release Post Lock & Return Structured JSON Response

2. Byte-Exact Atomic Compare-And-Swap (CAS)

In standard MySQL queries, string comparisons like WHERE post_content = %s depend on the column collation. Under case-insensitive or accent-insensitive collations (e.g., utf8mb4_general_ci or utf8mb4_unicode_ci):

  • 'Resume' matches 'Résumé' (accents ignored)
  • 'draft' matches 'Draft' (case ignored)
  • Trailing whitespace differences may be ignored depending on padding settings

If an author made a subtle capitalization or accent fix between preview and cleanup, a standard collation comparison would report that the post has not changed, dangerously overwriting the author's work!

Speedlink3 Content Guardian eliminates this race condition by casting both sides into strict binary strings:

$query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = %s, post_modified = %s, post_modified_gmt = %s WHERE ID = %d AND CAST(post_content AS BINARY) = CAST(%s AS BINARY)", $new_content, $now, $now_gmt, $post_id, $original_content ); $rows_affected = $wpdb->query( $query );

If another author or background process modified even a single byte, accent, or whitespace character, $rows_affected evaluates to 0, the transaction detects the conflict, and returns HTTP 409 Conflict without altering the database.

3. Guaranteed Pre-Update Backup (Fail-Closed)

Speedlink3 Content Guardian strictly enforces that no post is updated without a verified backup snapshot. In earlier legacy implementations, the update function executed SQL first and called add_post_meta() afterwards. If metadata insertion failed (e.g. disk full or meta table locked), the post content was updated without a recoverable snapshot.

Content Guardian enforces a strict Fail-Closed model:

// Step 1: Create backup snapshot before update $backup_key = '_sl3cg_backup_' . time() . '_' . wp_generate_password( 8, false ); $backup_saved = add_post_meta( $post_id, $backup_key, [ 'content' => $original_content, 'timestamp' => time(), 'user_id' => get_current_user_id() ], true ); // Step 2: Validate persistence before proceeding if ( ! $backup_saved || ! get_post_meta( $post_id, $backup_key, true ) ) { // ABORT: Fail closed immediately return new WP_Error( 'backup_failed', 'Could not verify pre-update backup snapshot. Update aborted.' ); } // Step 3: Now and only now execute the atomic CAS update

4. WP-Cron Lifecycle Decoupling

Scheduled tasks such as daily token cleanup and expired lock pruning must execute during normal wp-cron.php executions without requiring an active administrator session.

Content Guardian registers its cron hooks globally across all execution contexts while strictly gating admin UI rendering and AJAX handlers behind capability checks:

// Registered globally on init: add_action( 'sl3cg_daily_cleanup_event', [ $this, 'execute_scheduled_cleanup' ] ); // Registered only in admin context: if ( is_admin() ) { add_action( 'admin_menu', [ $this, 'register_admin_menu' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); }

5. Owner-Bound Post Lock Protocol

When an editor opens a post preview in Content Guardian, an exclusive lock is registered with:

  • _sl3cg_lock_user_id: ID of the reviewing administrator.
  • _sl3cg_lock_timestamp: Expiration window (15 minutes).
  • _sl3cg_lock_token: Cryptographic hash bound to the preview session.

If another user attempts to update the post, the lock check rejects the operation with HTTP 423 Locked or HTTP 409 Conflict.