verifiers 0.4.2.dev136__py3-none-any.whl → 0.4.2.dev138__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.
verifiers/v1/graph.py CHANGED
@@ -912,6 +912,11 @@ def _project_prompt_attribution(
912
912
  return projected_spans, projected_is_content
913
913
 
914
914
 
915
+ def _advance_cursor(cursor: int, span: tuple[int, int] | None) -> int:
916
+ """A renderer may place a later message's tokens before a span already consumed."""
917
+ return max(cursor, span[1]) if span is not None else cursor
918
+
919
+
915
920
  def _commit_turn(turn: PendingTurn, response: Response) -> int:
916
921
  trace = turn.trace
917
922
  prompt = turn.prompt
@@ -987,11 +992,11 @@ def _commit_turn(turn: PendingTurn, response: Response) -> int:
987
992
  while len(prefix) < len(prompt):
988
993
  i = len(prefix)
989
994
  span = spans[i] if spans and i < len(spans) else None
990
- end = span[1] if span else path_len
995
+ end = _advance_cursor(path_len, span)
991
996
  renderer_span = (
992
997
  renderer_spans[i] if renderer_spans and i < len(renderer_spans) else None
993
998
  )
994
- renderer_end = renderer_span[1] if renderer_span else renderer_path_len
999
+ renderer_end = _advance_cursor(renderer_path_len, renderer_span)
995
1000
  parent = prefix[-1] if prefix else None
996
1001
  if tokens is not None and span is None:
997
1002
  next_start = next(
@@ -1055,7 +1060,7 @@ def _commit_turn(turn: PendingTurn, response: Response) -> int:
1055
1060
  for i, msg in enumerate(prompt[num_reused:], start=num_reused):
1056
1061
  start = path_len if cursor is None else cursor
1057
1062
  span = spans[i] if spans and i < len(spans) else None
1058
- end = span[1] if span else start
1063
+ end = _advance_cursor(start, span)
1059
1064
  # Each node copies its slice: a view would retain the turn's full-context array.
1060
1065
  node_tokens = prompt_ids[start:end].copy()
1061
1066
  renderer_start = (
@@ -1064,7 +1069,7 @@ def _commit_turn(turn: PendingTurn, response: Response) -> int:
1064
1069
  renderer_span = (
1065
1070
  renderer_spans[i] if renderer_spans and i < len(renderer_spans) else None
1066
1071
  )
1067
- renderer_end = renderer_span[1] if renderer_span else renderer_start
1072
+ renderer_end = _advance_cursor(renderer_start, renderer_span)
1068
1073
  trace.nodes.append(
1069
1074
  MessageNode.model_construct(
1070
1075
  parent=parent,
@@ -401,50 +401,81 @@ class HarborTask(Task[HarborData, State, HarborTaskConfig]):
401
401
  # Harbor's dedicated verifier image owns the complete test suite and its
402
402
  # dependencies. Mixing it with packaged tests can retain obsolete helpers.
403
403
  stage = "test -f /tests/test.sh"
404
+ clear = ""
405
+ setup = (
406
+ runtime.with_user("root")
407
+ if runtime.backend.SUPPORTS_USER_SWITCHING
408
+ else runtime
409
+ )
404
410
  if self.data.verifier is None or self.data.verifier_image is None:
405
- await runtime.write(
406
- "/tmp/tests.tgz", make_tar(Path(self.data.task_dir) / "tests")
411
+ owner = ""
412
+ if runtime.backend.SUPPORTS_USER_SWITCHING:
413
+ identity = await runtime.run(["sh", "-c", "id -u; id -g"], {})
414
+ ids = identity.stdout.split()
415
+ if (
416
+ identity.exit_code
417
+ or len(ids) != 2
418
+ or not all(value.isdigit() for value in ids)
419
+ ):
420
+ raise TaskError(
421
+ f"staging tests failed: could not resolve staging user "
422
+ f"(exit {identity.exit_code}): "
423
+ f"{(identity.stderr or identity.stdout).strip()[-500:]}"
424
+ )
425
+ owner = f" && chown {ids[0]}:{ids[1]} /tests && chmod u+rwx /tests"
426
+ # The packaged tests must be all that is in /tests: in a shared box the
427
+ # agent may have left a conftest.py or pytest.ini there, which the tests
428
+ # would load. An existing directory is emptied in place using POSIX sh
429
+ # (preserving any mount point); anything else (a symlink, a file, nothing)
430
+ # is replaced by a fresh directory. Ownership is set to the staging user
431
+ # when switching from root, so a pre-existing /tests (e.g. mode 0700 owned
432
+ # by agent_user) or missing /tests never blocks the non-root unpack.
433
+ # Also clear /tmp/tests.tgz first so an agent-planted file or symlink at
434
+ # that path cannot be written through by `runtime.write`.
435
+ clear = (
436
+ "if [ -d /tests ] && [ ! -L /tests ]; then "
437
+ "for p in /tests/* /tests/.[!.]* /tests/..?*; do "
438
+ 'if [ -e "$p" ] || [ -L "$p" ]; then rm -rf -- "$p" || exit 1; fi; '
439
+ "done; "
440
+ "else rm -f /tests && mkdir /tests; fi"
441
+ f"{owner} && rm -rf /tmp/tests.tgz && "
407
442
  )
408
443
  # The archive holds the hidden tests: left in /tmp, it stays readable by
409
444
  # whatever `test.sh` runs as another user, however /tests is protected.
410
- stage = (
411
- f"{'rm -rf /tests && ' if wipe else ''}"
412
- "mkdir -p /tests && tar -xzf /tmp/tests.tgz -C /tests && "
413
- "rm /tmp/tests.tgz"
414
- )
445
+ stage = "tar -xzf /tmp/tests.tgz -C /tests && rm -f /tmp/tests.tgz"
415
446
  # Verifier subprocesses can use different users; opening their log directory
416
447
  # requires its owner or root, even when it is already writable. A grading box
417
448
  # of its own starts with an empty log directory: anything already there came
418
449
  # from the image or from the agent's restored artifacts, not from this grader.
419
450
  isolated = wipe or self.scoring.mode == "isolated"
420
- setup = (
421
- runtime.with_user("root")
422
- if runtime.backend.SUPPORTS_USER_SWITCHING
423
- else runtime
451
+ prepare = (
452
+ f"{clear}{'rm -rf /logs/verifier && ' if isolated else ''}"
453
+ f"mkdir -p /logs/verifier {ARTIFACTS_DIR} && "
454
+ f"chmod 777 /logs/verifier {ARTIFACTS_DIR}"
424
455
  )
425
- for view, command in (
426
- (
427
- setup,
428
- (
429
- f"{'rm -rf /logs/verifier && ' if isolated else ''}"
430
- f"mkdir -p /logs/verifier {ARTIFACTS_DIR} && "
431
- f"chmod 777 /logs/verifier {ARTIFACTS_DIR}"
432
- ),
433
- ),
434
- (
435
- runtime,
436
- (
437
- "rm -f /logs/verifier/reward.json /logs/verifier/reward.txt && "
438
- f"{stage}"
439
- ),
440
- ),
441
- ):
442
- result = await view.run(["sh", "-c", command], {})
443
- if result.exit_code:
444
- raise TaskError(
445
- f"staging tests failed (exit {result.exit_code}): "
446
- f"{(result.stderr or result.stdout).strip()[-500:]}"
447
- )
456
+ result = await setup.run(["sh", "-c", prepare], {})
457
+ if result.exit_code:
458
+ raise TaskError(
459
+ f"staging tests failed (exit {result.exit_code}): "
460
+ f"{(result.stderr or result.stdout).strip()[-500:]}"
461
+ )
462
+ if clear:
463
+ await runtime.write(
464
+ "/tmp/tests.tgz", make_tar(Path(self.data.task_dir) / "tests")
465
+ )
466
+ result = await runtime.run(
467
+ [
468
+ "sh",
469
+ "-c",
470
+ f"rm -f /logs/verifier/reward.json /logs/verifier/reward.txt && {stage}",
471
+ ],
472
+ {},
473
+ )
474
+ if result.exit_code:
475
+ raise TaskError(
476
+ f"staging tests failed (exit {result.exit_code}): "
477
+ f"{(result.stderr or result.stdout).strip()[-500:]}"
478
+ )
448
479
 
449
480
  @reward(weight=1.0)
450
481
  async def solved(self, runtime: Runtime, trace: Trace) -> float | dict[str, float]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev136
3
+ Version: 0.4.2.dev138
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
@@ -6,7 +6,7 @@ verifiers/v1/env.py,sha256=5F-LhPLAfVNwcco2TR-OOAnv0QtIj49X8pc_dSa-Hgk,20748
6
6
  verifiers/v1/episode.py,sha256=Tqjo8aQDOh4sM03he2WMXzEhmn2ybzwwtUS_QSvESsA,6983
7
7
  verifiers/v1/errors.py,sha256=sgguxm402rbWmCNar7kHpekb30VA7wvE88GBG8890v8,6049
8
8
  verifiers/v1/grading.py,sha256=ukULZ4BW8ecj0HX7g1w4kN7R4qs2TmDOSr9XFN6gI-Y,15095
9
- verifiers/v1/graph.py,sha256=_IEMMdOJ7TAy2TM9H9LZBAeYCgV9-Uo8XtfTUdg_aBI,48582
9
+ verifiers/v1/graph.py,sha256=S3ALWqy2ohkwUnmf2u04zyjX6t5lioVAHx_8LptjqBQ,48797
10
10
  verifiers/v1/harness.py,sha256=3jJjA_Td8f61jzN33J7h0Hk_hUCe_pqh_ePjH_EVg7c,19067
11
11
  verifiers/v1/judge.py,sha256=T-TyYVcLGIoyUADYKy_pCBj2CTLhERlct5pmmWqPpTA,10507
12
12
  verifiers/v1/restore.py,sha256=DA1Tcj0HZkUNOxrmMOJwR25WtCKdsZCTYBJZIf2RWUM,8861
@@ -154,7 +154,7 @@ verifiers/v1/runtimes/backends/prime.py,sha256=Z_Sp3Y5yUXWVcmgEEO_1QMeV_HKRyWAaY
154
154
  verifiers/v1/runtimes/backends/subprocess.py,sha256=7JIEetsJWELIf410tkJOcntHT3D_6TPXcsMD3IfhWTw,8595
155
155
  verifiers/v1/tasksets/__init__.py,sha256=2ijE3qIlLoUA02g6iysOwWQylyBBQL1GhSpjv8_bp0w,521
156
156
  verifiers/v1/tasksets/harbor/__init__.py,sha256=FjW4tM3rgGALMK-8p7ux26G4-d4ZFVmaAmO6Fni6e_g,214
157
- verifiers/v1/tasksets/harbor/taskset.py,sha256=d2-_d5KB6g06iYsyI_4hX0zFoptFj9ejRyevrfjXJfs,44279
157
+ verifiers/v1/tasksets/harbor/taskset.py,sha256=rUqhGF7LAYxNqkAE0DBDldSjSBgkFCHeIG7XNQTNIl0,46158
158
158
  verifiers/v1/tasksets/harbor/toolset.py,sha256=l-h1GATE9HLnEjb844CzBAiVLkPmE-XarjBlQ2ec5gM,3969
159
159
  verifiers/v1/tasksets/nemo_gym/__init__.py,sha256=654gAvG3Wd_Z_nh6mypeKn4s_IIQ0Ge6vcZvxTHC2_E,306
160
160
  verifiers/v1/tasksets/nemo_gym/response.py,sha256=EhrsquEP8g0bjzAThGfE6Ypgy86_nVX235NiFYtVDVM,4463
@@ -188,8 +188,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
188
188
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
189
189
  verifiers/v1/utils/trace_store.py,sha256=7F6xMhYgl3qmylnCU8-ekqswH16fUat1uegeM1OR9QQ,2563
190
190
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
191
- verifiers-0.4.2.dev136.dist-info/METADATA,sha256=clrnyH5MHixC06Z04cYB9cIyuMH_U60DArWfykcBea8,5118
192
- verifiers-0.4.2.dev136.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
193
- verifiers-0.4.2.dev136.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
194
- verifiers-0.4.2.dev136.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
195
- verifiers-0.4.2.dev136.dist-info/RECORD,,
191
+ verifiers-0.4.2.dev138.dist-info/METADATA,sha256=tsfRbWwCZYEn5dzVxhll4g6tn6GBsrc39ZsGclOc1RQ,5118
192
+ verifiers-0.4.2.dev138.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
193
+ verifiers-0.4.2.dev138.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
194
+ verifiers-0.4.2.dev138.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
195
+ verifiers-0.4.2.dev138.dist-info/RECORD,,