From f35003771c4037ed2c11934b309faa6c71e0e554 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Nov 2026 09:21:12 +0000 Subject: [PATCH 1/2] Fix Codex auto worker launch and document live cockpit feedback --- agents/conductors/batch/_codex.py | 4 ++-- bin/codex_orchestrator_check.py | 10 ++++++---- docs/codex_orchestrator.md | 3 ++- skills/COMMANDS.md | 2 +- skills/batch/reference.md | 7 ++++++- skills/cockpit/SKILL.md | 2 +- skills/cockpit/cockpit.md | 12 +++++++++++- tests/test_orchestrator_codex.py | 26 +++++++++++++++++++++++++- 8 files changed, 54 insertions(+), 12 deletions(-) diff --git a/agents/conductors/batch/_codex.py b/agents/conductors/batch/_codex.py index 35ee0d96..ba5d635d 100644 --- a/agents/conductors/batch/_codex.py +++ b/agents/conductors/batch/_codex.py @@ -155,12 +155,12 @@ def command(model: str, effort: str, mode: str, cwd: Path, write_root: Path) -> "-c", f"model_reasoning_effort={json.dumps(effort)}", "-c", 'model_provider="openai"', "-c", 'forced_login_method="chatgpt"', "-c", "features.multi_agent=false", "-c", "features.goals=false", # usage is for this worker only - "--sandbox", "workspace-write", "--cd", str(cwd), + "--cd", str(cwd), "--add-dir", str(write_root), "--skip-git-repo-check"] if mode == "auto": argv.append("--approve-for-me") else: - argv += ["-c", 'approval_policy="never"'] + argv += ["--sandbox", "workspace-write", "-c", 'approval_policy="never"'] return argv + ["-"] diff --git a/bin/codex_orchestrator_check.py b/bin/codex_orchestrator_check.py index b791991f..f897690c 100644 --- a/bin/codex_orchestrator_check.py +++ b/bin/codex_orchestrator_check.py @@ -40,7 +40,7 @@ def check() -> dict: 'verify gh auth and Heart before a shift. This check starts no model.'} -def smoke(model: str) -> dict: +def smoke(model: str, mode: str = 'auto') -> dict: # Disposable workspace: no repositories, shift grants or publication. import shutil @@ -52,7 +52,7 @@ def smoke(model: str) -> dict: 'Do not read other projects, call another model, use the network, ' 'create a task, commit, push or launch any background work.') lease = _codex.launch(prompt, home=home, cwd=root, write_root=root, model=model, - effort='medium', mode='dontAsk', env=dict(os.environ)) + effort='medium', mode=mode, env=dict(os.environ)) sid = lease['agent_id'] try: end = time.monotonic() + 300 @@ -62,7 +62,7 @@ def smoke(model: str) -> dict: usage = _codex.usage(sid, home) passed = state == 'done' and marker.exists() and marker.read_text().strip() == 'PYAUTO_CODEX_OK' return {'ok': passed and usage is not None, 'state': state, 'usage': usage, - 'marker': passed, 'scope': 'no-op only; no development/merge readiness claim'} + 'marker': passed, 'worker_mode': mode, 'scope': 'no-op only; no development/merge readiness claim'} time.sleep(.2) return {'ok': False, 'error': 'smoke timed out after 300 seconds'} finally: @@ -83,12 +83,14 @@ def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--smoke', action='store_true', help='explicitly run one no-op model session') parser.add_argument('--model', help='installed Codex model id; required with --smoke') + parser.add_argument('--worker-mode', choices=('auto', 'dontAsk'), default='auto', + help='worker approval mode exercised by --smoke (default: auto)') args = parser.parse_args() if args.smoke and not args.model: parser.error('--smoke requires --model') result = check() if args.smoke and result['ok']: - result = smoke(args.model) + result = smoke(args.model, args.worker_mode) print(json.dumps(result, indent=2)) return 0 if result['ok'] else 1 diff --git a/docs/codex_orchestrator.md b/docs/codex_orchestrator.md index e75b9b71..a03b161e 100644 --- a/docs/codex_orchestrator.md +++ b/docs/codex_orchestrator.md @@ -105,7 +105,8 @@ After the read-only check passes, explicitly run one disposable no-op session: python3 PyAutoBrain/bin/codex_orchestrator_check.py --smoke --model ``` -This consumes a Codex session. It verifies launch, completion, a written marker +This uses the production auto-mode launcher and consumes one Codex session. +Pass `--worker-mode dontAsk` to exercise that mode instead. It verifies launch, completion, a written marker and usage in a temporary workspace. It does not create an issue, PR or shift, run a reviewer, or prove repository permissions. It times out after five minutes. diff --git a/skills/COMMANDS.md b/skills/COMMANDS.md index 2dc01d49..79d764bc 100644 --- a/skills/COMMANDS.md +++ b/skills/COMMANDS.md @@ -124,7 +124,7 @@ call, so the Brain is not bypassed): as `/queue` writes the queue. - **`/cockpit`** — watch a running shift from chat and steer it - (PyAutoBrain#646). One Monitor on the canonical `batch watch --stream` + (PyAutoBrain#646). Codex reads in the current turn; Claude uses one Monitor on the canonical `batch watch --stream` command, inside the shift's window, re-armed only at `segment-end`; the one watch a session may hold (Mind `policy/shift_cockpit_watch.md`, enforced by the end-at-deliverable hook). Steering is one comment on the shift issue from diff --git a/skills/batch/reference.md b/skills/batch/reference.md index 99294643..cf1ab61c 100644 --- a/skills/batch/reference.md +++ b/skills/batch/reference.md @@ -74,7 +74,12 @@ without `issue:`, and an expired CLI login (the human runs `claude /login`). 45 min after `review-at:`. Never two open briefs at once. The watcher reads the `origin/main` ref of the Mind checkout in its env file **without fetching**, so push the brief from that checkout or `git fetch` it before -launch; otherwise the watcher idles with "no open brief". +launch; otherwise the watcher idles with "no open brief". After a push from a separate +worktree, also verify the configured Mind checkout contains the pushed brief: +compare the local file's `git hash-object` with `git rev-parse origin/main:batches/.md`. +When its `main` lags, use `git merge --ff-only origin/main` there and repeat +the comparison. If Git reports a conflict or the hashes differ, report that +pickup is blocked. Verify pickup with the first watcher tick or status comment. ## When the batch is complete diff --git a/skills/cockpit/SKILL.md b/skills/cockpit/SKILL.md index fe4a19cd..1deea5f7 100644 --- a/skills/cockpit/SKILL.md +++ b/skills/cockpit/SKILL.md @@ -1,6 +1,6 @@ --- name: cockpit -description: Watch a running shift from chat when the human asks for a watch (/cockpit, "watch the shift", "start the cockpit") — stream its events with Monitor and steer it by comments on the shift issue. A question about the shift gets a one-shot read, never a watch. In a /cockpit chat, a pasted prompt, path or dashboard copy line means /add it to the shift, never start dev. +description: Watch a running shift from chat when the human asks for a watch (/cockpit, "watch the shift", "start the cockpit") — stream its events in the current Codex turn or with Claude Monitor and steer it by comments on the shift issue. A question about the shift gets a one-shot read, never a watch. In a /cockpit chat, a pasted prompt, path or dashboard copy line means /add it to the shift, never start dev. --- # Cockpit diff --git a/skills/cockpit/cockpit.md b/skills/cockpit/cockpit.md index 91efad0b..12de4d21 100644 --- a/skills/cockpit/cockpit.md +++ b/skills/cockpit/cockpit.md @@ -53,7 +53,17 @@ the record's `- issue:` line. ## 3. Attach -Call `Monitor` with `timeout_ms: 1800000`, description `shift events`, +In Codex, an explicit watch runs in the **current chat turn**. Run the canonical +command below in a foreground terminal session that returns a session handle. +Read incremental stdout from that same handle and relay each event in chat as +it arrives. Use short bounded waits so steering can interrupt the read. Carry +the printed cursor into the next segment only on exit 3. On user cancellation +or before ending the turn, interrupt and reap the stream reader. This detaches +the chat from the feed; stopping the shift requires the separate steering act +below. If foreground streaming is unavailable, give the user the same command +for their terminal. A status question alone still uses the one-shot snapshot. + +In Claude, call `Monitor` with `timeout_ms: 1800000`, description `shift events`, and exactly this command, in this flag order, with nothing before, after or around it: diff --git a/tests/test_orchestrator_codex.py b/tests/test_orchestrator_codex.py index d75d73d4..8fa5cb3c 100644 --- a/tests/test_orchestrator_codex.py +++ b/tests/test_orchestrator_codex.py @@ -128,7 +128,10 @@ def test_command_preserves_sandbox_and_model(mode, tmp_path): argv = _codex.command("selected-model", "high", mode, tmp_path, tmp_path / "worktrees") assert argv[:3] == ["codex", "exec", "--json"] assert argv[argv.index("--model") + 1] == "selected-model" - assert argv[argv.index("--sandbox") + 1] == "workspace-write" + if mode == "auto": + assert "--sandbox" not in argv # --approve-for-me selects workspace-write itself + else: + assert argv[argv.index("--sandbox") + 1] == "workspace-write" assert "features.multi_agent=false" in argv assert ("--approve-for-me" in argv) == (mode == "auto") assert "--trust" not in argv and "--dangerously-bypass-hook-trust" not in argv @@ -332,3 +335,24 @@ def test_check_default_does_not_launch_a_worker(tmp_path, monkeypatch): monkeypatch.setattr(check.subprocess, 'run', lambda *a, **kw: SimpleNamespace( returncode=0, stdout='--json --sandbox --add-dir --approve-for-me')) assert check.check()['ok'] + +@pytest.mark.parametrize(("options", "expected"), [([], "auto"), (["--worker-mode", "dontAsk"], "dontAsk")]) +def test_smoke_invokes_production_launcher_with_selected_mode(tmp_path, monkeypatch, options, expected): + import importlib.util + path = Path(orch.__file__).resolve().parents[3] / "bin" / "codex_orchestrator_check.py" + spec = importlib.util.spec_from_file_location("codex_check_mode_test", path) + check = importlib.util.module_from_spec(spec) + spec.loader.exec_module(check) + monkeypatch.setattr(check, "check", lambda: {"ok": True}) + monkeypatch.setattr(sys, "argv", ["check", "--smoke", "--model", "selected", *options]) + + def launch(prompt, *, cwd, mode, model, **kwargs): + assert mode == expected and model == "selected" + (cwd / "smoke-ok.txt").write_text("PYAUTO_CODEX_OK") + return {"agent_id": "disposable"} + + monkeypatch.setattr(_codex, "launch", launch) + monkeypatch.setattr(_codex, "state", lambda *_: "done") + monkeypatch.setattr(_codex, "usage", lambda *_: {"total": 1}) + monkeypatch.setattr(_codex, "stop", lambda *_: None) + assert check.main() == 0 From 521e830ccfe3487134dda120ff132a11400685ee Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 23 Nov 2026 09:32:20 +0000 Subject: [PATCH 2/2] Trim cockpit instructions to the skill budget --- skills/cockpit/cockpit.md | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/skills/cockpit/cockpit.md b/skills/cockpit/cockpit.md index 12de4d21..9abf18cf 100644 --- a/skills/cockpit/cockpit.md +++ b/skills/cockpit/cockpit.md @@ -13,11 +13,8 @@ Shared routing context: `PyAutoBrain/skills/COMMANDS.md`. ## Attach only when asked -Arm the watch only on an explicit request for one: `/cockpit`, "/cockpit -watch", "watch the shift", "start the cockpit" (policy condition 1: the human -asked for it in this session). A question ("what's the shift doing?", "is -anything stuck?") gets a one-shot answer from `batch watch --once` or the reads -in section 7, with no Monitor; offer the watch in one line if it would help. +Attach only when explicitly asked in this session, e.g. `/cockpit` or "watch the shift". +For a status question, answer once with `batch watch --once` or the reads in section 7, with no Monitor. ## The rule of this chat @@ -53,15 +50,10 @@ the record's `- issue:` line. ## 3. Attach -In Codex, an explicit watch runs in the **current chat turn**. Run the canonical -command below in a foreground terminal session that returns a session handle. -Read incremental stdout from that same handle and relay each event in chat as -it arrives. Use short bounded waits so steering can interrupt the read. Carry -the printed cursor into the next segment only on exit 3. On user cancellation -or before ending the turn, interrupt and reap the stream reader. This detaches -the chat from the feed; stopping the shift requires the separate steering act -below. If foreground streaming is unavailable, give the user the same command -for their terminal. A status question alone still uses the one-shot snapshot. +In Codex, run the command below in a foreground terminal during the **current chat turn**. +Read stdout from the same session handle with short, interruptible waits and relay each event as it arrives. +Resume only on exit 3 with the printed cursor. On cancellation or turn end, interrupt and reap the reader. +If streaming is unavailable, give the human the command for their terminal. In Claude, call `Monitor` with `timeout_ms: 1800000`, description `shift events`, and exactly this command, in this flag order, with nothing before, after or @@ -151,9 +143,8 @@ within 3 ticks (about 3 min), or `steer-unread` arrives, say so once. ## Stop watching -On "stop watching" or "close the cockpit", stop the Monitor with `TaskStop` -and say "Stopped watching; the shift carries on." The shift is unaffected (to -stop it, that is `/stop`). Do not arm again unless asked. +On "stop watching" or "close the cockpit", interrupt and reap the Codex reader or use Claude's `TaskStop`. +Confirm that the shift carries on. Resume watching only on request. ## 6. Questions @@ -184,9 +175,7 @@ second Monitor. - Arming anything after the shift ends, or re-arming after any exit but `segment-end`. -## Without Monitor (web, mobile, Codex) +## Without a streaming tool -Run `batch watch --once` in the foreground when asked, and steer by the same -comments. Nothing is armed. Without `gh`, post the steering comment and make -the reads through the GitHub MCP tools that -[`../GITHUB_ACCESS.md`](../GITHUB_ACCESS.md) maps each `gh` call to. +On web or mobile, use `batch watch --once` on request and steer through the shift issue. +When `gh` is unavailable, use the equivalents in [GitHub access](../GITHUB_ACCESS.md).