A duplicate Stop can be acknowledged only if its scoped files have no unrecorded changes. Never use unrelated working-tree edits as evidence of a new turn, and never silently accept an invalid or stale manifest.
(
root: &Path,
options: &TurnRecordOptions<'_>,
)
| 182 | /// unrecorded changes. Never use unrelated working-tree edits as evidence of |
| 183 | /// a new turn, and never silently accept an invalid or stale manifest. |
| 184 | pub(crate) fn has_pending_changes( |
| 185 | root: &Path, |
| 186 | options: &TurnRecordOptions<'_>, |
| 187 | ) -> AgentResult<bool> { |
| 188 | let Some(files) = manifest(options)? else { |
| 189 | return Ok(false); |
| 190 | }; |
| 191 | if files.is_empty() { |
| 192 | return Ok(false); |
| 193 | } |
| 194 | validate(root, &files, options)?; |
| 195 | let fail = |error: atomic_repository::RepositoryError| AgentError::RecordFailed { |
| 196 | session_id: options.session.session_id.clone(), |
| 197 | turn_number: options.turn_number, |
| 198 | reason: format!("cannot verify duplicate Stop's scoped files: {error}"), |
| 199 | }; |
| 200 | let repo = |
| 201 | Repository::open_readonly_wait(root, std::time::Duration::from_secs(10)).map_err(fail)?; |
| 202 | let working_copy = repo.require_working_copy_id().map_err(fail)?; |
| 203 | let status = repo |
| 204 | .status(working_copy, StatusOptions::default().with_untracked(true)) |
| 205 | .map_err(fail)?; |
| 206 | let scoped = filter(status, Some(&files)); |
| 207 | Ok(!scoped.is_clean() || scoped.has_untracked() || scoped.has_conflicts()) |
| 208 | } |
| 209 | |
| 210 | pub(super) fn filter(status: RepositoryStatus, files: Option<&FileManifest>) -> RepositoryStatus { |
| 211 | let Some(files) = files else { |
no test coverage detected