Find code by asking what it does. A CLI for coding agents that uses Jev to discover relevant files and source context.
TypeScript ai-sdkclaude-codeclicode-searchcodexcoding-agentscontext-retrievaldeveloper-toolsjevsemantic-searchtypescriptvercel-ai-gateway
Keep treatment lifecycle consistent with extended work clock
David Zhangd08a14d6c304
diff --git a/evals/implementation/swebench/installed.md b/evals/implementation/swebench/installed.mdindex 6e2c65c..31b9ed6 100644--- a/evals/implementation/swebench/installed.md+++ b/evals/implementation/swebench/installed.md@@ -78,10 +78,15 @@ billing, cohort acceptance and exact body capture through a synthetic provider.New schema-3 plans freeze a 900-second treatment **work** budget. The monitor useshost monotonic observation of native `command_execution` started/completed events.+Only native command-execution events establish concurrent work for this clock.It excludes the union of standalone `jg` search waits only while no other commandis active. Overlapping retrieval calls earn no double credit; unrelated concurrentcommands count as work. Completion, cancellation, terminal turns and process EOF-end credit. A separate 24-hour wall limit protects against a runaway retrieval.+end credit. Nonterminal error/reconnect events do not end an active command.+A separate 24-hour wall limit protects against a runaway retrieval. The task+container stays alive for setup and artifact capture until lifecycle cleanup; it+has no competing shorter sleep deadline. An expired clock always records a failed+attempt, even if the native process has already exited zero while output drains.Receipts retain work, credited retrieval and wall durations plus the disjointcredit intervals and native command IDs, so timing remains auditable.diff --git a/evals/implementation/swebench/installed.py b/evals/implementation/swebench/installed.pyindex f429a90..e698761 100644--- a/evals/implementation/swebench/installed.py+++ b/evals/implementation/swebench/installed.py@@ -324,7 +324,7 @@ def monitor_native(invocation, stdout, stderr, policy):value = json.loads(line)item = value.get('item', {})kind = value.get('type')- if kind in ('turn.completed', 'turn.failed', 'error'):+ if kind in ('turn.completed', 'turn.failed'):close_credit(now)active.clear()elif kind in ('item.started', 'item.completed') and item.get('type') == 'command_execution':@@ -421,9 +421,11 @@ def run(args):command(['docker', 'network', 'create', '--internal', network])command(['docker', 'run', '-d', '--name', proxy, '--label', 'jg.cell=' + cell['id'], '-e', 'JEVGREP_TRACE_DIR=/run/jev-traces', image, 'python3', '-u', '-c', (HERE / 'gateway_broker.py').read_text()])command(['docker', 'network', 'connect', '--alias', 'model-egress', network, proxy])+ # The monitor owns the deadline; keep the container alive for setup and+ # artifact capture too, then remove it in finally.command(['docker', 'run', '-d', '--name', tag, '--label', 'jg.cell=' + cell['id'], '--network', network,'-e', 'HTTP_PROXY=http://model-egress:3128', '-e', 'HTTPS_PROXY=http://model-egress:3128',- '-e', 'NO_PROXY=localhost,127.0.0.1,model-egress', image, 'sleep', '1800'])+ '-e', 'NO_PROXY=localhost,127.0.0.1,model-egress', image, 'sleep', 'infinity'])dx(['sh', '-c', 'useradd -m -u 1001 agent; mkdir -p /home/agent/.codex /home/agent/.claude /workspace; chown -R agent:agent /home/agent /workspace'])receipt['official_image_head'] = dx(['git', '-C', '/testbed', 'rev-parse', 'HEAD']).stdout.decode().strip()receipt['official_source_status'] = dx(['git', '-C', '/testbed', 'status', '--porcelain']).stdout.decode()@@ -495,7 +497,8 @@ def run(args):sessions = list((out / 'codex-sessions').rglob('*.jsonl'))if len(sessions) == 1:shutil.copyfile(sessions[0], out / 'raw-rollout.jsonl')- receipt['status'] = 'completed' if receipt.get('exit_code') == 0 and receipt['native_completed'] and receipt['required_retrieval_observed'] else 'failed'+ receipt['status'] = 'completed' if (not receipt['timed_out'] and receipt.get('exit_code') == 0 and+ receipt['native_completed'] and receipt['required_retrieval_observed']) else 'failed'except Exception as error:receipt['status'] = 'failed'# Tool output may contain environment arguments: retain error types, never raw commands or keys.diff --git a/evals/implementation/swebench/test_installed.py b/evals/implementation/swebench/test_installed.pyindex a07e58b..2652e95 100644--- a/evals/implementation/swebench/test_installed.py+++ b/evals/implementation/swebench/test_installed.py@@ -9,6 +9,7 @@ import ioimport jsonimport osimport sys+import subprocessfrom pathlib import Pathimport tempfileimport threading@@ -63,6 +64,18 @@ class InstalledTests(unittest.TestCase):self.assertEqual(result['credit_intervals'][0]['command_ids'], ['search'])self.assertIn('turn.completed', events)+ def test_nonterminal_error_during_retrieval_preserves_credit_until_completion(self):+ command = 'jg "research"'+ result, events = self.monitor([self.event('search', command), 0.3,+ {'type':'error','message':'stream reconnecting'}, 3.2,+ self.event('search', command, True), {'type':'turn.completed'}])+ self.assertEqual(result['exit_code'], 0)+ self.assertFalse(result['timed_out'])+ self.assertEqual(result['timing_event_errors'], 0)+ self.assertGreater(result['retrieval_wait_seconds'], 3)+ self.assertEqual(len(result['credit_intervals']), 1)+ self.assertIn('turn.completed', events)+def test_unrelated_command_reaches_work_deadline(self):result, events = self.monitor([self.event('test', "python -m unittest"), 3,{'type':'turn.completed'}])@@ -170,6 +183,59 @@ class InstalledTests(unittest.TestCase):'required_retrieval_observed':True,'timing_valid':True,'native_completed':True,'exit_code':0,'host_pid':os.getpid()})return out+ def test_timeout_with_zero_exit_retains_patch_but_cannot_complete_treatment(self):+ with tempfile.TemporaryDirectory() as temporary:+ path, plan = self.fixture(Path(temporary))+ calls, elapsed, lifetime = [], [0], [float('inf')]+ def docker(argv, checked=True, **kwargs):+ calls.append(argv)+ if argv[:3] == ['docker', 'run', '-d'] and argv[-2] == 'sleep':+ lifetime[0] = float(argv[-1])+ if argv[:2] == ['docker', 'exec'] and elapsed[0] >= lifetime[0]:+ if checked:+ raise subprocess.CalledProcessError(1, ['docker', 'exec'])+ return subprocess.CompletedProcess(argv, 1, b'', b'container stopped')+ output = b''+ if argv[-2:] == ['rev-parse', 'HEAD']:+ output = plan['cell']['expected_image_head'].encode()+ elif argv[-2:] == ['rev-parse', 'HEAD^{tree}']:+ output = plan['cell']['expected_source_tree'].encode()+ elif argv[-1:] == ['--version'] and argv[-2] in runner.VERSIONS:+ output = runner.VERSIONS[argv[-2]].encode()+ elif 'sha256sum' in argv:+ output = (runner.digest(plan['skill']) + ' skill').encode()+ elif 'diff' in argv:+ output = b'fixture patch'+ return subprocess.CompletedProcess(argv, 0, output, b'')+ def expired(invocation, stdout, stderr, policy):+ # Native completion can already be in the pipe when the work+ # deadline is noticed. A zero OS exit cannot override that clock.+ # Simulate an hour of retrieval plus expired work. Docker's+ # task container must remain available for patch extraction.+ elapsed[0] = 4501+ events = [self.event('search', 'jg "research"', True), {'type':'turn.completed'}]+ stdout.write(('\n'.join(json.dumps(e) for e in events) + '\n').encode())+ return {'exit_code':0,'timed_out':True,'timeout_kind':'work',+ 'wall_seconds':4501,'work_seconds':901,'retrieval_wait_seconds':3600,+ 'credit_intervals':[],'timing_event_errors':0}+ with patch.object(runner, 'check_image', return_value=plan['cell']['image']), \+ patch.object(runner, 'command', side_effect=docker), \+ patch.object(runner.subprocess, 'run', side_effect=lambda argv, **kw: docker(argv, checked=False, **kw)), \+ patch.object(runner, 'monitor_native', side_effect=expired), \+ patch.dict(os.environ, {'AI_GATEWAY_API_KEY':'fixture-only'}), contextlib.redirect_stdout(io.StringIO()):+ with self.assertRaises(SystemExit):+ runner.run(argparse.Namespace(plan=path, dry_run=False, task=None))+ out = Path(plan['output'])+ receipt = json.loads((out/'receipt.json').read_text())+ self.assertEqual(receipt['exit_code'], 0)+ self.assertTrue(receipt['timed_out'])+ self.assertTrue(receipt['native_completed'])+ self.assertTrue(receipt['required_retrieval_observed'])+ self.assertEqual(receipt['status'], 'failed')+ self.assertFalse(runner.protocol_valid(receipt))+ self.assertEqual((out/'agent.patch').read_bytes(), b'fixture patch')+ self.assertEqual(sum(call[:3] == ['docker', 'rm', '-f'] for call in calls), 2)+def test_dry_run_validates_pair_without_credentials_or_agent(self):with tempfile.TemporaryDirectory() as temporary:path,plan=self.fixture(Path(temporary))