diff --git a/crates/bashkit-monty-types/src/resource.rs b/crates/bashkit-monty-types/src/resource.rs index 055200889..4e8973f58 100644 --- a/crates/bashkit-monty-types/src/resource.rs +++ b/crates/bashkit-monty-types/src/resource.rs @@ -380,7 +380,7 @@ impl ResourceTracker { turn_execution_time: Cell::new(Duration::ZERO), running_since: Cell::new(None), recursion_limit_override: Cell::new(None), - tick: Cell::new(0), + tick: Cell::new(0), // bashkit fork: see the `tick` field } } diff --git a/crates/bashkit-monty/src/types/dict.rs b/crates/bashkit-monty/src/types/dict.rs index 76b92f166..246364036 100644 --- a/crates/bashkit-monty/src/types/dict.rs +++ b/crates/bashkit-monty/src/types/dict.rs @@ -1167,6 +1167,7 @@ impl<'h> HeapRead<'h, Dict> { defer_drop!(pair, vm); let (key, value) = pair; if printed > 0 { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(printed, vm)? { f.write_str(", ...[timeout]")?; break; @@ -1207,6 +1208,7 @@ impl<'h> HeapRead<'h, Dict> { f.write_char('{')?; for (n, &i) in order.iter().enumerate() { if n > 0 { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(n, vm)? { f.write_str(", ...[timeout]")?; break; diff --git a/crates/bashkit-monty/src/types/generic_alias.rs b/crates/bashkit-monty/src/types/generic_alias.rs index 525fb0fdf..ed8a12225 100644 --- a/crates/bashkit-monty/src/types/generic_alias.rs +++ b/crates/bashkit-monty/src/types/generic_alias.rs @@ -182,6 +182,7 @@ impl<'h> PyTrait<'h> for HeapObjectRead<'h, GenericAlias> { } for index in 0..count { if index > 0 { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(index, vm)? { f.write_str(", ...[timeout]")?; break; diff --git a/crates/bashkit-monty/src/types/host_class.rs b/crates/bashkit-monty/src/types/host_class.rs index 93bfab147..e3c812ddd 100644 --- a/crates/bashkit-monty/src/types/host_class.rs +++ b/crates/bashkit-monty/src/types/host_class.rs @@ -315,7 +315,7 @@ impl<'h> PyTrait<'h> for HeapObjectRead<'h, HostClass> { /// Each caller supplies its own field list via `field`, mapping an index to that /// field's name and a cloned value (dropped here). A cycle renders `...`, a /// `None` value ``, a memory limit truncates `...[timeout]`, and a time -/// limit raises (see `repr_check_time`). +/// limit raises (bashkit fork: see `repr_check_time`). /// /// `field` is resolved immediately before that field is written, never all up /// front, so a `__repr__` that mutates a later field is observed — matching the diff --git a/crates/bashkit-monty/src/types/list.rs b/crates/bashkit-monty/src/types/list.rs index f4d89755c..ce67c195c 100644 --- a/crates/bashkit-monty/src/types/list.rs +++ b/crates/bashkit-monty/src/types/list.rs @@ -1,6 +1,6 @@ use std::{cmp::Ordering, fmt::Write, mem}; -use monty_types::ResourceError; +use monty_types::ResourceError; // bashkit fork: a repr time hit returns this error use serde::{Deserialize, Serialize}; use smallvec::SmallVec; @@ -1068,6 +1068,7 @@ pub(crate) fn repr_sequence_fmt<'h>( let Some(item) = get_item(vm.heap, i) else { break }; defer_drop!(item, vm); if i > 0 { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(i, vm)? { f.write_str(", ...[timeout]")?; break; @@ -1096,6 +1097,7 @@ pub(crate) fn repr_items_fmt( ) -> RunResult<()> { for (i, item) in items.iter().enumerate() { if i > 0 { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(i, vm)? { f.write_str(", ...[timeout]")?; break; diff --git a/crates/bashkit-monty/src/types/partial.rs b/crates/bashkit-monty/src/types/partial.rs index 99418f64b..57b83011d 100644 --- a/crates/bashkit-monty/src/types/partial.rs +++ b/crates/bashkit-monty/src/types/partial.rs @@ -371,6 +371,7 @@ impl<'h> PyTrait<'h> for HeapObjectRead<'h, Partial> { let mut item = 0; 'items: { for index in 0..self.get(vm.heap).args.len() { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(item, vm)? { f.write_str(", ...[timeout]")?; break 'items; @@ -383,6 +384,7 @@ impl<'h> PyTrait<'h> for HeapObjectRead<'h, Partial> { } for index in 0..self.get(vm.heap).keywords.len() { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(item, vm)? { f.write_str(", ...[timeout]")?; break 'items; diff --git a/crates/bashkit-monty/src/types/union.rs b/crates/bashkit-monty/src/types/union.rs index 1f4c3d16d..e7a2ac1e0 100644 --- a/crates/bashkit-monty/src/types/union.rs +++ b/crates/bashkit-monty/src/types/union.rs @@ -359,6 +359,7 @@ impl<'h> PyTrait<'h> for HeapObjectRead<'h, Union> { let count = args.get(vm.heap).as_slice().len(); for index in 0..count { if index > 0 { + // bashkit fork: `?` so a time hit errors instead of truncating (see `repr_check_time`). if repr_check_time(index, vm)? { f.write_str(" | ...[timeout]")?; break; diff --git a/knowledge/log.md b/knowledge/log.md index ea6741b64..757a1b428 100644 --- a/knowledge/log.md +++ b/knowledge/log.md @@ -3,6 +3,7 @@ ## 2026-11-06 * **Python wall-clock limit**: Monty 1.x pauses its clock while the VM waits on the host, so `PythonLimits::max_duration` bounded VM time only. A `while True: p.write_text('x')` loop under a 500 ms limit ran 6 s, never yielding its worker thread, so caller-side timeouts could not cancel it and co-tenants on that thread stalled. The host-call loop now enforces the wall-clock deadline (exit 124) and yields at every host call. Found by the multi-tenant stress suite. See [Python Builtin](runtimes/python-builtin.md), TM-PY-036. +* **Monty fork drift markers completed**: the drift check landed (#2861) from a branch cut before the shared-graph fix (#2857), so `main` went red on 12 unmarked regions the moment both were in. Eleven were real #2857 edits (seven `repr_check_time(..)?` call sites, the `ResourceError` import, a doc sentence, the `tick` initializer) and are now marked. The twelfth was a checker blind spot: its fixed three-line window read the tail of a multi-line fork note and missed the marker on the note's first line, which is how the forks are written (`repr_check_time`'s note is eleven lines). The window now covers the whole comment/attribute block attached to the changed item, stopping at the first line of code so one item's note cannot mark the next item's drift. See [Dependencies](operations/dependencies.md#monty-forks). * **Monty fork drift check**: `scripts/check_monty_fork.py` compares both forks with the SHA-256-pinned upstream 1.4.0 crates and fails on unmarked edits (it found one unmarked import, now marked); runs in CI lint and `just check`. Re-sync checklist for upstream security fixes added. See [Dependencies](operations/dependencies.md#monty-forks). * **Monty multi-tenant stress**: `python_tenant_stress_tests` mixes hostile and well-behaved `python3` tenants on shared worker threads, abandons calls mid-run, and reuses one session's memory budget many times; each tenant must hit only its own limit. 20-round soak passed locally (80 s). See [Python Builtin](runtimes/python-builtin.md), TM-PY-032. * **Dependabot config parse fix**: #2852 set `versioning-strategy: increase` on a cargo entry, which cargo rejects, so Dependabot refused the whole `dependabot.yml` (red check on `main`). Replaced by committing the two random-fs fixture lockfiles, which also puts them in the advisory scan; a test pins cargo strategies to `auto`/`lockfile-only`. See [Dependencies](operations/dependencies.md). diff --git a/knowledge/operations/dependencies.md b/knowledge/operations/dependencies.md index 451b656f9..88ccb233b 100644 --- a/knowledge/operations/dependencies.md +++ b/knowledge/operations/dependencies.md @@ -71,8 +71,9 @@ edits. See [Python Builtin](../runtimes/python-builtin.md#monty-14-embedding-for `scripts/check_monty_fork.py` (CI lint job, `just check-monty-fork`) diffs both forks against the SHA-256-pinned upstream 1.4.0 `.crate` files and fails on any -changed region without a `bashkit fork:` marker in or up to three lines above -it, on fork-only files without a marker header, on upstream files missing from +changed region without a `bashkit fork:` marker in it, in the comment or +attribute block attached to it (however long), or up to three lines above it, +on fork-only files without a marker header, on upstream files missing from the fork (upstream tests excepted), and on any dependency or feature in a fork `Cargo.toml` that differs from upstream's (the `monty-types` rename aside). Dependabot does not bump crates only the forks declare, so upstream security fixes arrive by re-sync: diff --git a/scripts/check_monty_fork.py b/scripts/check_monty_fork.py index f20348b43..d1cd01242 100755 --- a/scripts/check_monty_fork.py +++ b/scripts/check_monty_fork.py @@ -30,7 +30,9 @@ ROOT = Path(__file__).resolve().parents[1] MARKER = 'bashkit fork:' -# Lines above a changed region that may hold its marker comment. +# Plain lines above a changed region that may hold its marker comment. The +# comment/attribute block attached to the changed item is searched in full on +# top of this, however long it is, see `marker_window`. MARKER_WINDOW = 3 VERSION = '1.4.0' UPSTREAM = { @@ -73,6 +75,28 @@ def fetch(name: str, sha256: str, dest: Path) -> Path: return dest / f'{name}-{VERSION}' +def is_attached_comment(line: str) -> bool: + """A comment or attribute line, which in Rust binds to the item below it.""" + stripped = line.lstrip() + return stripped.startswith('//') or stripped.startswith('#[') or stripped.startswith('#![') + + +def marker_window(fork: list[str], j1: int, j2: int) -> list[str]: + """Fork lines that may carry the marker for the changed region `j1:j2`. + + Decision: the contiguous comment/attribute block above the region is + searched in full, not just `MARKER_WINDOW` lines. A fork note here is + usually several lines of rationale and the marker sits on its first line, + so a fixed window reads the tail of the note and misses the marker. The + block stops at the first line of code, so one item's note cannot mark the + next item's drift. + """ + start = j1 + while start > 0 and is_attached_comment(fork[start - 1]): + start -= 1 + return fork[min(start, max(0, j1 - MARKER_WINDOW)) : j2] + + def unmarked_hunks(upstream: list[str], fork: list[str]) -> list[int]: """1-based fork line numbers of changed regions with no marker nearby.""" bad = [] @@ -80,8 +104,7 @@ def unmarked_hunks(upstream: list[str], fork: list[str]) -> list[int]: for tag, _i1, _i2, j1, j2 in matcher.get_opcodes(): if tag == 'equal': continue - window = fork[max(0, j1 - MARKER_WINDOW) : j2] - if not any(MARKER in line for line in window): + if not any(MARKER in line for line in marker_window(fork, j1, j2)): bad.append(j1 + 1) return bad diff --git a/scripts/tests/test_check_monty_fork.py b/scripts/tests/test_check_monty_fork.py index a7e2fa480..9a298bbd9 100644 --- a/scripts/tests/test_check_monty_fork.py +++ b/scripts/tests/test_check_monty_fork.py @@ -78,6 +78,58 @@ def test_unmarked_deletion_fails(self): self.write_fork(UPSTREAM_SRC.replace('fn c() {}\n', '')) self.assertEqual(len(cmf.check_crate(self.fork, self.up)), 1) + # Upstream item whose doc comment and `#[inline]` stay unchanged in the + # fork, so a fork note inserted into the doc block and a change to the + # signature below it are two separate diff hunks (as in `check_time_every`). + DOCUMENTED = ( + 'fn a() {}\n' + '/// doc one\n' + '/// doc two\n' + '#[inline]\n' + 'fn b() {\n' + ' 1\n' + '}\n' + ) + NOTE = ( + '/// bashkit fork: first line carries the marker\n' + '/// second line of the rationale\n' + '/// third line of the rationale\n' + '/// fourth line of the rationale\n' + ) + + def write_pair(self, upstream, fork): + (self.up / 'src' / 'lib.rs').write_text(upstream) + self.write_fork(fork) + + def test_marker_at_the_top_of_a_long_note_covers_the_item(self): + """The marker is on the note's first line, beyond MARKER_WINDOW.""" + self.write_pair( + self.DOCUMENTED, + self.DOCUMENTED.replace('#[inline]\n', self.NOTE + '#[inline]\n').replace( + 'fn b() {', 'fn b(x: u8) {' + ), + ) + self.assertEqual(cmf.check_crate(self.fork, self.up), []) + + def test_unmarked_long_note_still_fails(self): + note = self.NOTE.replace('bashkit fork: first', 'first') + self.write_pair( + self.DOCUMENTED, + self.DOCUMENTED.replace('#[inline]\n', note + '#[inline]\n').replace( + 'fn b() {', 'fn b(x: u8) {' + ), + ) + self.assertTrue(cmf.check_crate(self.fork, self.up)) + + def test_comment_block_does_not_reach_past_code(self): + """A note on one item cannot mark drift in the item after it.""" + self.write_pair( + self.DOCUMENTED + 'fn c() {}\n', + self.DOCUMENTED.replace('/// doc one', '// bashkit fork: why\n/// doc one') + + 'fn c() { 0 }\n', + ) + self.assertTrue(cmf.check_crate(self.fork, self.up)) + def test_marker_far_above_does_not_cover_change(self): text = '// bashkit fork: unrelated\n' + UPSTREAM_SRC.replace('fn c() {}', 'fn c() { 0 }') self.write_fork(text)