Delete persisted message boards with their root threads (#47029)

## Why

Permanent thread deletion needs to remove persisted agent message board data even when the message board feature has been disabled.

## What changed

- Add a cleanup hook for single and batch thread deletion, invoked after reference and writer checks but before rollout removal so cleanup failures remain retryable.
- Remove the deleted roots' channels, posts, and subscriptions regardless of the current feature setting.
- Record board tombstones and check them within write transactions to prevent delayed writes from recreating deleted data.

## Testing

Add an app-server regression test that creates a board, archives its root thread, restarts with the feature disabled, and verifies that permanent deletion removes the persisted channels, posts, and subscriptions.

GitOrigin-RevId: 4ea71559a8df0814dffda23a056a9bbaf6e0a0cb
This commit is contained in:
jif
2026-09-21 13:28:02 +00:00
committed by copyberry
parent 8a62cc4dc1
commit 73129716c2
6 changed files with 228 additions and 22 deletions
+18 -4
View File
@@ -25,6 +25,7 @@ use crate::tasks::interrupted_turn_history_marker;
use crate::thread_startup_metadata::ThreadStartupMetadata;
use codex_agent_graph_store::AgentGraphStore;
use codex_agent_graph_store::LocalAgentGraphStore;
use codex_agent_message_board_extension::LocalAgentMessageBoard;
use codex_analytics::AnalyticsEventsClient;
use codex_app_server_protocol::ThreadHistoryBuilder;
use codex_app_server_protocol::TurnStatus;
@@ -449,10 +450,23 @@ pub fn thread_store_from_config(
.features
.enabled(Feature::BackgroundPaginatedRolloutMigration);
let has_state_db = state_db.is_some();
let store = Arc::new(LocalThreadStore::new(
LocalThreadStoreConfig::from_config(config),
state_db,
));
let sqlite = config.sqlite_config().clone();
let store = Arc::new(
LocalThreadStore::new(LocalThreadStoreConfig::from_config(config), state_db)
.with_thread_data_cleanup(move |thread_ids| {
let sqlite = sqlite.clone();
Box::pin(async move {
let boards = thread_ids.into_iter().map(Into::into).collect::<Vec<_>>();
LocalAgentMessageBoard::delete_boards(&sqlite, &boards)
.await
.map_err(|err| ThreadStoreError::Internal {
message: format!(
"failed to delete agent message boards: {err}"
),
})
})
}),
);
if has_state_db && background_migration_enabled {
let startup_store = Arc::clone(&store);
let codex_home = config.codex_home.to_path_buf();