Repository navigation
Surface SessionStart status messages from the host bootstrap - #15
Conversation
The managed host-enrollment bootstrap runs on every Claude/Codex SessionStart but its status was invisible: it printed a raw status JSON object to stdout, which both harnesses parse as structured hook output. Those keys are not recognized control fields, so nothing reached the user (and nothing reached the model either). Use the harness-supported `systemMessage` hook output field so the bootstrap can actually surface its status to the user: - Plugin-update notices (both Claude and Codex): compare the installed plugin version from the managed-runtime manifest against a per-host last-seen version persisted in the host data dir, and announce the change once per upgrade. Silent on first install and when the version is unknown so the rollout does not falsely announce an update. This runs before the enrollment gate so every install (not just enrolled hosts) gets it. - Claude enrollment outcomes: show a message only when something actionable happened (config just written, awaiting approval, blocked). The already-configured steady state, the gate-disabled state, and transient errors stay silent so the hook does not banner every session. The status JSON stays in the payload for manual troubleshooting and the worker check-in is unchanged; the extra `systemMessage` field is ignored by the host hook parsers when present.
| # and Codex render the SessionStart `systemMessage`. | ||
| plugin_root = _plugin_root() | ||
| metadata = _load_runtime_metadata(plugin_root, host) | ||
| update_notice = _plugin_update_notice(metadata) |
There was a problem hiding this comment.
[Medium] The new update-notice path is best-effort UI messaging, but it now runs before the auth gate and can raise while reading, locking, or writing the state file. That means a missing/unwritable/corrupt host data dir turns an otherwise gate-disabled or healthy SessionStart into an error before enrollment/configuration can proceed; after an upgrade it can also mark the version seen before any later failure emits the notice. Wrap plugin-update notice generation in local error handling and return no notice on state I/O/parse failures, or defer the last-seen write until after a successful hook output.
Codex SessionStart hooks support the same `systemMessage` field as Claude, so surface the enrollment status on both hosts (not just Claude) with host-appropriate wording and config paths. Reword the fresh-config prompt to "Restart <host> to start telemetry".
| last_seen_version = _string_value(seen_versions.get(metadata.target)) | ||
| if last_seen_version == current_version: | ||
| return None | ||
| seen_versions[metadata.target] = current_version |
There was a problem hiding this comment.
[Medium] _plugin_update_notice writes the new last_seen_plugin_versions value before any systemMessage is actually emitted. If a later step raises (for example worker/network failure, invalid policy, or config write failure), main() emits only the error payload and the version has already been marked seen, so the user never receives the one-time update notice on a later successful session. Defer persisting the new version until after the notice is included in emitted hook output, or carry the pending notice through the exception path and only mark it seen once surfaced.
The update-notice path runs before the enrollment gate, so a missing, unwritable, or corrupt host data dir must not turn an otherwise healthy or gate-disabled SessionStart into an error. Split the work in two: - _pending_plugin_update reads the last-seen version read-only and swallows state I/O/parse failures, yielding no notice instead of raising. - _record_plugin_version_seen persists the new version only after the hook output (including any notice) is emitted, and only on non-quiet runs. An exception during enrollment now skips recording, so the one-time notice re-appears on the next healthy session instead of being lost. It re-reads state under the lock so a credential written by the enrollment step in the same run is preserved. Adds tests for the gate-disabled corrupt-state case and for the upgrade-then-failure-then-recovery sequence.
…-success-messages # Conflicts: # src/promptless_instruction_hub/managed_runtime_assets/host-enrollment/promptless-host-enrollment-bootstrap
Codex Bug BotNo new bugs detected in this PR. |
) ## Problem Codex now fails the host-enrollment `SessionStart` hook every session: ``` • SessionStart hook (failed) error: hook returned invalid session start JSON output ``` The bootstrap writes its **full diagnostic status object** to **stdout** on every `SessionStart`: ```json {"host":"codex","needs_restart":true,"status":"needs_restart","systemMessage":"Promptless telemetry configured for Codex. Restart Codex to start telemetry."} ``` Codex validates SessionStart hook **stdout** against a strict schema — its Rust parser deserializes into a fixed struct with serde `deny_unknown_fields`, accepting only `continue` / `stopReason` / `systemMessage` / `suppressOutput` / `hookSpecificOutput`. Our diagnostic keys (`status`, `host`, `needs_restart`, `reason`) are outside that schema, so Codex rejects the whole object as *"invalid session start JSON output"*. This hits **every** Codex session — including the common gate-disabled steady state (`{"status":"disabled",...}`), not just the configured case. (Strict per-event validation confirmed by [openai/codex#18887](openai/codex#18887), [#27052](openai/codex#27052).) The premise added in #15 — *"the extra field is ignored by the host hook parsers"* — holds for **Claude Code** (lenient: ignores unrecognized top-level fields, which is why Claude never errored) but is **false for Codex** (strict). The error actually first appeared in #11, which dropped `--quiet` and started writing this JSON to Codex's stdout; #15 added `systemMessage` on the same wrong assumption and so didn't fix it. ## Fix Split the streams in `_emit`: - **stdout** carries only the schema-valid `systemMessage` (`{"systemMessage": "..."}`), and **nothing at all** when there is no message — Codex treats empty stdout as success. - **stderr** carries the full diagnostic object (`status` / `host` / `needs_restart` / `reason`, plus the message), which neither host parses as hook output but stays available for manual troubleshooting (the `--quiet`-off intent from #11). Claude keeps rendering the `systemMessage` banner; Codex stops erroring. ## Tests - A shared `_assert_session_start_streams` helper now asserts the split on **every** bootstrap run: stdout is empty or exactly `{systemMessage}` (never the schema-breaking keys), stderr carries the diagnostic. This guards all existing cases against future stdout leaks. - New `test_bootstrap_stdout_stays_codex_schema_safe` pins the exact Codex-breaking fields out of stdout and verifies steady-state stdout is empty. - Updated two gate-disabled assertions (`stderr == ""` → `stdout == ""`) since the diagnostic now lives on stderr. ## Validation - `uv run pytest` — **136 passed** - `uv run ruff check src tests`, `uv run ruff format --check src tests`, `uv run ty check src tests` — clean - Bootstrap script (extensionless, missed by CI globs) `py_compile`s and is ruff/format-clean - Manual smoke test of the gate-disabled Codex path: stdout is now empty (Codex success), diagnostic on stderr
Summary
The managed host-enrollment bootstrap runs on every Claude/Codex
SessionStart, but its status was effectively invisible. It printed a raw status JSON object (e.g.{"status":"configured","host":"claude",...}) to stdout — which both harnesses parse as structured hook output. Those keys aren't recognized control fields, so nothing reached the user (and nothing reached the model either).This switches the bootstrap to the harness-supported
systemMessagehook-output field, which both Claude Code and Codex render to the user (Codex docs: "systemMessage— Surfaced as a warning in the UI or event stream"; Claude docs: "Warning message shown to the user"). Two things now surface, on both hosts:1. Plugin-update notices
Neither harness has a plugin install/update event, so we use the documented version-diff pattern: each run, compare the installed plugin version (from the managed-runtime manifest) against a per-host last-seen version persisted in the host data dir (which survives plugin updates), and announce the change once per upgrade.
2. Enrollment outcomes
Shows a message only when something actionable happened: config just written (restart to apply), awaiting browser approval, or blocked. The already-configured steady state, the gate-disabled state, and transient errors stay silent so the hook doesn't banner every session. Wording and the referenced config path are host-appropriate.
When both fire in the same session, they combine into one
systemMessage. The status JSON stays in the payload for manual troubleshooting and the worker check-in is unchanged.Notes
BOOTSTRAP_VERSIONis unchanged (0.1.0) — it drives workerrequired_bootstrap_versionpolicy gating, not feature tracking, and this change has no worker-contract impact.Validation
uv run pytest tests/test_managed_bootstrap.py— 23 passed (new/updated tests: plugin-update announced per host with first-install + steady-state silence and per-host keying; both hosts surface the enrollment message only on change; blocked surfaces on both hosts).uv run ruff check src tests,uv run ruff format --check src tests,uv run ty check src tests— all clean. Bootstrap scriptpy_compiles and is ruff/format-clean (note: the script has no.pyextension so CI'ssrc testsglobs don't lint it — pre-existing).