MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / reactive_pass

Function reactive_pass

atomic-cli/src/commands/git/watch.rs:298–410  ·  view source on GitHub ↗

One reactive pass: optionally gate on an external-change hint, wait for quiescence, reconcile under the metadata-only budget, and report the outcome. `hint_baseline` is the journal-evidence gate: a pass runs only when the observed truth differs from the baseline the caller last accounted for. `None` (single-pass mode) always attempts: the shared transaction classifier itself decides and a fully-a

(
    root: &Path,
    hint_baseline: Option<&MetadataHint>,
    notice_baseline: Option<&MetadataHint>,
    quiet: Duration,
    poll: Duration,
    sessions: &SessionStore,
)

Source from the content-addressed store, hash-verified

296/// — the caller keeps the hint baseline so the pending reconcile is
297/// retried once Git releases the state.
298fn reactive_pass(
299 root: &Path,
300 hint_baseline: Option<&MetadataHint>,
301 notice_baseline: Option<&MetadataHint>,
302 quiet: Duration,
303 poll: Duration,
304 sessions: &SessionStore,
305) -> CliResult<PassOutcome> {
306 let current = MetadataHint::observe(root)?;
307 if let Some(baseline) = hint_baseline {
308 if !current.differs_from(baseline) {
309 return Ok(PassOutcome::NoChange);
310 }
311 }
312 // The hint fired. Unsafe states surface, never act (RFC §11.2 rule 6):
313 // an evaluation that is not quiescent right now becomes a notice and
314 // the daemon waits instead of repairing.
315 let observation = observe_git_metadata(root).map_err(|error| CliError::StaleBaseline {
316 report: format!("shim watch cannot observe Git state: {error}"),
317 })?;
318 if let GitQuiescence::Busy { reason, detail } = GitQuiescence::evaluate(&observation) {
319 let should_notice = notice_baseline.is_none_or(|noticed| current.differs_from(noticed));
320 if should_notice {
321 notify_active_sessions(
322 sessions,
323 root,
324 WatchNoticeKind::UnsafeState,
325 &format!("Git-owned state in flight ({reason}): {detail}"),
326 "wait for Git to finish, then run 'atomic git shim reconcile' if needed",
327 );
328 }
329 return Ok(PassOutcome::Deferred);
330 }
331 wait_for_quiescence(root, quiet, poll, None)?;
332 // The prior-operation journal evidence AND the pending-recovery gate
333 // (review R1): the budgeted open refuses before any recovery runs, and
334 // a shim operation still in flight defers this pass entirely; its own
335 // completion will be part of the re-baselined truth.
336 let repo = match atomic_repository::Repository::open_with_budget(
337 root,
338 atomic_repository::repository::ReconcileEffectBudget::MetadataOnly,
339 ) {
340 Ok(repo) => repo,
341 Err(atomic_repository::RepositoryError::ReactiveDeferred { detail }) => {
342 let should_notice = notice_baseline.is_none_or(|noticed| current.differs_from(noticed));
343 if should_notice {
344 notify_active_sessions(
345 sessions,
346 root,
347 WatchNoticeKind::UnsafeState,
348 &format!("reactive reconcile deferred: {detail}"),
349 "run 'atomic git shim reconcile' explicitly to complete the pending work",
350 );
351 }
352 return Ok(PassOutcome::Deferred);
353 }
354 Err(error) => return Err(CliError::Repository(error)),
355 };

Callers 1

run_watchFunction · 0.85

Calls 8

observeFunction · 0.85
observe_git_metadataFunction · 0.85
notify_active_sessionsFunction · 0.85
wait_for_quiescenceFunction · 0.85
RepositoryClass · 0.85
head_operation_in_flightFunction · 0.85
bracket_passFunction · 0.85
differs_fromMethod · 0.80

Tested by

no test coverage detected