Skip to content

Surface SessionStart status messages from the host bootstrap - #15

Merged
adit-chandra merged 4 commits into
mainfrom
adit/claude-bootstrap-success-messages
Jun 30, 2026
Merged

adit-chandra merged 4 commits into
mainfrom
adit/claude-bootstrap-success-messages

Conversation

@adit-chandra

@adit-chandra adit-chandra commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

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 systemMessage hook-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.

  • Runs before the enrollment gate, so every install — not just enrolled hosts — gets it.
  • Silent on first install and when the version is unknown, so rolling this out doesn't falsely announce an update.
  • Keyed by host so a data dir shared between Claude and Codex tracks each version independently.

Promptless Instruction Hub updated to v0.2.0 (was v0.1.0).

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.

Promptless telemetry configured for Claude Code. Restart Claude Code to start telemetry.
Promptless telemetry configured for Codex. Restart Codex to start telemetry.

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_VERSION is unchanged (0.1.0) — it drives worker required_bootstrap_version policy gating, not feature tracking, and this change has no worker-contract impact.
  • The Python bootstrap is dogfood-only; customer-grade releases will ship a static native binary with the same behavior.

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 script py_compiles and is ruff/format-clean (note: the script has no .py extension so CI's src tests globs don't lint it — pre-existing).
  • The live render is the one thing tests can't prove; confirm in a real Claude Code / Codex session that the banner appears. Mechanism verified against the official Claude and Codex hooks docs.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Bug Bot

Found 1 potential bug introduced by this PR.

1 inline comment(s) below.

# and Codex render the SessionStart `systemMessage`.
plugin_root = _plugin_root()
metadata = _load_runtime_metadata(plugin_root, host)
update_notice = _plugin_update_notice(metadata)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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".

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Bug Bot

Found one new bug: plugin update notices can be marked as seen before they are actually surfaced, so transient bootstrap failures can permanently suppress the one-time notice.

1 inline comment(s) below.

last_seen_version = _string_value(seen_versions.get(metadata.target))
if last_seen_version == current_version:
return None
seen_versions[metadata.target] = current_version

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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
@github-actions

Copy link
Copy Markdown

Codex Bug Bot

No new bugs detected in this PR.

@adit-chandra
adit-chandra merged commit 4a68deb into main Jun 30, 2026
6 checks passed
@adit-chandra
adit-chandra deleted the adit/claude-bootstrap-success-messages branch June 30, 2026 04:05
adit-chandra added a commit that referenced this pull request Jun 30, 2026
)

## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant