Skip to content

Commit 5d58e31

Browse files
shengyfuCopilot
andcommitted
Classify blob-boundary file growth as unstable
Check growth past the opened length before the managed blob limit. Add deterministic regressions for one-byte growth at the boundary and stable initially oversized files. Keep benchmark timings attributed to the immutable measured source rather than this follow-up. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 9776b17f-6a2d-4c47-9e89-0f8113d14b95
1 parent 1129c9b commit 5d58e31

3 files changed

Lines changed: 71 additions & 5 deletions

File tree

‎SHARED_INDEX_BENCHMARKS.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ remains a separate diagnostic, not the baseline in this comparison.
4141
| Host | Windows/ReFS, 16 logical CPUs |
4242
| Exact-source qualification | [CI run 38500502076](https://github.com/microsoft/tgrep/actions/runs/38500502076), all nine jobs passed |
4343

44+
A subsequent guard-order correction classifies a file growing one byte beyond
45+
its opened length at the managed blob limit as unstable, rather than as a
46+
blob-limit violation. A stable initially oversized file retains its blob-limit
47+
error. That correction and its deterministic regressions are not part of the
48+
measured executable; these timings remain attributed to `58fdda8`, not later
49+
PR heads.
50+
4451
Standalone ran first; the file cache was **not flushed**. Implementation
4552
builds/tests were paused during measurement, but this was not an exclusive
4653
host. Native watching was disabled to isolate initial attachment. These

‎tgrep-core/src/worktrees.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,17 +2039,17 @@ fn read_file<'a>(
20392039
if count == 0 {
20402040
break;
20412041
}
2042+
// A growing file is unstable, not a request to wait for additional
2043+
// capacity while retaining an already admitted read buffer.
2044+
if bytes.len() as u64 + count as u64 > expected {
2045+
return Err(WorktreeError::UnstableFile(path.into()));
2046+
}
20422047
if work_limit.is_some_and(|limit| bytes.len() as u64 + count as u64 > limit) {
20432048
return Err(crate::Error::from(crate::managed::Error::pressure(
20442049
"checkout-blob-read-limit",
20452050
))
20462051
.into());
20472052
}
2048-
// A growing file is unstable, not a request to wait for additional
2049-
// capacity while retaining an already admitted read buffer.
2050-
if bytes.len() as u64 + count as u64 > expected {
2051-
return Err(WorktreeError::UnstableFile(path.into()));
2052-
}
20532053
bytes.extend_from_slice(&chunk[..count]);
20542054
}
20552055
let current = reopen()?;

‎tgrep-core/src/worktrees/tests.rs‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,65 @@ fn managed_cancellation_and_policy_changes_drain_paused_directory_batches() {
458458
}
459459
}
460460

461+
#[test]
462+
fn managed_verified_read_classifies_growth_at_blob_limit_as_unstable() {
463+
let fixture = Fixture::new();
464+
write(&fixture.root, "file.txt", b"committed\n");
465+
commit(&fixture.root);
466+
let (_namespace, permit, view) = fixture.controlled();
467+
let path = fixture.root.join("file.txt");
468+
let blob_bytes = permit.read_limits().blob_bytes;
469+
let writer = File::options().write(true).open(&path).unwrap();
470+
writer.set_len(blob_bytes).unwrap();
471+
let reader = view.files.batch(Path::new("")).unwrap();
472+
let relative = Path::new("file.txt");
473+
let opened = reader.open_observed(relative).unwrap();
474+
assert_eq!(opened.metadata.len(), blob_bytes);
475+
writer.set_len(blob_bytes + 1).unwrap();
476+
477+
let read = read_file(
478+
|| reader.open_observed(relative),
479+
relative,
480+
opened,
481+
None,
482+
Some(&permit),
483+
);
484+
assert!(matches!(read, Err(WorktreeError::UnstableFile(_))));
485+
}
486+
487+
#[test]
488+
fn managed_verified_read_preserves_blob_limit_for_stable_oversized_file() {
489+
let fixture = Fixture::new();
490+
write(&fixture.root, "file.txt", b"committed\n");
491+
commit(&fixture.root);
492+
let (_namespace, permit, view) = fixture.controlled();
493+
let path = fixture.root.join("file.txt");
494+
let blob_bytes = permit.read_limits().blob_bytes;
495+
File::options()
496+
.write(true)
497+
.open(&path)
498+
.unwrap()
499+
.set_len(blob_bytes + 1)
500+
.unwrap();
501+
let reader = view.files.batch(Path::new("")).unwrap();
502+
let relative = Path::new("file.txt");
503+
let opened = reader.open_observed(relative).unwrap();
504+
assert_eq!(opened.metadata.len(), blob_bytes + 1);
505+
506+
let read = read_file(
507+
|| reader.open_observed(relative),
508+
relative,
509+
opened,
510+
None,
511+
Some(&permit),
512+
);
513+
assert!(
514+
matches!(read, Err(WorktreeError::Index(crate::Error::Managed(error)))
515+
if error.category == crate::managed::ErrorCategory::ResourcePressure
516+
&& error.reason_code == "checkout-blob-read-limit")
517+
);
518+
}
519+
461520
#[test]
462521
fn managed_verified_read_rejects_restored_mtime_mutation_and_replacement() {
463522
for replace in [false, true] {

0 commit comments

Comments
 (0)