From 46be42e42319ec68c35bb2b3e9d2eade0fcd8761 Mon Sep 17 00:00:00 2001 From: atlaie Date: Fri, 13 Nov 2026 16:47:42 +0100 Subject: [PATCH 1/2] feat: say when a log shows only its first characters job.stderr / job.stdout (repr and notebook view) say when they show only the first N characters that the data owners released, and the whole length when the copy is shorter than asked for. Messages, display and docstrings only; no behaviour change. Asana: https://app.asana.com/0/0/1220519978965332/f Co-Authored-By: Claude Opus 5.5 --- .../src/syft_enclaves/enclave_job_info.py | 20 +++++++++++++++++++ .../src/syft_enclaves/log_requests.py | 13 ++++++++++++ .../tests/test_read_permissions.py | 20 +++++++++++++++++++ packages/syft-job/src/syft_job/job.py | 4 ++++ packages/syft-job/src/syft_job/job_repr.py | 10 +++++++--- packages/syft-job/src/syft_job/job_stdout.py | 11 +++++++--- 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py index 3b6c586d6ca..67c11594c7d 100644 --- a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py +++ b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py @@ -24,6 +24,7 @@ LogRequest, RequestedPermissionsUpdate, load_log_request, + log_head_length, log_request_file_name, longest_log_head, ) @@ -357,6 +358,25 @@ def _log_path(self, log_file: str) -> Path: # The data owners may have shared only the first chars of the log. return longest_log_head(self.job_review_path, log_file) or full + def _log_note(self, log_file: str) -> Optional[str]: + """Say when the viewers show only the first chars of ``log_file``. + + The reader knows the log's full length only when the copy is shorter + than asked for: then it holds the whole log. + """ + path = self._log_path(log_file) + n_chars = log_head_length(path, log_file) + if n_chars is None: + return None + note = f"first {n_chars:,} characters, released by the data owners" + try: + length = len(path.read_text(errors="replace")) + except OSError: + return note + if length < n_chars: + note += f"; the whole log is {length:,} characters" + return note + def reject(self, reason: Optional[str] = None) -> None: """Reject this job in the DO's own approval file. diff --git a/packages/syft-enclave/src/syft_enclaves/log_requests.py b/packages/syft-enclave/src/syft_enclaves/log_requests.py index 22e01c499f1..f2f52764cd8 100644 --- a/packages/syft-enclave/src/syft_enclaves/log_requests.py +++ b/packages/syft-enclave/src/syft_enclaves/log_requests.py @@ -101,6 +101,19 @@ def log_head_name(log_file: str, n_chars: int) -> str: return f"{path.stem}_{n_chars}{path.suffix}" +def log_head_length(path: Path, log_file: str) -> Optional[int]: + """The ``n_chars`` of ``path`` when it is a copy of the first chars of ``log_file``. + + None for any other file, such as the log itself. + """ + log = Path(log_file) + prefix = f"{log.stem}_" + if path.suffix != log.suffix or not path.stem.startswith(prefix): + return None + n_chars = path.stem[len(prefix) :] + return int(n_chars) if n_chars.isdigit() else None + + def write_log_head( review_dir: Path, log_file: str, n_chars: Optional[int] ) -> Optional[str]: diff --git a/packages/syft-enclave/tests/test_read_permissions.py b/packages/syft-enclave/tests/test_read_permissions.py index 413f05721d6..0cb9fe2a67d 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -804,6 +804,24 @@ def test_requested_stderr_head_reaches_submitter(): assert not has_file(ds, "stderr.txt") assert str(ds.jobs["j"].stderr) == full[:10] assert ds.jobs["j"].approved_read_permissions == {"stderr_10.txt": [ds.email]} + # The viewer says it shows only the first chars. + note = "first 10 characters, released by the data owners" + assert repr(ds.jobs["j"].stderr) == f"{full[:10]}\n({note})" + assert f"stderr.txt ({note})" in ds.jobs["j"].stderr._repr_html_() + + +def test_log_head_longer_than_log_says_it_is_whole(): + enclave, do1, do2, ds = run_crash_sharing_nothing() + for do in (do1, do2): + request_stderr(do, readers=ds.email, n_chars=100_000) + run_and_share(enclave, ds) + + enclave_review = Path(enclave._rds.job_client.jobs["j"].job_review_path) + length = len((enclave_review / "stderr.txt").read_text()) + assert repr(ds.jobs["j"].stderr).endswith( + "(first 100,000 characters, released by the data owners; " + f"the whole log is {length:,} characters)" + ) def test_one_owner_requesting_log_shares_nothing(): @@ -822,6 +840,8 @@ def test_log_request_defaults_to_data_owners(): assert readers_of(enclave, "stderr.txt", (ds, do1, do2)) == [do1, do2] assert has_file(do1, "stderr.txt") assert not has_file(ds, "stderr.txt") + # The whole log carries no note. + assert "released by" not in repr(do1.jobs["j"].stderr) def test_default_log_readers_ignore_owners_named_by_submitter(): diff --git a/packages/syft-job/src/syft_job/job.py b/packages/syft-job/src/syft_job/job.py index 04b4866c003..68a514ce77d 100644 --- a/packages/syft-job/src/syft_job/job.py +++ b/packages/syft-job/src/syft_job/job.py @@ -256,6 +256,10 @@ def _list_output_files() -> List[Path]: return output_files + def _log_note(self, log_file: str) -> Optional[str]: + """What the viewers add about the ``log_file`` they show, or None.""" + return None + @property def stdout(self) -> StdoutViewer: """Get a viewer for the stdout content.""" diff --git a/packages/syft-job/src/syft_job/job_repr.py b/packages/syft-job/src/syft_job/job_repr.py index b619bbe8813..7955a6ddae7 100644 --- a/packages/syft-job/src/syft_job/job_repr.py +++ b/packages/syft-job/src/syft_job/job_repr.py @@ -81,9 +81,11 @@ def __repr__(self) -> str: lines = content.split("\n") if len(lines) <= 3: - return content + text = content else: - return f"StderrViewer({len(lines)} lines, {len(content)} chars)" + text = f"StderrViewer({len(lines)} lines, {len(content)} chars)" + note = self.job_info._log_note("stderr.txt") + return f"{text}\n({note})" if note else text def _repr_html_(self) -> str: """HTML representation for Jupyter notebooks with scrollable view.""" @@ -132,6 +134,8 @@ def _repr_html_(self) -> str: lines = clean_content.split("\n") char_count = len(clean_content) line_count = len(lines) + note = self.job_info._log_note("stderr.txt") + title = f"stderr.txt ({escape(note)})" if note else "stderr.txt" return f"""