Skip to content
Draft
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
[0.2.0]: https://github.com/runedeck/rune/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/runedeck/rune/releases/tag/v0.1.0

## [Unreleased]

### Fixed

- Record a queued Codex message as `read` when the `postbox` hook sees its session's turn start with it, and list a message posted by name under the thread id Codex printed.
- Warn before `rune queue post` looks a Codex session up by name, and add a `hint` with the UUID when Codex refuses the name and names the session it matched.

## [0.6.0] - 2026-10-26

### Added
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ rune queue list --state posted # the postbox, changed by nothing

Every message is recorded in the postbox, `~/.rune/postbox.tsv`, one file for every session on the machine. Each event is one tab-separated line: timestamp, id, state, sender, harness, session, message. A tab, newline, or backslash in a message is escaped, so `rg` and `column -t -s $'\t'` read the file. Nothing is removed: a state change (`posted`, `queued`, `read`) is a new line with the message's id, and its last line is its state. The sender is `--from`, else the posting session as `harness:id`, else `user:<login>`.

Codex takes the message through its own queue, `codex queue --remote unix://`, the local app-server daemon that holds the running sessions, and the postbox records it as `queued`. A route's environment applies, so a profile that sets `CODEX_HOME` reaches the sessions of that home. The profile's arguments start a session, so they are not passed, and a warning names them. `--remote <ADDR>` and `--remote-auth-token-env <VAR>` reach another server. `--postbox` leaves a Codex message in the postbox instead. The result names the message id and the thread id that Codex printed.
Codex takes the message through its own queue, `codex queue --remote unix://`, the local app-server daemon that holds the running sessions, and the postbox records it as `queued`. A route's environment applies, so a profile that sets `CODEX_HOME` reaches the sessions of that home. The profile's arguments start a session, so they are not passed, and a warning names them. `--remote <ADDR>` and `--remote-auth-token-env <VAR>` reach another server. `--postbox` leaves a Codex message in the postbox instead. The result names the message id and the thread id that Codex printed, and the `queued` line names that thread id, so a message posted by name lists under its thread.

Post to a Codex session by its UUID, which the session reads from `CODEX_THREAD_ID`. Codex finds a UUID at once, but searches its server's sessions page by page for a name, which can take a minute or more. So a post by name warns before it starts. When Codex refuses a name and names the UUID it matched, the hint says to post with `--session <uuid>`.

Inside Claude Code's command sandbox, `post` cannot reach the socket of the Codex daemon, and `post` and `read` cannot write `~/.rune/`. Add `rune queue *` to `sandbox.excludedCommands`, as for `rune run *`.

Claude Code, agy, grok, cursor, and OpenCode have no queue for a running session, so their messages wait in the postbox as `posted`. A session reads them in one of two ways. The `postbox` hook handler adds them to Claude Code's session start and next prompt, and at the end of a Claude Code or Codex turn it keeps the turn going with the messages as the reason:

Expand All @@ -474,7 +478,7 @@ hooks:
events: [session.start, prompt.before, turn.finish]
```

Then run `rune hook install`. The hook reads by the session's id, so post to a Claude Code session by the id in its `CLAUDE_CODE_SESSION_ID`. A grok, agy, cursor, or OpenCode session runs `rune queue read --session <its id or name>`, as the rune skill tells it to. Inside Claude Code or Codex, `rune queue read` finds its own session in `CLAUDE_CODE_SESSION_ID` or `CODEX_THREAD_ID`.
Then run `rune hook install`. The hook reads by the session's id, so post to a Claude Code session by the id in its `CLAUDE_CODE_SESSION_ID`. In a Codex session, the same handler records a `queued` message as `read` when the queue starts the session's turn with it, because that turn's prompt is the message's text. A grok, agy, cursor, or OpenCode session runs `rune queue read --session <its id or name>`, as the rune skill tells it to. Inside Claude Code or Codex, `rune queue read` finds its own session in `CLAUDE_CODE_SESSION_ID` or `CODEX_THREAD_ID`.

`--json` makes every result one object (`posted`, `queued`, `read`, `list`, `dry_run`). `--dry-run` prints what would be posted with the message as `<message>`. A route that names no harness exits 125 with kind `unsupported_harness`. Every other exit status uses the table of `rune run`: the harness's own status passes through, and 124 to 127 are the runner's.

Expand Down
40 changes: 40 additions & 0 deletions docs/changes/queue-records-codex-reads/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Queue records Codex reads: design

## Approach

Codex gives no receipt when a session reads a queued message. It starts the session's next turn with the message as the prompt, and it fires its prompt *[hook][HOOK]* (`UserPromptSubmit`) for that turn, with the prompt text in the payload. So the `postbox` handler compares each prompt with the session's `queued` messages, and records a message whose text is the prompt as `read`. Text is compared after trimming both sides. A prompt the owner types matches nothing, and nothing changes.

This beat marking every `queued` message read at the session's next turn end: a turn the owner started before the queue delivered would then mark a message read that the session never saw. It also beat reading Codex's rollout files, which are Codex's own format.

A message posted by name is recorded under that name, and the hook gets the session id. So the `queued` line names the thread id from Codex's receipt, and a message's session is the one its last line names. A `read` line copies the session it reads for, so the rule holds for every state. Without a receipt line, the name stays, and the message stays `queued`.

For a name, Codex searches its server's sessions page by page, and a UUID needs no search. rune cannot shorten the search: Codex has no command that lists its sessions with their names (`codex agents` is an interactive browser), and the name index Codex keeps in `~/.codex/session_index.jsonl` lacks the thread from the field report. So the post warns before the search starts, and the warning is on stderr even when an outer timeout stops the post. When Codex refuses a name and names the UUIDs it matched, the failure's hint names them and `--session`.

## Evidence

The field report came from the Claude Code session `Proton/ai-demo` on 2026-10-27 (rune 0.6.0, Codex app-server daemon). The rest was read on the owner's machine.

| Fact | Source |
| --- | --- |
| The message posted at 19:46:29Z started a Codex turn, which fired `session.start` and `prompt.before` at 19:46:41Z | rune's hook records, `~/.local/state/rune/hooks/record/2026-10.jsonl` |
| That turn's user message equals the ledger text, all 1720 characters | Codex rollout of thread `01a15844-7b2e-71a0-aa88-b41f3c4622af` |
| `UserPromptSubmit` input has `prompt`, the user prompt about to be sent | [Codex hooks][CODEXHOOKS] |
| `--session Proton/ai-demo` ran past 60 s. With `--timeout 5m`, Codex exited 1: `Cannot verify a unique session label across server pages; matching session UUID: …` | field report |
| An unknown UUID was refused in 0.14 s, an unknown name in 45 s | `codex queue` 0.154.0 against the owner's daemon, 2026-10-28 |
| Codex has two name refusals: the unverified label above, and one that ends "use a session UUID to disambiguate" | strings of the Codex 0.154.0 binary |

## Structure

- `src/cli/queue/ledger.rs`: `fold` takes the session of the last line. `take_prompted` marks read the `queued` messages of one session whose text is the prompt, under the ledger's lock. `take_posted` and `take_prompted` share one locked read-and-append step.
- `src/cli/hook/adapters.rs`: on `prompt.before` with a prompt, the `postbox` handler calls `take_prompted` before it delivers `posted` messages. Codex still gets no context on a prompt.
- `src/cli/queue/mod.rs`: `queued_outcome` reads the receipt before it writes the `queued` line. `name_lookup_warning` joins the post's warnings. `failure_outcome` adds the hint from `session_hint` when no sandbox hint applies.

## Risks

- Codex changes the prompt it starts a queued turn with, for example with a prefix. The message then stays `queued`, as before this change.
- Codex starts one turn with two queued messages. Neither text equals the prompt, so both stay `queued`.
- The same text queued twice for one session is marked read by the first turn. Both messages reached the same session.
- Codex changes its refusal text. The hint then disappears, and the stderr tail still shows the refusal.

[HOOK]: ../../specs/glossary/hook.md
[CODEXHOOKS]: https://developers.openai.com/codex/hooks
30 changes: 30 additions & 0 deletions docs/changes/queue-records-codex-reads/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
status: proposed
---

# Queue records Codex reads

## Why

On 2026-10-27 a Claude Code session and a Codex session talked through `rune queue` from end to end, and the session that took part reported three faults ([field report][FIELDREPORT]). Two of them are rune's. A message posted for Codex stayed `queued` after Codex read and answered it, because rune hands the message to `codex queue` and never learns more. And `--session Proton/ai-demo` ran past 60 s with no explanation. With `--timeout 5m`, Codex then refused the name and named the matching UUID, and rune passed that through as a bare failure. The third fault, the command sandbox that blocks the Codex socket, belongs to the owner's sandbox settings.

## What Changes

- The `postbox` *[hook][HOOK]* handler records a `queued` message as `read` when a prompt of its session carries the message's text. Codex starts the session's next turn with the queued message as the prompt, and fires its prompt hook for that turn.
- The `queued` line names the thread id from Codex's receipt, and a message's session is the one its last line names. So a message posted by name is found by the session id the hook reads.
- A post to a Codex session by name warns that Codex searches its server's sessions for a name, and that a UUID needs no search.
- When Codex refuses a name and names the UUIDs it matched, the failure carries a hint: post with `--session <uuid>`.
- The hook's message tells the reader to answer a `harness:id` sender with `rune queue post <harness> --session <id>`.
- The README says that `rune queue` needs the same sandbox exemption as `rune run`.

## Capabilities

- queue-messages-for-sessions (modified)

## Impact

- `src/cli/queue/mod.rs`, `src/cli/queue/ledger.rs`, `src/cli/hook/adapters.rs`, their tests, `tests/queue.rs`, `README.md`, `templates/skill/SKILL.md`, `CHANGELOG.md`.
- A Codex message posted by name now lists under the thread id that Codex printed.

[HOOK]: ../../specs/glossary/hook.md
[FIELDREPORT]: design.md#evidence
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## ADDED Requirements

### Requirement: A queued message is read when its turn starts

When a session's prompt is the text of a message that the *[harness][HARNESS]*'s own queue holds for that session, the *[hook][HOOK]* MUST record that message as `read`. A `queued` line MUST name the session id that the [harness][HARNESS] printed for the message, and a message's session MUST be the one its last line names. A prompt that is no queued message of the session MUST leave every message as it was.

#### Scenario: Codex turn starts with a queued message

- **WHEN** a message for the Codex session `ouroboros` is queued, and Codex prints the thread `019a-ouroboros` for it
- **AND** a prompt in that thread carries the message's text
- **THEN** the [hook][HOOK] records the message as `read`, and the list shows it for `019a-ouroboros`

#### Scenario: Owner prompt leaves the queue alone

- **WHEN** a message is `queued` for a Codex session, and the owner sends another prompt in that session
- **THEN** the message stays `queued`

### Requirement: A Codex session name leads to its UUID

A post to a Codex session given by a name, not a UUID, MUST warn that Codex searches every session of its server for a name, and that a UUID needs no search. When Codex refuses a name and names the UUIDs it matched, the failure MUST carry a hint that names them and tells the caller to post with `--session`. A post to a UUID MUST NOT warn.

#### Scenario: Refused name names its UUID

- **WHEN** Codex exits 1 because it cannot verify a unique session label, and names the matching session UUID
- **THEN** the command exits 1, the hint names that UUID and `--session`, and the ledger is unchanged

#### Scenario: Session UUID gets no warning

- **WHEN** the caller posts for a Codex session by its UUID
- **THEN** the post writes no warning

[HARNESS]: ../../../../specs/glossary/harness.md
[HOOK]: ../../../../specs/glossary/hook.md
12 changes: 12 additions & 0 deletions docs/changes/queue-records-codex-reads/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 1. Implementation

- [x] 1.1 `fold` takes a message's session from its last line, and the `queued` line names the receipt's thread id
- [x] 1.2 `take_prompted` and the `postbox` handler on `prompt.before`: a prompt that is a queued message's text marks it read
- [x] 1.3 The name warning for a Codex session that is not a UUID, and the hint from Codex's name refusals
- [x] 1.4 The hook's answer line for a `harness:id` sender, the README queue section, the rune skill section, and the CHANGELOG entry

## 2. Verification

- [x] 2.1 Unit tests: the session of the last line, `take_prompted`, the hook on a queued prompt and on another prompt, the UUID shape, the warning, and the hint
- [x] 2.2 Integration tests with a fake Codex and a scratch HOME: a name resolved to the receipt's thread and read by its turn, no warning for a UUID, and the hint on a refused name
- [x] 2.3 `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `cargo test --bin rune` (1379 pass), `cargo test --test queue --test hook_dispatch` (39 pass), `rune spec validate queue-records-codex-reads` (2026-10-28)
95 changes: 95 additions & 0 deletions docs/proofs/queue-records-codex-reads/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
type: proof
change: queue-records-codex-reads
head: 2019c64bc794044a8fb9d45518484edf67ca85b5
head_change: wvzquvsnqmpxtsvmlwvuxzqnmzkvuvsn
head_tree: 26119afdb345cf835b9ac60f14a04df6465dc022
recorded: 2026-10-28
transcript: ed2d89946fd00f164d3e4e60a5d4df2654df2bc5928c9b1a88bac62ddc4bd5df
scenes:
- scenario: queue-messages-for-sessions#a-queued-message-is-read-when-its-turn-starts/codex-turn-starts-with-a-queued-message
kind: check
- scenario: queue-messages-for-sessions#a-queued-message-is-read-when-its-turn-starts/owner-prompt-leaves-the-queue-alone
kind: check
- scenario: queue-messages-for-sessions#a-codex-session-name-leads-to-its-uuid/refused-name-names-its-uuid
kind: check
- scenario: queue-messages-for-sessions#a-codex-session-name-leads-to-its-uuid/session-uuid-gets-no-warning
kind: check
---

# Proof: queue-records-codex-reads

One scene per scenario, in closure order. Every scene gives rune a HOME of its own, `home`, so the postbox is `home/.rune/postbox.tsv` and the owner's ledger is never touched. A Codex scene writes a fake `codex` that prints the receipt line or the name refusal of Codex 0.154.0, and runs it with `--binary`, so no Codex app server is reached. The hook scenes hand `rune hook adapter postbox` the payload the dispatcher builds from Codex's `UserPromptSubmit`, with the prompt. Each post names its sender with `--from`, so the recorder's own harness session does not show. Message ids and timestamps change on every run and are elided. `mlr` reads the ledger as the tab-separated table it is.

## queue-messages-for-sessions#a-queued-message-is-read-when-its-turn-starts/codex-turn-starts-with-a-queued-message

```console
$ sh -s
< cat > fake-codex <<'EOF'
< #!/bin/sh
< echo 'Queued message msg-41 for thread 019a-ouroboros.'
< EOF
< chmod +x fake-codex
$ HOME=home rune queue post codex --session ouroboros --from claude:42e43c0b --binary ./fake-codex "Is the deck ready?"
warning: Codex looks the name ouroboros up page by page across its server's sessions, which can take a minute or more; a session UUID needs no search
queued message msg-41 for codex thread 019a-ouroboros
$ HOME=home rune hook adapter postbox
< {"v":1,"harness":"codex","event":"prompt.before","native_event":"UserPromptSubmit","session_id":"019a-ouroboros","prompt":"Is the deck ready?","raw":{}}
{"v":1,"effect":"pass","reason":null,"input":null,"context":[]}
$ mlr --itsv --opprint cut -o -f state,sender,harness,session home/.rune/postbox.tsv
state sender harness session
posted claude:42e43c0b codex ouroboros
queued claude:42e43c0b codex 019a-ouroboros
read claude:42e43c0b codex 019a-ouroboros
$ HOME=home rune queue list
[..] read claude:42e43c0b -> codex:019a-ouroboros Is the deck ready?
```

## queue-messages-for-sessions#a-queued-message-is-read-when-its-turn-starts/owner-prompt-leaves-the-queue-alone

```console
$ sh -s
< cat > fake-codex <<'EOF'
< #!/bin/sh
< echo 'Queued message msg-42 for thread 01a15844-7b2e-71a0-aa88-b41f3c4622af.'
< EOF
< chmod +x fake-codex
$ HOME=home rune queue post codex --session 01a15844-7b2e-71a0-aa88-b41f3c4622af --from claude:42e43c0b --binary ./fake-codex "Is the deck ready?"
queued message msg-42 for codex thread 01a15844-7b2e-71a0-aa88-b41f3c4622af
$ HOME=home rune hook adapter postbox
< {"v":1,"harness":"codex","event":"prompt.before","native_event":"UserPromptSubmit","session_id":"01a15844-7b2e-71a0-aa88-b41f3c4622af","prompt":"Run the tests","raw":{}}
{"v":1,"effect":"pass","reason":null,"input":null,"context":[]}
$ HOME=home rune queue list
[..] queued claude:42e43c0b -> codex:01a15844-7b2e-71a0-aa88-b41f3c4622af Is the deck ready?
```

## queue-messages-for-sessions#a-codex-session-name-leads-to-its-uuid/refused-name-names-its-uuid

```console
$ sh -s
< cat > fake-codex <<'EOF'
< #!/bin/sh
< echo 'Error: Cannot verify a unique session label across server pages; matching session UUID: 01a15844-7b2e-71a0-aa88-b41f3c4622af' >&2
< exit 1
< EOF
< chmod +x fake-codex
$ HOME=home rune --json queue post codex --session Proton/ai-demo --from claude:42e43c0b --binary ./fake-codex "Is the deck ready?"
? 1
warning: Codex looks the name Proton/ai-demo up page by page across its server's sessions, which can take a minute or more; a session UUID needs no search
{"details":{"exit_code":1,"harness_errors":[],"stderr_tail":"Error: Cannot verify a unique session label across server pages; matching session UUID: 01a15844-7b2e-71a0-aa88-b41f3c4622af","stdout_tail":""},"exit_code":1,"hint":"Codex matched the name to session 01a15844-7b2e-71a0-aa88-b41f3c4622af: post with --session 01a15844-7b2e-71a0-aa88-b41f3c4622af","kind":"exit","ok":false,"tool":"codex"}
$ sh -c 'test ! -e home/.rune/postbox.tsv && echo "nothing recorded"'
nothing recorded
```

## queue-messages-for-sessions#a-codex-session-name-leads-to-its-uuid/session-uuid-gets-no-warning

```console
$ sh -s
< cat > fake-codex <<'EOF'
< #!/bin/sh
< echo 'Queued message msg-43 for thread 01a15844-7b2e-71a0-aa88-b41f3c4622af.'
< EOF
< chmod +x fake-codex
$ HOME=home rune queue post codex --session 01a15844-7b2e-71a0-aa88-b41f3c4622af --from claude:42e43c0b --binary ./fake-codex "Is the deck ready?"
queued message msg-43 for codex thread 01a15844-7b2e-71a0-aa88-b41f3c4622af
```
Loading
Loading