-
Notifications
You must be signed in to change notification settings - Fork 0
feat(event): refuse TDT/CHRONOS outputs as state transitions #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3fced58
feat(event): refuse TDT/CHRONOS outputs as state transitions
seonghobae 31ca187
test(event): add independent known-identity baseline contract
seonghobae 5e0c6e6
test(event): avoid test-only public constructor
seonghobae 786436a
fix(event): narrow first-story logic to a known-identity baseline
seonghobae 90b1af1
ci(event): verify PR 50 known-identity baseline repair
seonghobae b5ae04f
ci(event): activate PR 50 repair through registered workflow
seonghobae a5e7609
ci(event): allow ready-for-review repair trigger
seonghobae 955e5da
ci(event): preserve protected-main traceability during repair
seonghobae b9de41a
merge(main): reconcile event-intelligence status gates
seonghobae b8b2567
fix(event): align known-identity repair preconditions
seonghobae dc78049
fix(event): restore ADR repair precondition
seonghobae b4e0646
chore(ci): remove completed event repair loop
seonghobae 9e15e9e
Merge current main into event intelligence gates
seonghobae af67f14
docs(adr): align event intelligence maturity
seonghobae fa4dff2
docs: align provider payload maturity evidence
seonghobae 2a29e24
test(event): cover every intelligence branch
seonghobae 1b12210
docs: align event intelligence maturity evidence
seonghobae a189b97
docs: fix temporal ledger table shape
seonghobae 8710e24
fix(event): enforce evidence layer at promotion boundary
seonghobae 314a6db
Merge remote-tracking branch 'origin/main' into HEAD
seonghobae 8f26c2f
test: cover event evidence layer accessor
seonghobae d4cd083
docs(adr): record provider-payload minimization as implemented-main
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| //! Evidence-status gates for TDT detection and CHRONOS prediction. | ||
|
|
||
| use crate::EventError; | ||
| use std::{collections::HashSet, hash::BuildHasher}; | ||
|
|
||
| /// Epistemic layer of an event-intelligence output. | ||
| /// | ||
| /// Only [`EventEvidenceLayer::PromotedTransition`] may enter the forward | ||
| /// state/input-process-outcome graph. TDT detections and CHRONOS predictions | ||
| /// remain measurement or hypothesis artifacts. | ||
| #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] | ||
| pub enum EventEvidenceLayer { | ||
| /// Fallible textual mention grounded in evidence. | ||
| ObservedMention, | ||
| /// TDT-style detection, link, or track output. | ||
| TdtDetection, | ||
| /// CHRONOS-style schema completion or predicted event. | ||
| ChronosPrediction, | ||
| /// Symbolic temporal-consistency judgment. | ||
| TemporalConsistency, | ||
| /// Independently promoted forward state transition. | ||
| PromotedTransition, | ||
| } | ||
|
|
||
| impl EventEvidenceLayer { | ||
| /// Stable wire name for this layer. | ||
| #[must_use] | ||
| pub const fn wire_name(self) -> &'static str { | ||
| match self { | ||
| Self::ObservedMention => "observed_mention", | ||
| Self::TdtDetection => "tdt_detection", | ||
| Self::ChronosPrediction => "chronos_prediction", | ||
| Self::TemporalConsistency => "temporal_consistency", | ||
| Self::PromotedTransition => "promoted_transition", | ||
| } | ||
| } | ||
|
|
||
| /// Whether this layer may admit a forward state-transition edge. | ||
| #[must_use] | ||
| pub const fn may_admit_state_transition(self) -> bool { | ||
| matches!(self, Self::PromotedTransition) | ||
| } | ||
| } | ||
|
|
||
| /// Admit a layer into the forward state graph or fail closed. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`EventError::PredictionIsNotFact`] for CHRONOS predictions and | ||
| /// [`EventError::DetectionIsNotTransition`] for every other non-promoted layer. | ||
| pub fn admit_state_transition(layer: EventEvidenceLayer) -> Result<(), EventError> { | ||
| if layer.may_admit_state_transition() { | ||
| Ok(()) | ||
| } else if matches!(layer, EventEvidenceLayer::ChronosPrediction) { | ||
| Err(EventError::PredictionIsNotFact) | ||
| } else { | ||
| Err(EventError::DetectionIsNotTransition) | ||
| } | ||
|
seonghobae marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /// First-story versus subsequent-track decision for one candidate story. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum TdtStoryDecision { | ||
| /// The story identity has not been seen in the stream. | ||
| FirstStory, | ||
| /// The story identity continues a previously seen event. | ||
| Track, | ||
| } | ||
|
|
||
| /// Classify one candidate against previously seen story identities. | ||
| #[must_use] | ||
| pub fn classify_tdt_story<S: BuildHasher>( | ||
| seen_story_ids: &HashSet<u64, S>, | ||
| candidate_story_id: u64, | ||
| ) -> TdtStoryDecision { | ||
| if seen_story_ids.contains(&candidate_story_id) { | ||
| TdtStoryDecision::Track | ||
| } else { | ||
| TdtStoryDecision::FirstStory | ||
| } | ||
| } | ||
|
|
||
| /// Known-truth first-story detection counts. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub struct FirstStoryRates { | ||
| hits: usize, | ||
| misses: usize, | ||
| false_alarms: usize, | ||
| first_story_truth: usize, | ||
| continuation_truth: usize, | ||
| } | ||
|
|
||
| impl FirstStoryRates { | ||
| /// Correct first-story detections. | ||
| #[must_use] | ||
| pub const fn hits(self) -> usize { | ||
| self.hits | ||
| } | ||
|
|
||
| /// Missed first stories. | ||
| #[must_use] | ||
| pub const fn misses(self) -> usize { | ||
| self.misses | ||
| } | ||
|
|
||
| /// Continuations labeled as first stories. | ||
| #[must_use] | ||
| pub const fn false_alarms(self) -> usize { | ||
| self.false_alarms | ||
| } | ||
|
|
||
| /// Miss rate among true first stories. | ||
| #[must_use] | ||
| pub fn miss_rate(self) -> f64 { | ||
| if self.first_story_truth == 0 { | ||
| 0.0 | ||
| } else { | ||
| #[allow(clippy::cast_precision_loss)] | ||
| { | ||
| self.misses as f64 / self.first_story_truth as f64 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// False-alarm rate among true continuations. | ||
| #[must_use] | ||
| pub fn false_alarm_rate(self) -> f64 { | ||
| if self.continuation_truth == 0 { | ||
| 0.0 | ||
| } else { | ||
| #[allow(clippy::cast_precision_loss)] | ||
| { | ||
| self.false_alarms as f64 / self.continuation_truth as f64 | ||
| } | ||
| } | ||
|
seonghobae marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| /// Score a first-story detector against a known binary stream. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`EventError::InvalidWirePayload`] when the streams are empty or | ||
| /// have unequal length. | ||
| pub fn first_story_detection_rates( | ||
| truth_is_first: &[bool], | ||
| predicted_is_first: &[bool], | ||
| ) -> Result<FirstStoryRates, EventError> { | ||
| if truth_is_first.is_empty() || truth_is_first.len() != predicted_is_first.len() { | ||
| return Err(EventError::InvalidWirePayload); | ||
| } | ||
| let mut hits = 0; | ||
| let mut misses = 0; | ||
| let mut false_alarms = 0; | ||
| let mut first_story_truth = 0; | ||
| let mut continuation_truth = 0; | ||
| for (&truth, &predicted) in truth_is_first.iter().zip(predicted_is_first) { | ||
| if truth { | ||
| first_story_truth += 1; | ||
| if predicted { | ||
| hits += 1; | ||
| } else { | ||
| misses += 1; | ||
| } | ||
| } else { | ||
| continuation_truth += 1; | ||
| if predicted { | ||
| false_alarms += 1; | ||
| } | ||
| } | ||
| } | ||
| Ok(FirstStoryRates { | ||
| hits, | ||
| misses, | ||
| false_alarms, | ||
| first_story_truth, | ||
| continuation_truth, | ||
| }) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::collections::HashSet; | ||
|
|
||
| use super::{ | ||
| EventEvidenceLayer, TdtStoryDecision, classify_tdt_story, first_story_detection_rates, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn zero_denominator_rates_are_zero_and_track_is_not_first() { | ||
| assert_eq!( | ||
| classify_tdt_story(&HashSet::from([7]), 7), | ||
| TdtStoryDecision::Track | ||
| ); | ||
| assert_eq!( | ||
| classify_tdt_story(&HashSet::new(), 8), | ||
| TdtStoryDecision::FirstStory | ||
| ); | ||
| assert!(first_story_detection_rates(&[], &[]).is_err()); | ||
| assert!(first_story_detection_rates(&[true], &[true, false]).is_err()); | ||
| let no_first_story = std::hint::black_box( | ||
| first_story_detection_rates(&[false], &[false]).expect("no first"), | ||
| ); | ||
| assert!(no_first_story.miss_rate() < 1e-15); | ||
| let no_continuation = | ||
| std::hint::black_box(first_story_detection_rates(&[true], &[true]).expect("no track")); | ||
| assert!(no_continuation.false_alarm_rate() < 1e-15); | ||
| let all_first = first_story_detection_rates(&[true, true], &[true, false]).expect("all"); | ||
| assert!((all_first.miss_rate() - 0.5).abs() < 1e-15); | ||
| assert!(all_first.false_alarm_rate() < 1e-15); | ||
| let continuations = | ||
| first_story_detection_rates(&[false, false], &[true, false]).expect("continuations"); | ||
| assert_eq!(continuations.false_alarms(), 1); | ||
| assert_eq!(continuations.misses(), 0); | ||
| assert!(continuations.miss_rate() < 1e-15); | ||
| assert!((continuations.false_alarm_rate() - 0.5).abs() < 1e-15); | ||
| assert_eq!( | ||
| EventEvidenceLayer::TdtDetection.wire_name(), | ||
| "tdt_detection" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.