Skip to main content

ac_algorithm/
submission.rs

1//! Submissions: the intent/result state machine that prevents duplicate and
2//! mismatched sends (C-07, ADR-0005 invariant 4).
3//!
4//! States follow `atcoder-integrated-environment-plan.md` §11: send intent,
5//! in-flight, unknown outcome, judge acceptance, judging, finalized, failed.
6//! A `ResultUnknown` submission is reconciled against official history — it
7//! is never resent unconditionally. Transition enforcement and the actual
8//! send pipeline are owned by issue #21.
9
10use std::time::SystemTime;
11
12use serde::{Deserialize, Serialize};
13
14use crate::ids::{SolutionId, SubmissionId, TaskId};
15use crate::verdict::JudgeVerdict;
16
17/// Lifecycle of a [`Submission`].
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
19pub enum SubmissionState {
20    /// Byte string fixed and send intended, not yet transmitted.
21    Intent,
22    /// Transmission in progress.
23    Transmitting,
24    /// The send outcome is unknown (e.g. connection lost mid-request).
25    /// Reconcile with official history before any resend.
26    ResultUnknown,
27    /// The judge accepted the submission.
28    Accepted,
29    /// The judge is evaluating it.
30    Judging,
31    /// A final verdict was received.
32    Completed,
33    /// The submission failed before or during judging.
34    Failed,
35}
36
37/// A submission record binding intent, fixed bytes, and official result.
38#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
39pub struct Submission {
40    /// Submission identifier.
41    pub id: SubmissionId,
42    /// Task the submission targets.
43    pub task: TaskId,
44    /// Solution snapshot being submitted.
45    pub solution: SolutionId,
46    /// Hash of the exact byte string sent (preview/test/copy/submit agree).
47    pub source_sha256: String,
48    /// Official `AtCoder` language ID selected for the submission.
49    pub language_id: String,
50    /// Current state-machine position.
51    pub state: SubmissionState,
52    /// Final judge verdict once [`SubmissionState::Completed`].
53    pub verdict: Option<JudgeVerdict>,
54    /// Official submission identifier once accepted.
55    pub official_id: Option<String>,
56    /// When the intent was recorded.
57    pub created_at: SystemTime,
58    /// When the record last changed state.
59    pub updated_at: SystemTime,
60}