mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-18 16:06:47 +00:00
fix(accounts): avoid provider catalog waits when saving (#260)
Publish committed account and permission facts using the current model catalog when the extension set is unchanged. Preempt an in-flight background catalog reconciliation when another configuration commit arrives, then retry catalog refresh later without losing deferred revision notifications. Let account editors confirm successful saves before reloading lists and groups. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -363,6 +363,21 @@ impl RuntimeSnapshotCompiler {
|
||||
|
||||
/// 读取一个 revision,并为已注册 Provider 查询实时模型目录。
|
||||
pub async fn compile(&self) -> Result<RuntimeSnapshot, RuntimeSnapshotCompileError> {
|
||||
self.compile_inner(None).await
|
||||
}
|
||||
|
||||
/// 配置提交复用同一扩展集合的已发布目录,目录留待对账刷新。
|
||||
pub(crate) async fn compile_with_cached_catalog(
|
||||
&self,
|
||||
previous: &RuntimeSnapshot,
|
||||
) -> Result<RuntimeSnapshot, RuntimeSnapshotCompileError> {
|
||||
self.compile_inner(Some(previous)).await
|
||||
}
|
||||
|
||||
async fn compile_inner(
|
||||
&self,
|
||||
previous: Option<&RuntimeSnapshot>,
|
||||
) -> Result<RuntimeSnapshot, RuntimeSnapshotCompileError> {
|
||||
// 同一配置 revision 的目录稳定性重试必须复用且强持有同一个扩展集合。
|
||||
// 否则一次动态目录发布会让临时候选在下一轮前析构,随后重复 prepare
|
||||
// 得到新的初始目录代次,稳定性检查永远无法收敛。
|
||||
@@ -404,8 +419,11 @@ impl RuntimeSnapshotCompiler {
|
||||
let catalogs = self.catalogs_for_extensions(extensions.as_ref())?;
|
||||
let catalog_generations = catalogs.catalog_generations();
|
||||
let provider_kinds = catalog_generations.keys().cloned().collect();
|
||||
let cached = previous.filter(|previous| {
|
||||
previous.extensions().map(|set| set.id()) == extensions.as_ref().map(|set| set.id())
|
||||
});
|
||||
let snapshot =
|
||||
compile_runtime_snapshot(facts, catalogs.as_ref(), provider_kinds).await?;
|
||||
compile_runtime_snapshot(facts, catalogs.as_ref(), provider_kinds, cached).await?;
|
||||
let observed_generations = catalogs.catalog_generations();
|
||||
if catalog_generations == observed_generations {
|
||||
if extensions.is_some()
|
||||
@@ -419,7 +437,11 @@ impl RuntimeSnapshotCompiler {
|
||||
return Err(RuntimeSnapshotCompileError::RevisionChanged);
|
||||
}
|
||||
return Ok(snapshot
|
||||
.with_provider_catalog_generations(observed_generations)
|
||||
.with_provider_catalog_generations(if cached.is_some() {
|
||||
BTreeMap::new()
|
||||
} else {
|
||||
observed_generations
|
||||
})
|
||||
.with_extensions(extensions));
|
||||
}
|
||||
}
|
||||
@@ -431,11 +453,32 @@ async fn compile_runtime_snapshot(
|
||||
facts: SnapshotFacts,
|
||||
catalogs: &dyn ProviderCatalogPort,
|
||||
provider_kinds: Vec<ProviderKind>,
|
||||
previous: Option<&RuntimeSnapshot>,
|
||||
) -> Result<RuntimeSnapshot, RuntimeSnapshotCompileError> {
|
||||
// 只有成功取得的完整目录能证明模型缺项;发现型目录和查询失败均交由上游验证。
|
||||
let mut provider_models = Vec::new();
|
||||
let mut exhaustive_provider_catalogs = BTreeSet::new();
|
||||
for provider in &provider_kinds {
|
||||
if let Some(previous) = previous {
|
||||
if previous.exhaustive_provider_catalogs.contains(provider) {
|
||||
exhaustive_provider_catalogs.insert(provider.clone());
|
||||
}
|
||||
if let Some(models) = previous.provider_models.get(provider) {
|
||||
provider_models.extend(models.iter().map(|(model, capabilities)| {
|
||||
let compiled =
|
||||
ProviderModel::new(provider.clone(), model.clone(), capabilities.clone());
|
||||
match previous
|
||||
.provider_model_presentations
|
||||
.get(provider)
|
||||
.and_then(|presentations| presentations.get(model))
|
||||
{
|
||||
Some(presentation) => compiled.with_presentation(presentation.clone()),
|
||||
None => compiled,
|
||||
}
|
||||
}));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let Ok(models) = catalogs.query_model_capabilities(provider).await else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
pub mod extensions;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::{Arc, Mutex as SyncMutex, RwLock};
|
||||
use std::time::Duration;
|
||||
@@ -226,6 +227,78 @@ impl Drop for DeferredScheduleGuard {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct RefreshPriorityState {
|
||||
pending_commits: usize,
|
||||
active_background: Option<CancellationToken>,
|
||||
}
|
||||
|
||||
struct CommittedRefreshGuard {
|
||||
priority: Arc<SyncMutex<RefreshPriorityState>>,
|
||||
}
|
||||
|
||||
impl CommittedRefreshGuard {
|
||||
fn begin(priority: Arc<SyncMutex<RefreshPriorityState>>) -> Self {
|
||||
let active = {
|
||||
let mut state = lock_unpoisoned(&priority);
|
||||
state.pending_commits += 1;
|
||||
state.active_background.clone()
|
||||
};
|
||||
// 先登记待发布提交,再取消正在等待目录的后台刷新,避免后者抢先重入。
|
||||
if let Some(active) = active {
|
||||
active.cancel();
|
||||
}
|
||||
Self { priority }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for CommittedRefreshGuard {
|
||||
fn drop(&mut self) {
|
||||
lock_unpoisoned(&self.priority).pending_commits -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
struct BackgroundRefreshGuard {
|
||||
priority: Arc<SyncMutex<RefreshPriorityState>>,
|
||||
cancellation: CancellationToken,
|
||||
}
|
||||
|
||||
impl BackgroundRefreshGuard {
|
||||
fn begin(priority: Arc<SyncMutex<RefreshPriorityState>>) -> Option<Self> {
|
||||
let mut state = lock_unpoisoned(&priority);
|
||||
if state.pending_commits != 0 {
|
||||
return None;
|
||||
}
|
||||
let cancellation = CancellationToken::new();
|
||||
state.active_background = Some(cancellation.clone());
|
||||
drop(state);
|
||||
Some(Self {
|
||||
priority,
|
||||
cancellation,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for BackgroundRefreshGuard {
|
||||
fn drop(&mut self) {
|
||||
lock_unpoisoned(&self.priority).active_background = None;
|
||||
}
|
||||
}
|
||||
|
||||
// 仅中断未完成的读取/编译;发布及延迟通知仍在刷新锁内完成,避免丢失提交。
|
||||
async fn preempt_for_committed_refresh<T>(
|
||||
cancellation: &CancellationToken,
|
||||
operation: impl Future<Output = T>,
|
||||
) -> Result<T, RuntimeSnapshotCompileError> {
|
||||
let cancelled = cancellation.cancelled().fuse();
|
||||
let operation = operation.fuse();
|
||||
pin_mut!(cancelled, operation);
|
||||
select_biased! {
|
||||
_ = cancelled => Err(RuntimeSnapshotCompileError::RevisionChanged),
|
||||
result = operation => Ok(result),
|
||||
}
|
||||
}
|
||||
|
||||
/// 配置提交后的本进程快照发布与跨进程失效通知。
|
||||
#[derive(Clone)]
|
||||
pub struct RuntimeSnapshotPublisher {
|
||||
@@ -234,11 +307,13 @@ pub struct RuntimeSnapshotPublisher {
|
||||
subscriptions: Arc<dyn SnapshotSubscriptionPort>,
|
||||
refresh_lock: Arc<Mutex<()>>,
|
||||
deferred: Arc<SyncMutex<DeferredPublicationState>>,
|
||||
refresh_priority: Arc<SyncMutex<RefreshPriorityState>>,
|
||||
}
|
||||
|
||||
enum RefreshMode {
|
||||
Required,
|
||||
Reconcile,
|
||||
Committed,
|
||||
}
|
||||
|
||||
impl RuntimeSnapshotPublisher {
|
||||
@@ -254,6 +329,7 @@ impl RuntimeSnapshotPublisher {
|
||||
subscriptions,
|
||||
refresh_lock: Arc::new(Mutex::new(())),
|
||||
deferred: Arc::new(SyncMutex::new(DeferredPublicationState::default())),
|
||||
refresh_priority: Arc::new(SyncMutex::new(RefreshPriorityState::default())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,27 +342,42 @@ impl RuntimeSnapshotPublisher {
|
||||
&self,
|
||||
mode: RefreshMode,
|
||||
) -> Result<ConfigRevision, RuntimeSnapshotCompileError> {
|
||||
// 所有入口共享从读取事实到发布或暂停的完整临界区;只锁最后的替换会让
|
||||
// 旧编译覆盖新授权,或让晚到的失败暂停新快照。请求读取不等待此锁。
|
||||
// 提交先登记并中断慢后台读取;发布/暂停仍在完整临界区内串行执行。
|
||||
let _committed = matches!(mode, RefreshMode::Committed)
|
||||
.then(|| CommittedRefreshGuard::begin(Arc::clone(&self.refresh_priority)));
|
||||
let _refresh = self.refresh_lock.lock().await;
|
||||
self.refresh_locked(mode).await
|
||||
self.refresh_locked_with_priority(mode).await
|
||||
}
|
||||
|
||||
async fn refresh_locked_with_priority(
|
||||
&self,
|
||||
mode: RefreshMode,
|
||||
) -> Result<ConfigRevision, RuntimeSnapshotCompileError> {
|
||||
if matches!(mode, RefreshMode::Committed) {
|
||||
return self.refresh_locked(mode, None).await;
|
||||
}
|
||||
let background = BackgroundRefreshGuard::begin(Arc::clone(&self.refresh_priority))
|
||||
.ok_or(RuntimeSnapshotCompileError::RevisionChanged)?;
|
||||
self.refresh_locked(mode, Some(&background.cancellation))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn refresh_locked(
|
||||
&self,
|
||||
mode: RefreshMode,
|
||||
cancellation: Option<&CancellationToken>,
|
||||
) -> Result<ConfigRevision, RuntimeSnapshotCompileError> {
|
||||
let mut active = ActiveRefreshGuard::begin(Arc::clone(&self.deferred));
|
||||
let configuration_changed = if matches!(mode, RefreshMode::Reconcile) {
|
||||
let persisted_revision = self
|
||||
.compiler
|
||||
.store()
|
||||
.current_config_revision()
|
||||
.await
|
||||
.map_err(|_| {
|
||||
self.snapshots.suspend();
|
||||
RuntimeSnapshotCompileError::StoreUnavailable
|
||||
})?;
|
||||
let persisted_revision = preempt_for_committed_refresh(
|
||||
cancellation.expect("background refresh cancellation"),
|
||||
self.compiler.store().current_config_revision(),
|
||||
)
|
||||
.await?
|
||||
.map_err(|_| {
|
||||
self.snapshots.suspend();
|
||||
RuntimeSnapshotCompileError::StoreUnavailable
|
||||
})?;
|
||||
let changed = runtime_revision_needs_refresh(
|
||||
self.published_revision().map(ConfigRevision::get),
|
||||
persisted_revision.get(),
|
||||
@@ -307,7 +398,19 @@ impl RuntimeSnapshotPublisher {
|
||||
true
|
||||
};
|
||||
for attempt in 0..MAXIMUM_DEFERRED_REFRESH_ATTEMPTS {
|
||||
let snapshot = match self.compiler.compile().await {
|
||||
let compiled = if matches!(mode, RefreshMode::Committed) {
|
||||
match self.snapshots.snapshot_for_diagnostics() {
|
||||
Some(previous) => self.compiler.compile_with_cached_catalog(&previous).await,
|
||||
None => self.compiler.compile().await,
|
||||
}
|
||||
} else {
|
||||
preempt_for_committed_refresh(
|
||||
cancellation.expect("background refresh cancellation"),
|
||||
self.compiler.compile(),
|
||||
)
|
||||
.await?
|
||||
};
|
||||
let snapshot = match compiled {
|
||||
Ok(snapshot) => snapshot,
|
||||
Err(RuntimeSnapshotCompileError::RevisionChanged)
|
||||
if attempt + 1 < MAXIMUM_DEFERRED_REFRESH_ATTEMPTS =>
|
||||
@@ -389,7 +492,10 @@ impl RuntimeSnapshotPublisher {
|
||||
if !has_pending {
|
||||
return;
|
||||
}
|
||||
if let Err(error) = self.refresh_locked(RefreshMode::Required).await {
|
||||
if let Err(error) = self
|
||||
.refresh_locked_with_priority(RefreshMode::Required)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(?error, "deferred runtime snapshot publication failed");
|
||||
}
|
||||
}
|
||||
@@ -412,7 +518,7 @@ impl RuntimeSnapshotPublisher {
|
||||
|
||||
/// 数据库提交不能被目录或通知基础设施的暂时故障伪装成回滚。
|
||||
async fn publish_committed_inner(&self, committed_revision: ConfigRevision) {
|
||||
if let Err(error) = self.refresh().await {
|
||||
if let Err(error) = self.refresh_with_mode(RefreshMode::Committed).await {
|
||||
tracing::warn!(?error, "committed runtime snapshot refresh failed");
|
||||
}
|
||||
self.notify_committed_revision(committed_revision).await;
|
||||
|
||||
@@ -18,8 +18,9 @@ use gateway_core::routing::snapshot::{
|
||||
SnapshotStoreError, SnapshotStorePort,
|
||||
};
|
||||
use gateway_core::routing::{
|
||||
AccountGroupId, ConfigRevision, ProviderCatalogGeneration, ProviderCatalogPort,
|
||||
ProviderCatalogUnavailable, ProviderKind, ProviderModelCapabilities, RuntimeSnapshot,
|
||||
AccountGroupId, ConfigRevision, ModelCapabilities, ProviderCatalogGeneration,
|
||||
ProviderCatalogPort, ProviderCatalogUnavailable, ProviderKind, ProviderModelCapabilities,
|
||||
RuntimeSnapshot, UpstreamModelId,
|
||||
};
|
||||
use gateway_core::runtime::{
|
||||
RuntimeSnapshotHandle, RuntimeSnapshotPublisher, SnapshotControl, SnapshotRevisionStream,
|
||||
@@ -162,6 +163,119 @@ fn publisher_should_refresh_locally_and_notify_committed_revision() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn committed_account_change_should_publish_without_waiting_for_provider_catalog() {
|
||||
block_on(async {
|
||||
let store = Arc::new(TestSnapshotStore::new(Ok(scoped_facts(9, true))));
|
||||
let catalog = Arc::new(TestCatalog::default());
|
||||
catalog
|
||||
.models
|
||||
.lock()
|
||||
.expect("models lock")
|
||||
.push(ProviderModelCapabilities::new(
|
||||
UpstreamModelId::new("listed-model").expect("model"),
|
||||
ModelCapabilities::new(Default::default(), None),
|
||||
));
|
||||
let compiler = Arc::new(catalog_compiler(store.clone(), catalog.clone()));
|
||||
let initial = compiler.compile().await.expect("initial snapshot");
|
||||
let provider = ProviderKind::new("audit").expect("provider");
|
||||
let initial_models = initial.public_models_for_provider(&provider);
|
||||
let handle = RuntimeSnapshotHandle::new(initial);
|
||||
let publisher = RuntimeSnapshotPublisher::new(
|
||||
compiler,
|
||||
handle.clone(),
|
||||
Arc::new(TestSnapshotSubscriptions::default()),
|
||||
);
|
||||
*store.facts.lock().expect("facts lock") = Ok(scoped_facts(10, false));
|
||||
*store.current_revision.lock().expect("revision lock") = Ok(revision(10));
|
||||
let (release, gate) = oneshot::channel();
|
||||
*catalog.next_query.lock().expect("catalog gate lock") = Some(gate);
|
||||
|
||||
publisher.publish_committed(revision(10)).await;
|
||||
let committed = handle.acquire().expect("committed snapshot");
|
||||
assert_eq!(committed.revision(), revision(10));
|
||||
assert!(!removed_account_allowed(&committed));
|
||||
assert_eq!(
|
||||
committed.public_models_for_provider(&provider),
|
||||
initial_models
|
||||
);
|
||||
assert_eq!(catalog.queries.load(Ordering::SeqCst), 1);
|
||||
assert_ne!(
|
||||
committed.provider_catalog_generations(),
|
||||
&catalog.catalog_generations(),
|
||||
);
|
||||
|
||||
let mut reconcile = Box::pin(publisher.refresh());
|
||||
assert!(futures::poll!(reconcile.as_mut()).is_pending());
|
||||
release.send(()).expect("release catalog query");
|
||||
reconcile.await.expect("catalog reconciliation");
|
||||
assert_eq!(
|
||||
handle
|
||||
.acquire()
|
||||
.expect("reconciled snapshot")
|
||||
.provider_catalog_generations(),
|
||||
&catalog.catalog_generations(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn committed_account_change_should_preempt_inflight_catalog_reconciliation() {
|
||||
block_on(async {
|
||||
let store = Arc::new(TestSnapshotStore::new(Ok(scoped_facts(9, true))));
|
||||
let catalog = Arc::new(TestCatalog::default());
|
||||
let compiler = Arc::new(catalog_compiler(store.clone(), catalog.clone()));
|
||||
let initial = compiler.compile().await.expect("initial snapshot");
|
||||
let handle = RuntimeSnapshotHandle::new(initial);
|
||||
let publisher = RuntimeSnapshotPublisher::new(
|
||||
compiler,
|
||||
handle.clone(),
|
||||
Arc::new(TestSnapshotSubscriptions::default()),
|
||||
);
|
||||
|
||||
// 首次提交复用目录,随后对账停在慢 Provider 查询;下一次提交仍须及时撤权。
|
||||
*store.facts.lock().expect("facts lock") = Ok(scoped_facts(10, true));
|
||||
*store.current_revision.lock().expect("revision lock") = Ok(revision(10));
|
||||
publisher.publish_committed(revision(10)).await;
|
||||
let (release, gate) = oneshot::channel();
|
||||
*catalog.next_query.lock().expect("catalog gate lock") = Some(gate);
|
||||
let (task, context) = reconciliation_task(&publisher);
|
||||
let mut reconcile = task.run_cycle(context.clone());
|
||||
assert!(futures::poll!(reconcile.as_mut()).is_pending());
|
||||
assert_eq!(catalog.queries.load(Ordering::SeqCst), 2);
|
||||
|
||||
*store.facts.lock().expect("facts lock") = Ok(scoped_facts(11, false));
|
||||
*store.current_revision.lock().expect("revision lock") = Ok(revision(11));
|
||||
let mut committed = publisher.publish_committed(revision(11));
|
||||
assert!(futures::poll!(committed.as_mut()).is_pending());
|
||||
assert!(matches!(
|
||||
futures::poll!(reconcile.as_mut()),
|
||||
std::task::Poll::Ready(Err(_)),
|
||||
));
|
||||
assert_eq!(
|
||||
futures::poll!(committed.as_mut()),
|
||||
std::task::Poll::Ready(()),
|
||||
);
|
||||
assert!(release.send(()).is_err());
|
||||
let current = handle.acquire().expect("committed snapshot");
|
||||
assert_eq!(current.revision(), revision(11));
|
||||
assert!(!removed_account_allowed(¤t));
|
||||
assert_ne!(
|
||||
current.provider_catalog_generations(),
|
||||
&catalog.catalog_generations(),
|
||||
);
|
||||
|
||||
task.run_cycle(context).await.expect("next reconciliation");
|
||||
assert_eq!(
|
||||
handle
|
||||
.acquire()
|
||||
.expect("reconciled snapshot")
|
||||
.provider_catalog_generations(),
|
||||
&catalog.catalog_generations(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn publisher_should_suspend_but_still_notify_after_committed_refresh_failure() {
|
||||
let store = Arc::new(TestSnapshotStore::new(Err(
|
||||
@@ -221,6 +335,46 @@ fn deferred_commit_during_refresh_should_retry_the_latest_revision_without_reent
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preempted_deferred_refresh_should_preserve_its_revision_notification() {
|
||||
block_on(async {
|
||||
let store = Arc::new(TestSnapshotStore::new(Ok(scoped_facts(10, true))));
|
||||
let catalog = Arc::new(TestCatalog::default());
|
||||
let (release, gate) = oneshot::channel();
|
||||
*catalog.next_query.lock().expect("catalog gate lock") = Some(gate);
|
||||
let handle = RuntimeSnapshotHandle::new(empty_snapshot(9));
|
||||
let subscriptions = Arc::new(TestSnapshotSubscriptions::default());
|
||||
let publisher = RuntimeSnapshotPublisher::new(
|
||||
Arc::new(catalog_compiler(store.clone(), catalog)),
|
||||
handle.clone(),
|
||||
subscriptions.clone(),
|
||||
);
|
||||
|
||||
let mut deferred = publisher.publish_committed_deferred(revision(10));
|
||||
assert!(futures::poll!(deferred.as_mut()).is_pending());
|
||||
*store.facts.lock().expect("facts lock") = Ok(scoped_facts(11, false));
|
||||
*store.current_revision.lock().expect("revision lock") = Ok(revision(11));
|
||||
let mut committed = publisher.publish_committed(revision(11));
|
||||
assert!(futures::poll!(committed.as_mut()).is_pending());
|
||||
assert_eq!(
|
||||
futures::poll!(deferred.as_mut()),
|
||||
std::task::Poll::Ready(())
|
||||
);
|
||||
assert_eq!(
|
||||
futures::poll!(committed.as_mut()),
|
||||
std::task::Poll::Ready(()),
|
||||
);
|
||||
assert!(release.send(()).is_err());
|
||||
let current = handle.acquire().expect("committed snapshot");
|
||||
assert_eq!(current.revision(), revision(11));
|
||||
assert!(!removed_account_allowed(¤t));
|
||||
assert_eq!(
|
||||
*subscriptions.published.lock().expect("published lock"),
|
||||
vec![revision(10), revision(11)],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deferred_commit_at_refresh_completion_should_not_lose_the_next_publication() {
|
||||
block_on(async {
|
||||
@@ -389,15 +543,22 @@ fn reconciliation_revision_failure_should_not_suspend_later_committed_refresh()
|
||||
assert!(futures::poll!(reconcile.as_mut()).is_pending());
|
||||
let mut committed = publisher.publish_committed(revision(11));
|
||||
assert!(futures::poll!(committed.as_mut()).is_pending());
|
||||
assert_eq!(store.loads.load(Ordering::SeqCst), 0);
|
||||
|
||||
release
|
||||
.send(Err(SnapshotStoreError::unavailable()))
|
||||
.expect("release failed revision read");
|
||||
assert!(reconcile.await.is_err());
|
||||
assert!(handle.acquire().is_err());
|
||||
committed.await;
|
||||
assert!(matches!(
|
||||
futures::poll!(reconcile.as_mut()),
|
||||
std::task::Poll::Ready(Err(_)),
|
||||
));
|
||||
assert_eq!(
|
||||
futures::poll!(committed.as_mut()),
|
||||
std::task::Poll::Ready(()),
|
||||
);
|
||||
assert!(
|
||||
release
|
||||
.send(Err(SnapshotStoreError::unavailable()))
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(store.loads.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(handle.revision(), Some(revision(11)));
|
||||
assert!(handle.acquire().is_ok());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -613,6 +774,7 @@ struct TestCatalog {
|
||||
generation: AtomicU64,
|
||||
queries: AtomicUsize,
|
||||
next_query: Mutex<Option<oneshot::Receiver<()>>>,
|
||||
models: Mutex<Vec<ProviderModelCapabilities>>,
|
||||
}
|
||||
|
||||
impl ProviderCatalogPort for TestCatalog {
|
||||
@@ -633,7 +795,7 @@ impl ProviderCatalogPort for TestCatalog {
|
||||
if let Some(gate) = gate {
|
||||
gate.await.expect("release catalog query");
|
||||
}
|
||||
Ok(Vec::new())
|
||||
Ok(self.models.lock().expect("models lock").clone())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,6 +543,8 @@ HTTP validation
|
||||
revision;credential 轮换只推进账号自己的 `credential_revision`。Redis 通知用于缩短收敛延迟,
|
||||
PostgreSQL 周期对账才是正确性基础。
|
||||
|
||||
管理提交重读持久化配置;扩展集合未变化时复用已发布的模型目录,先发布新的账号与权限事实,目录代次留待订阅任务或周期对账从 Provider 刷新,避免上游目录请求阻塞管理响应。
|
||||
新提交会中断正在读取持久版本或编译目录的后台刷新,让提交先取得发布权;被中断的目录对账留待下个周期重试。
|
||||
同一 publisher 的管理提交、订阅通知与周期对账共享编译到发布/暂停的临界区,避免旧结果覆盖新授权或
|
||||
晚到的失败暂停新快照;请求读取不等待刷新锁。对账仍允许持久 revision 回退,不能只比较版本大小。
|
||||
配置不可确认时暂停新请求;仅目录 generation 变化且编译失败时继续使用旧快照,留待下次对账。
|
||||
|
||||
@@ -94,8 +94,8 @@ export function useAccountBatchEditor(options: {
|
||||
})
|
||||
showBatchEditModal.value = false
|
||||
options.selectedIds.value = new Set()
|
||||
await Promise.all([options.reloadAccounts(), options.reloadGroups()])
|
||||
toast.success(`已更新 ${accountIds.length} 个账号`)
|
||||
void Promise.allSettled([options.reloadAccounts(), options.reloadGroups()])
|
||||
}, { onError: () => void options.reloadAccounts() })
|
||||
}
|
||||
|
||||
|
||||
@@ -134,8 +134,8 @@ export function useAccountEditor(options: {
|
||||
: undefined,
|
||||
})
|
||||
showEditModal.value = false
|
||||
await Promise.all([options.reloadAccounts(), options.reloadGroups()])
|
||||
toast.success('账号已更新')
|
||||
void Promise.allSettled([options.reloadAccounts(), options.reloadGroups()])
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user