verifiers 0.4.2.dev60__py3-none-any.whl → 0.4.2.dev62__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,10 @@ import argparse
4
4
  import asyncio
5
5
  import json
6
6
  import logging
7
+ import os
8
+ import selectors
7
9
  import subprocess
10
+ import time
8
11
  import traceback
9
12
  from contextlib import AsyncExitStack
10
13
  from pathlib import Path
@@ -32,6 +35,7 @@ from tenacity import (
32
35
  if TYPE_CHECKING:
33
36
  # The harness bundles this module into the generated script before execution.
34
37
  from verifiers.v1.harnesses.utils.compaction import ( # noqa: TC004
38
+ TOOL_OUTPUT_MAX_BYTES,
35
39
  Compactor,
36
40
  bound_tool_message,
37
41
  compactable,
@@ -183,16 +187,62 @@ def run_search(
183
187
  return f"search failed ({e}). Try again or rephrase the query."
184
188
 
185
189
 
190
+ class _BashOutput:
191
+ def __init__(self) -> None:
192
+ self.head = b""
193
+ self.tail = b""
194
+ self.size = 0
195
+
196
+ def add(self, chunk: bytes) -> None:
197
+ self.head += chunk[: max(0, TOOL_OUTPUT_MAX_BYTES - len(self.head))]
198
+ self.tail = (self.tail + chunk)[-TOOL_OUTPUT_MAX_BYTES:]
199
+ self.size += len(chunk)
200
+
201
+
186
202
  def run_bash(command: str) -> str:
187
203
  try:
188
- result = subprocess.run(
204
+ with subprocess.Popen(
189
205
  ["bash", "-c", command],
190
- capture_output=True,
191
- text=True,
192
- timeout=3600,
193
- check=False,
194
- )
195
- return result.stdout + result.stderr
206
+ stdout=subprocess.PIPE,
207
+ stderr=subprocess.PIPE,
208
+ ) as process:
209
+ stdout, stderr = _BashOutput(), _BashOutput()
210
+ deadline = time.monotonic() + 3600
211
+ try:
212
+ with selectors.DefaultSelector() as selector:
213
+ assert process.stdout is not None and process.stderr is not None
214
+ selector.register(process.stdout, selectors.EVENT_READ, stdout)
215
+ selector.register(process.stderr, selectors.EVENT_READ, stderr)
216
+ while selector.get_map():
217
+ remaining = deadline - time.monotonic()
218
+ if remaining <= 0:
219
+ raise subprocess.TimeoutExpired(process.args, 3600)
220
+ for key, _ in selector.select(remaining):
221
+ chunk = os.read(key.fd, 8192)
222
+ if chunk:
223
+ key.data.add(chunk)
224
+ else:
225
+ selector.unregister(key.fileobj)
226
+ process.wait(timeout=max(0, deadline - time.monotonic()))
227
+ finally:
228
+ # Do not communicate() here: descendants may still hold the pipes.
229
+ if process.returncode is None:
230
+ process.kill()
231
+ process.wait()
232
+ size = stdout.size + stderr.size
233
+ if size <= TOOL_OUTPUT_MAX_BYTES:
234
+ text = "".join(
235
+ output.head.decode().replace("\r\n", "\n").replace("\r", "\n")
236
+ for output in (stdout, stderr)
237
+ )
238
+ else:
239
+ marker = f"\n[... bash output truncated; {size} bytes total ...]\n"
240
+ keep = (TOOL_OUTPUT_MAX_BYTES - len(marker.encode())) // 2
241
+ # Preserve stdout-then-stderr ordering, including when just one is large.
242
+ head = (stdout.head + stderr.head)[:keep].decode(errors="ignore")
243
+ tail = (stdout.tail + stderr.tail)[-keep:].decode(errors="ignore")
244
+ text = head + marker + tail
245
+ return text.replace("\r\n", "\n").replace("\r", "\n")
196
246
  except Exception as e: # noqa: BLE001 - tool failures are returned to the model
197
247
  return f"error: {e}"
198
248
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev60
3
+ Version: 0.4.2.dev62
4
4
  Summary: Verifiers: Environments for LLM Reinforcement Learning
5
5
  Project-URL: Homepage, https://github.com/primeintellect-ai/verifiers
6
6
  Project-URL: Documentation, https://github.com/primeintellect-ai/verifiers
@@ -115,7 +115,7 @@ verifiers/v1/harnesses/terminus_2/harness.py,sha256=ZNKB2DihcAN4h6JL6fuJfw9-fsPo
115
115
  verifiers/v1/harnesses/terminus_2/program.py,sha256=V63SGuAu_H1LdfrjKj3gM4htjg-H3IjWJ4YFEZPkZK4,3023
116
116
  verifiers/v1/harnesses/utils/__init__.py,sha256=eTS-Ft2HwoLiYn5u1t_KueLmaZB_W12cdYmcVsE-G5A,364
117
117
  verifiers/v1/harnesses/utils/compaction.py,sha256=DeY6CYLEsv7-vJm26sT2mRaPHu3W2ywiZhvFr_pi6Hg,10495
118
- verifiers/v1/harnesses/utils/core.py,sha256=SNEW3_39V0uRHQTRwqI6DxoKjw9VOOdSmjzleZLEtJM,21351
118
+ verifiers/v1/harnesses/utils/core.py,sha256=RBLi3R5yGrIt2YixvPrWlCbR5l4KmKLvSMU3D704w9U,23733
119
119
  verifiers/v1/harnesses/utils/install.py,sha256=EESYSh_e9L4gj6N4GvAbQY2kb4ckven7tmtlQEErPiQ,3563
120
120
  verifiers/v1/harnesses/utils/launch.py,sha256=2KuLnNruUqH6vcW2Ru661P86ffRzaqslNs-kDMn7B6U,5670
121
121
  verifiers/v1/harnesses/utils/mcp.py,sha256=EtDraHEqgsOB6xKvcF2z9C6HlQyKoST0ZDvmy47NWgM,7450
@@ -189,8 +189,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
189
189
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
190
190
  verifiers/v1/utils/trace_store.py,sha256=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
191
191
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
192
- verifiers-0.4.2.dev60.dist-info/METADATA,sha256=PkzNtKbolX9IZchiHaNjOGT2-2k2BiOq_AmWzjFkPwc,5116
193
- verifiers-0.4.2.dev60.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
194
- verifiers-0.4.2.dev60.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
195
- verifiers-0.4.2.dev60.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
196
- verifiers-0.4.2.dev60.dist-info/RECORD,,
192
+ verifiers-0.4.2.dev62.dist-info/METADATA,sha256=1BEsHmwrVbRkQX6ncZkX3x69olJyrJL8-a6D-QnSx8A,5116
193
+ verifiers-0.4.2.dev62.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
194
+ verifiers-0.4.2.dev62.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
195
+ verifiers-0.4.2.dev62.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
196
+ verifiers-0.4.2.dev62.dist-info/RECORD,,