refactor(failure_auto_filer): Phase B language-advantage pass — dichotomy wave
CI Pipeline / best-practices (push) Successful in 9s
CI Pipeline / documentation (push) Successful in 4s
CI Pipeline / rust-surface (push) Failing after 15s
CI Pipeline / go-surface (push) Failing after 18s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 21s
CI Pipeline / gitea-offline (push) Canceled after 18s
deploy / deploy (push) Canceled after 41s
CI Pipeline / unit-tests (push) Canceled after 36s
CI Pipeline / lint (push) Canceled after 36s
CI Pipeline / canary (push) Canceled after 36s
Auto-version and Release / release (push) Canceled after 45s
CI Pipeline / best-practices (push) Successful in 9s
CI Pipeline / documentation (push) Successful in 4s
CI Pipeline / rust-surface (push) Failing after 15s
CI Pipeline / go-surface (push) Failing after 18s
CI Pipeline / required-checks (push) Canceled after 0s
CI Pipeline / CI Pipeline / notify-event-bridge (push) Canceled after 0s
CI Pipeline / type-check (push) Canceled after 21s
CI Pipeline / gitea-offline (push) Canceled after 18s
deploy / deploy (push) Canceled after 41s
CI Pipeline / unit-tests (push) Canceled after 36s
CI Pipeline / lint (push) Canceled after 36s
CI Pipeline / canary (push) Canceled after 36s
Auto-version and Release / release (push) Canceled after 45s
This commit is contained in:
1 parent
5cadd40157
commit
8aa4813445
1 file changed
+27
-34
@@ -232,6 +232,31 @@ func NewFailureAutoFiler(client ForgeClient, journal SpoolJournal, batchSize int
|
||||
return f
|
||||
}
|
||||
|
||||
// advanceState is the shared coalescing step behind File and flushGroup.
|
||||
// The oracle states the due predicate twice (file() vs _flush_group());
|
||||
// Go's multiple-return values collapse them into one guard-protected
|
||||
// helper returning both the due flag and the count snapshot.
|
||||
func (f *FailureAutoFiler) advanceState(sig sigKey, n int, now float64) (due bool, countAtFlush int) {
|
||||
f.mu.Lock()
|
||||
st := f.state[sig]
|
||||
if st == nil {
|
||||
st = &sigState{}
|
||||
f.state[sig] = st
|
||||
}
|
||||
st.count += n
|
||||
st.pending += n
|
||||
due = st.count == n || // first flush for this signature
|
||||
st.pending >= f.batchSize ||
|
||||
(st.pending > 0 && now-st.windowStart >= batchIntervalSeconds)
|
||||
countAtFlush = st.count
|
||||
if due {
|
||||
st.pending = 0
|
||||
st.windowStart = now
|
||||
}
|
||||
f.mu.Unlock()
|
||||
return due, countAtFlush
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ failure-path API
|
||||
|
||||
// Call is oracle __call__ (the callable-filer contract): exactly Submit.
|
||||
@@ -299,23 +324,7 @@ func (f *FailureAutoFiler) File(subsystem, errMsg string, tier int, now float64)
|
||||
now = clockNow(now)
|
||||
sig := signatureKey(subsystem, errMsg)
|
||||
text := errMsg
|
||||
f.mu.Lock()
|
||||
st := f.state[sig]
|
||||
if st == nil {
|
||||
st = &sigState{}
|
||||
f.state[sig] = st
|
||||
}
|
||||
st.count++
|
||||
st.pending++
|
||||
due := st.count == 1 ||
|
||||
st.pending >= f.batchSize ||
|
||||
(st.pending > 0 && now-st.windowStart >= batchIntervalSeconds)
|
||||
countAtFlush := st.count
|
||||
if due {
|
||||
st.pending = 0
|
||||
st.windowStart = now
|
||||
}
|
||||
f.mu.Unlock()
|
||||
due, countAtFlush := f.advanceState(sig, 1, now)
|
||||
if !due {
|
||||
return false // coalesced: no client call for this occurrence
|
||||
}
|
||||
@@ -563,23 +572,7 @@ func (f *FailureAutoFiler) flushGroup(sig sigKey, group []filerItem) error {
|
||||
now := last.now
|
||||
text := last.text // last error of the batch
|
||||
tier := last.tier
|
||||
f.mu.Lock()
|
||||
st := f.state[sig]
|
||||
if st == nil {
|
||||
st = &sigState{}
|
||||
f.state[sig] = st
|
||||
}
|
||||
st.count += len(group)
|
||||
st.pending += len(group)
|
||||
due := st.count == len(group) ||
|
||||
st.pending >= f.batchSize ||
|
||||
(st.pending > 0 && now-st.windowStart >= batchIntervalSeconds)
|
||||
countAtFlush := st.count
|
||||
if due {
|
||||
st.pending = 0
|
||||
st.windowStart = now
|
||||
}
|
||||
f.mu.Unlock()
|
||||
due, countAtFlush := f.advanceState(sig, len(group), now)
|
||||
if due {
|
||||
if _, err := f.write(sig, text, tier, countAtFlush, 0); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user