Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/development/lessons.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u
- **Trigger:** Forwarding streamed model responses through the loopback gateway.
- **Lesson:** [Issue #274](https://github.com/ThinkFlowLab/OpenDirector/issues/274) reproduced bundled OpenCode 1.19.5 / Bun 1.4.4 receiving every byte of a close-delimited response but never completing its body reader. Tools could execute before a 300-second timeout replayed the same model context. Python consumers completed the same response, so Python-only tests missed the integration failure.
- **Check:** Preserve incremental forwarding with explicit HTTP framing. Terminate the body only after successful upstream exhaustion; leave transport failures and cancellation distinguishable from completion. Exercise the actual bundled consumer with a local mock model, asserting request and tool execution counts, continuation with tool results, final text and persisted state. HTTP completion is not model completion or business acceptance.
- **OpenCode worker follow-up:** A [same-runner comparison](https://github.com/FayeSpica/OpenDirector/actions/runs/47029419494) reproduced the visual watchdog after the full OpenCode prefix in three legacy runs. Three interleaved runs passed with per-worker temporary, XDG, pytest and POSIX home paths. Apply the same isolation before launching both ordinary workers and forced-timeout workers. The experiment changed these paths together, so it does not identify a single trigger.

## Native reply text can contain presentation protocols

Expand Down
41 changes: 35 additions & 6 deletions tests/test_native_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ async def consume():
assert json.loads(saved.read_text()) == previous


def isolated_worker_launch(
tmp_path: Path, node_id: str, extra_env: dict[str, str] | None = None
) -> tuple[list[str], dict[str, str]]:
env = {**os.environ, **(extra_env or {}), 'OPENDIRECTOR_REAL_CLI_WORKER': '1'}
args = [sys.executable, '-m', 'pytest', node_id, '-s', '-q']
state = tmp_path / 'worker-state'
paths = {
'TMPDIR': 'tmp',
'TMP': 'tmp',
'TEMP': 'tmp',
'XDG_DATA_HOME': 'data',
'XDG_STATE_HOME': 'state',
'XDG_CACHE_HOME': 'cache',
'XDG_CONFIG_HOME': 'config',
'PYTEST_DEBUG_TEMPROOT': 'workers',
}
if os.name != 'nt':
paths.update(HOME='home', XDG_RUNTIME_DIR='runtime')
for variable, name in paths.items():
path = state / name
path.mkdir(parents=True, exist_ok=True)
env[variable] = str(path)
if os.name != 'nt':
Path(env['XDG_RUNTIME_DIR']).chmod(0o700)
env['OPENDIRECTOR_WORKER_STATE_ISOLATED'] = '1'
return [*args, '--basetemp', str(state / 'pytest')], env


@pytest.fixture
def real_opencode_worker(tmp_path, monkeypatch, request):
"""Bound real CLI cases in isolated workers and clean up owned processes."""
Expand All @@ -365,14 +393,15 @@ def real_opencode_worker(tmp_path, monkeypatch, request):
assert native.executable('default') is not None, 'Bundled OpenCode is not installed'
timeout = 105 if 'windows_unicode_pipeline' in request.node.name else 60
if os.environ.get('OPENDIRECTOR_REAL_CLI_WORKER') != '1':
result = subprocess.run([sys.executable, '-m', 'pytest', request.node.nodeid, '-s', '-q'],
env={**os.environ, 'OPENDIRECTOR_REAL_CLI_WORKER': '1'},
args, env = isolated_worker_launch(tmp_path, request.node.nodeid)
result = subprocess.run(args, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", errors="replace", timeout=timeout + 30)
assert result.returncode == 0, result.stdout
return False

for name in ('XDG_DATA_HOME', 'XDG_STATE_HOME', 'XDG_CACHE_HOME'):
monkeypatch.setenv(name, str(tmp_path / name.lower()))
if os.getenv('OPENDIRECTOR_WORKER_STATE_ISOLATED') != '1':
for name in ('XDG_DATA_HOME', 'XDG_STATE_HOME', 'XDG_CACHE_HOME'):
monkeypatch.setenv(name, str(tmp_path / name.lower()))
from opendirector.agent.process import _signal_tree
processes = []
spawn = asyncio.create_subprocess_exec
Expand Down Expand Up @@ -780,8 +809,8 @@ def test_real_opencode_watchdog_cleans_up_stalled_cli(tmp_path):
pytest.skip('Bundled OpenCode is not installed')
marker = tmp_path / 'pid'
case = f'{__file__}::test_real_opencode_native_skill_and_gateway_write[False-default]'
result = subprocess.run([sys.executable, '-m', 'pytest', case, '-s', '-q'],
env={**os.environ, 'OPENDIRECTOR_REAL_CLI_WORKER': '1', 'OPENDIRECTOR_TEST_CLI_STALL': str(marker)},
args, env = isolated_worker_launch(tmp_path, case, {'OPENDIRECTOR_TEST_CLI_STALL': str(marker)})
result = subprocess.run(args, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, timeout=25)
assert result.returncode != 0
assert 'stage: fresh turn' in result.stdout
Expand Down
Loading