feat(epic4): безопасные повторы и отмена durable Task (Story 4.4)
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 20m46s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 20m46s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
Durable per-outbound attempt до отправки запроса, bounded retry/read, server-owned verified writes, честный cancel/unknown, deadline/fencing, additive schema v29. Staged renames task.rs/tasks.rs разложены на модули. Includes disclosed cosmetic parity exception: единственная правка вне принятой дельты — удалена лишняя пустая строка в конце scripts/ci-story-checks.sh (EOF blank line); story-код не менялся.
This commit is contained in:
1 parent
8c02380762
commit
a3057de51e
44 files changed
+4547
-815
No files matched your search
@@ -8,6 +8,7 @@ use super::durable_tasks_v25;
|
||||
use super::durable_tasks_v26;
|
||||
use super::durable_tasks_v27;
|
||||
use super::durable_tasks_v28;
|
||||
use super::durable_tasks_v29;
|
||||
use super::execution_admission_v24;
|
||||
use super::execution_outcome_v5;
|
||||
use super::import_plan_v14;
|
||||
@@ -44,10 +45,10 @@ use preflight::*;
|
||||
use contract::baseline_source_digest;
|
||||
use contract::validate_descriptors;
|
||||
const MIGRATION_LOCK_ID: i64 = 0x4352_414E_4B4D_4947;
|
||||
const CURRENT_VERSION: i64 = 28;
|
||||
const CURRENT_VERSION: i64 = 29;
|
||||
const IMPLEMENTED_VERSIONS: &[i64] = &[
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||
27, 28,
|
||||
27, 28, 29,
|
||||
];
|
||||
const BASELINE_SOURCE_SHA256: &str =
|
||||
"eb1656fc5b4b5be9ee390d237d1d58e4b2274ae5ba9b7ba06a2f3f860dfda675";
|
||||
@@ -366,6 +367,12 @@ impl MigrationAuthority {
|
||||
durable_tasks_v28::SOURCE_SHA256,
|
||||
27,
|
||||
),
|
||||
expand_descriptor(
|
||||
29,
|
||||
durable_tasks_v29::NAME,
|
||||
durable_tasks_v29::SOURCE_SHA256,
|
||||
28,
|
||||
),
|
||||
]
|
||||
}
|
||||
pub fn validate_sequence() -> Result<(), MigrationError> {
|
||||
@@ -540,6 +547,9 @@ impl MigrationAuthority {
|
||||
if from < 28 {
|
||||
durable_tasks_v28::apply(&mut transaction, &Self::sequence()[27]).await?;
|
||||
}
|
||||
if from < 29 {
|
||||
durable_tasks_v29::apply(&mut transaction, &Self::sequence()[28]).await?;
|
||||
}
|
||||
match inspect(&mut transaction).await? {
|
||||
MigrationPreflight::Current {
|
||||
version: CURRENT_VERSION,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
use sqlx::{Postgres, Transaction, query};
|
||||
|
||||
use super::authority::{MigrationDescriptor, MigrationError};
|
||||
|
||||
pub(super) const NAME: &str = "durable-tasks-v29";
|
||||
pub(super) const SOURCE: &str = include_str!("durable_tasks_v29.sql");
|
||||
pub(super) const SOURCE_SHA256: &str =
|
||||
"0666c7d2aa440e6aae2170ceaf2fce2549118612e1505ef78817be60436a75dd";
|
||||
|
||||
pub(super) async fn apply(
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
descriptor: &MigrationDescriptor,
|
||||
) -> Result<(), MigrationError> {
|
||||
sqlx::raw_sql(SOURCE)
|
||||
.execute(&mut **transaction)
|
||||
.await
|
||||
.map_err(|_| {
|
||||
MigrationError::new(
|
||||
"apply_failed",
|
||||
"apply.durable_tasks_v29",
|
||||
Some(29),
|
||||
"restore_known_good_backup",
|
||||
)
|
||||
})?;
|
||||
query(
|
||||
"insert into __crank_migrations (version, name, checksum, phase, compatibility)
|
||||
values ($1, $2, $3, $4, $5)",
|
||||
)
|
||||
.bind(descriptor.version)
|
||||
.bind(descriptor.name)
|
||||
.bind(&descriptor.checksum)
|
||||
.bind(descriptor.phase)
|
||||
.bind(descriptor.compatibility)
|
||||
.execute(&mut **transaction)
|
||||
.await
|
||||
.map_err(|_| {
|
||||
MigrationError::new(
|
||||
"apply_failed",
|
||||
"apply.durable_tasks_v29",
|
||||
Some(29),
|
||||
"restore_known_good_backup",
|
||||
)
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
-- V29: durable per-outbound attempt history, pinned retry policy and cancellation (Story 4.4).
|
||||
-- An accepted Task keeps the retry snapshot it was admitted with; legacy Tasks get a single attempt.
|
||||
alter table tasks add column if not exists max_attempts integer not null default 1;
|
||||
alter table tasks add column if not exists retry_backoff_step_ms bigint not null default 0;
|
||||
alter table tasks add column if not exists next_attempt_at timestamptz;
|
||||
alter table tasks add column if not exists cancel_requested_at timestamptz;
|
||||
alter table tasks add column if not exists cancel_reason text;
|
||||
|
||||
alter table tasks add constraint tasks_max_attempts_check check (max_attempts between 1 and 5);
|
||||
alter table tasks add constraint tasks_retry_backoff_step_check
|
||||
check (retry_backoff_step_ms between 0 and 1000);
|
||||
alter table tasks add constraint tasks_cancel_reason_check check (
|
||||
cancel_reason is null or octet_length(cancel_reason) between 1 and 160
|
||||
);
|
||||
|
||||
-- One row per committed outbound attempt. The authoritative outcome of a Task stays on `tasks`;
|
||||
-- this history only records what was attempted and how each attempt resolved.
|
||||
create table if not exists task_attempts (
|
||||
attempt_id text primary key,
|
||||
task_id uuid not null references tasks (task_id) on delete cascade,
|
||||
ordinal integer not null,
|
||||
owner text not null,
|
||||
fence bigint not null default 0,
|
||||
input_fingerprint text not null,
|
||||
upstream_key_digest text,
|
||||
retry_allowed boolean not null default false,
|
||||
checkpoint_at timestamptz not null default now(),
|
||||
resolved_at timestamptz,
|
||||
outcome text,
|
||||
certainty text,
|
||||
phase text,
|
||||
constraint task_attempts_task_ordinal_unique unique (task_id, ordinal),
|
||||
constraint task_attempts_ordinal_check check (ordinal between 1 and 5),
|
||||
constraint task_attempts_outcome_check check (
|
||||
outcome is null
|
||||
or outcome in ('completed', 'failed', 'retry_scheduled', 'outcome_unknown')
|
||||
),
|
||||
constraint task_attempts_certainty_check check (
|
||||
certainty is null or certainty in ('known', 'unknown')
|
||||
),
|
||||
constraint task_attempts_phase_check check (
|
||||
phase is null or phase in ('before_dispatch', 'dispatched')
|
||||
),
|
||||
-- A resolved attempt is complete: an unresolved row carries no resolution at all, so a stale
|
||||
-- writer can never append a second outcome to the same attempt.
|
||||
constraint task_attempts_resolution_check check (
|
||||
(resolved_at is null and outcome is null and certainty is null and phase is null)
|
||||
or (resolved_at is not null and outcome is not null and certainty is not null)
|
||||
)
|
||||
);
|
||||
|
||||
create index if not exists task_attempts_task_id_idx on task_attempts (task_id, ordinal);
|
||||
@@ -489,6 +489,9 @@ pub(super) async fn validate_schema_fingerprint(
|
||||
if !super::schema_guard_v28::validate_v28_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
if !super::schema_guard_v29::validate_v29_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
} else if current_version < 26 {
|
||||
super::schema_guard_v25::validate_v25_durable_tasks(connection).await?;
|
||||
if !super::schema_guard_v26::validate_v26_absent(connection).await? {
|
||||
@@ -497,6 +500,9 @@ pub(super) async fn validate_schema_fingerprint(
|
||||
if !super::schema_guard_v28::validate_v28_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
if !super::schema_guard_v29::validate_v29_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
} else if current_version < 27 {
|
||||
super::schema_guard_v26::validate_v26_durable_tasks(connection).await?;
|
||||
if !super::schema_guard_v27::validate_v27_absent(connection).await? {
|
||||
@@ -505,15 +511,27 @@ pub(super) async fn validate_schema_fingerprint(
|
||||
if !super::schema_guard_v28::validate_v28_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
if !super::schema_guard_v29::validate_v29_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
} else if current_version < 28 {
|
||||
super::schema_guard_v26::validate_v26_base_columns(connection).await?;
|
||||
super::schema_guard_v27::validate_v27_durable_tasks(connection).await?;
|
||||
if !super::schema_guard_v28::validate_v28_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
} else {
|
||||
if !super::schema_guard_v29::validate_v29_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
} else if current_version < 29 {
|
||||
super::schema_guard_v26::validate_v26_base_columns(connection).await?;
|
||||
super::schema_guard_v28::validate_v28_durable_tasks(connection).await?;
|
||||
if !super::schema_guard_v29::validate_v29_absent(connection).await? {
|
||||
return Err(schema_error(current_version));
|
||||
}
|
||||
} else {
|
||||
super::schema_guard_v26::validate_v26_base_columns(connection).await?;
|
||||
super::schema_guard_v29::validate_v29_durable_attempts(connection).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ pub(super) async fn validate_v27_durable_tasks(
|
||||
.map_err(|_| MigrationError::storage("preflight.schema"))?
|
||||
.try_get("count")
|
||||
.map_err(|_| MigrationError::storage("preflight.schema"))?;
|
||||
if count != i64::try_from(37).unwrap_or_default() {
|
||||
if count != 37_i64 {
|
||||
return Err(MigrationError::new(
|
||||
"partial_sequence",
|
||||
"v27.columns",
|
||||
|
||||
@@ -10,10 +10,10 @@ const TASKS: &str = "tasks";
|
||||
pub(super) async fn validate_v28_absent(
|
||||
connection: &mut PgConnection,
|
||||
) -> Result<bool, MigrationError> {
|
||||
if relation_exists(connection, TASKS).await? {
|
||||
if super::schema_guard::column_exists(connection, TASKS, "platform_api_key_id").await? {
|
||||
return Ok(false);
|
||||
}
|
||||
if relation_exists(connection, TASKS).await?
|
||||
&& super::schema_guard::column_exists(connection, TASKS, "platform_api_key_id").await?
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ pub(super) async fn validate_v28_durable_tasks(
|
||||
.map_err(|_| MigrationError::storage("preflight.schema"))?
|
||||
.try_get("count")
|
||||
.map_err(|_| MigrationError::storage("preflight.schema"))?;
|
||||
if count != i64::try_from(38).unwrap_or_default() {
|
||||
if count != 38_i64 {
|
||||
return Err(MigrationError::new(
|
||||
"partial_sequence",
|
||||
"v28.columns",
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//! V29 schema guard: durable per-outbound attempt history, pinned retry policy and cancellation
|
||||
//! (Story 4.4).
|
||||
|
||||
use sqlx::{PgConnection, Row, query};
|
||||
|
||||
use super::authority::MigrationError;
|
||||
use super::schema_guard::{column_exists, relation_exists};
|
||||
|
||||
const TASKS: &str = "tasks";
|
||||
const ATTEMPTS: &str = "task_attempts";
|
||||
|
||||
pub(super) async fn validate_v29_absent(
|
||||
connection: &mut PgConnection,
|
||||
) -> Result<bool, MigrationError> {
|
||||
if relation_exists(connection, TASKS).await? {
|
||||
if column_exists(connection, TASKS, "max_attempts").await? {
|
||||
return Ok(false);
|
||||
}
|
||||
if relation_exists(connection, ATTEMPTS).await? {
|
||||
return Ok(false);
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
pub(super) async fn validate_v29_durable_attempts(
|
||||
connection: &mut PgConnection,
|
||||
) -> Result<(), MigrationError> {
|
||||
// The V28 column set is still required and unchanged; V29 only appends columns and one table.
|
||||
for column in [
|
||||
"platform_api_key_id",
|
||||
"max_attempts",
|
||||
"retry_backoff_step_ms",
|
||||
"next_attempt_at",
|
||||
"cancel_requested_at",
|
||||
"cancel_reason",
|
||||
] {
|
||||
if !column_exists(connection, TASKS, column).await? {
|
||||
return Err(invalid(29, "v29.columns"));
|
||||
}
|
||||
}
|
||||
// Exact total column count for version 29: the 38 V28 columns + 5 V29 columns.
|
||||
let count: i64 = query(
|
||||
"select count(*)::bigint as count from information_schema.columns
|
||||
where table_schema = current_schema() and table_name = $1",
|
||||
)
|
||||
.bind(TASKS)
|
||||
.fetch_one(&mut *connection)
|
||||
.await
|
||||
.map_err(|_| MigrationError::storage("preflight.schema"))?
|
||||
.try_get("count")
|
||||
.map_err(|_| MigrationError::storage("preflight.schema"))?;
|
||||
if count != 43_i64 {
|
||||
return Err(invalid(29, "v29.columns"));
|
||||
}
|
||||
if !relation_exists(connection, ATTEMPTS).await? {
|
||||
return Err(invalid(29, "v29.attempts"));
|
||||
}
|
||||
for column in [
|
||||
"attempt_id",
|
||||
"task_id",
|
||||
"ordinal",
|
||||
"owner",
|
||||
"fence",
|
||||
"input_fingerprint",
|
||||
"upstream_key_digest",
|
||||
"retry_allowed",
|
||||
"checkpoint_at",
|
||||
"resolved_at",
|
||||
"outcome",
|
||||
"certainty",
|
||||
"phase",
|
||||
] {
|
||||
if !column_exists(connection, ATTEMPTS, column).await? {
|
||||
return Err(invalid(29, "v29.attempts"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn invalid(version: i64, stage: &'static str) -> MigrationError {
|
||||
MigrationError::new(
|
||||
"partial_sequence",
|
||||
stage,
|
||||
Some(version),
|
||||
"restore_known_good_backup",
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user