feat: harden community production foundation through story 1.5

This commit is contained in:
2026-08-14 00:21:59 +03:00
parent c30461cc92
commit f6fc2e5c9b
161 changed files with 16758 additions and 2515 deletions
+5 -119
View File
@@ -130,7 +130,11 @@ pub struct PostgresTransportSessionStore {
impl PostgresTransportSessionStore {
pub async fn from_pool(pool: PgPool) -> Result<Self, SessionStoreError> {
apply_postgres_migrations(&pool).await?;
crank_registry::MigrationAuthority::require_current(&pool)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
Ok(Self { pool })
}
@@ -413,124 +417,6 @@ impl TransportSessionStore for PostgresTransportSessionStore {
}
}
async fn apply_postgres_migrations(pool: &PgPool) -> Result<(), SessionStoreError> {
let mut transaction = pool.begin().await.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query("select pg_advisory_xact_lock($1)")
.bind(0x4352_414E_4B4D_4350_i64)
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query(
"create table if not exists __crank_mcp_migrations (
version integer primary key,
checksum text not null,
applied_at timestamptz not null default now()
)",
)
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
let applied = query("select checksum from __crank_mcp_migrations where version = 1")
.fetch_optional(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
if let Some(row) = applied {
let checksum = row.get::<String, _>("checksum");
if checksum != "mcp-transport-sessions-v1" {
return Err(SessionStoreError {
details: format!("modified MCP migration version 1: {checksum}"),
});
}
transaction
.commit()
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
return Ok(());
}
query(
"create table if not exists mcp_transport_sessions (
id text primary key,
protocol_version text not null,
initialized boolean not null default false,
supports_elicitation boolean not null default false,
workspace_slug text not null,
agent_slug text not null,
created_at timestamptz not null,
updated_at timestamptz not null,
expires_at timestamptz null
)",
)
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query("alter table mcp_transport_sessions add column if not exists supports_elicitation boolean not null default false")
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query(
"alter table mcp_transport_sessions add column if not exists expires_at timestamptz null",
)
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query(
"create index if not exists mcp_transport_sessions_workspace_agent_idx
on mcp_transport_sessions(workspace_slug, agent_slug, updated_at desc)",
)
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query(
"create index if not exists mcp_transport_sessions_expires_at_idx
on mcp_transport_sessions(expires_at)
where expires_at is not null",
)
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
query("insert into __crank_mcp_migrations (version, checksum) values (1, $1)")
.bind("mcp-transport-sessions-v1")
.execute(&mut *transaction)
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
transaction
.commit()
.await
.map_err(|error| SessionStoreError {
details: error.to_string(),
})?;
Ok(())
}
fn is_expired(session: &SessionState, now: OffsetDateTime) -> bool {
session
.expires_at