Skip to content

Codex autopilot, PR 1: owner record reader, start marks and fail-closed merge command, all inactive (T663) - #447

Merged
erickb336 merged 7 commits into
mainfrom
sage/t663-codex-autopilot
Nov 7, 2026
Merged

erickb336 merged 7 commits into
mainfrom
sage/t663-codex-autopilot

Conversation

@erickb336

Copy link
Copy Markdown
Owner

What this is. The first of two pull requests for a Codex autopilot that merges (T663; the plan is PE R2589, the proof is T662). It adds three parts to the Codex plugin and turns none of them on. The owner sees no change: the Codex gate still refuses every merge, and no hook saves a merge permit, so the new merge command refuses every call. PR 2 (T677) adds the gate's admission and the guide.

Entry point (order 36). The owner installs the sage plugin in the Codex desktop app or the CLI, sends the mode phrase, then the autopilot on phrase. After PR 2, verified pull requests merge after their clean cycles.

The three parts

Part File What it does Fails closed on
Owner record reader packages/sage-codex/hooks/owner-record.mjs Reads the owner's latest autopilot switch from Codex's record of the session (transcript_path), with core's exactPhrase and PHRASES. On counts only from a message whose every item has provenance user, in a turn with trigger user or exec. Off counts from any owner message; the mode off phrase also turns autopilot off. Only messages after the boundary count: the later of the last session_meta line and the start mark. no path, read error, over 64 MiB, a partial last line after 3 re-reads, a line that is not JSON, an unknown top-level type or a payload that is not an object, no session_meta, a Codex version outside 0.164 to 0.166 in the strict form, a boundary that does not fit the record
Start marks packages/sage-codex/hooks/start-mark.mjs, session-start-hook.mjs (startup, resume, clear), sage-codex-hook.mjs (fork) Saves marks/<stateKey>.json in the mode folder with an atomic rename: session, source, record line count, process.ppid. Never on compact, never for a child. A failed save gives the user a limit line, never blocks, and removes the earlier mark of the session
Merge command packages/sage-codex/skills/sage/merge.mjs Arguments exactly <pr> <40-char sha>; root thread only (CODEX_THREAD_ID equals CODEX_SESSION_ID); takes the one-time merge permit of CODEX_TOOL_CALL_ID (permits/<sha256(id)>.json) by atomic rename; re-reads the record from the permit's boundary right before gh; refuses on a turn_aborted event of the permit's turn; then execFileSync("gh", ["pr","merge",pr,"--squash","--delete-branch","--match-head-commit",sha]) with no shell and without GH_HOST and GH_REPO a missing, used, damaged or older-than-300-s permit; a permit for another session, pull request, SHA or command; a sandboxed rename (asks to run it escalated); every reader refusal; Esc in the turn

gate-hook.mjs is unchanged, and so is checkMerge.

Tests

  • scripts/fixtures/codex-native/autopilot-record.test.mjs (14 tests): each reader case above, on real Codex 0.164.0 records of the T662 proof (owner-records.json: scrubbed of every local path and trimmed, with the probe phrases replaced by sage's phrases), and the start marks through the built hooks as Codex runs them: startup, resume, clear and fork save one; compact and a child save none; a failed save gives the limit line.
  • scripts/fixtures/codex-native/autopilot-merge.test.mjs (9 tests): each merge command case above, as a process with a fake gh. PATH holds only the fakes folder and node runs by its absolute path, so no real gh can run; the first test proves the fake by its absolute path and by name. The last test shows that on this head no path merges: the gate refuses every gh merge also when the mode reader and the merge check say yes, and the merge command finds no merge permit.
  • Both files fail on the base 4dd4d61 (the new modules are missing). With only the new modules copied into the base build, the 4 start mark tests fail, because the base hooks save no mark.

Not checked here

The desktop app (0.166.0-alpha.6) and a real Codex run: they are the QA proof of PR 2.

🤖 Generated with Claude Code

erickb336 and others added 7 commits November 7, 2026 10:00
…e (T663)

The reader reads the owner's latest autopilot switch from Codex's record of
the session and refuses every record that it cannot prove. The SessionStart
hooks save a start mark for startup, resume, clear and fork, never compact.
Tests use real Codex 0.164.0 records of the T662 proof, scrubbed and trimmed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
skills/sage/merge.mjs takes a pull request number and a head SHA. It runs only
from the root thread, with the one-time merge permit of its exact tool call
(taken by an atomic rename), and only when Codex's record still shows the
owner's on switch and no Esc in the turn. No hook saves a merge permit yet, so
it refuses every call, and the gate still refuses every recognized merge.
T677 turns it on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…k is required, the merge is bound to a repository (T663)

F-T663-2: the owner record reader replays the owner's switches with core's
switchModes, so an on counts only while sage mode is on, and the off form of
the mode phrase ends autopilot.
F-T663-5: autopilotSwitch takes the start mark itself and refuses a missing
one; an owner message needs one metadata item for each content item.
F-T663-4: the merge permit names the repository; gh runs with --repo, in an
empty private folder of sage, without GH_HOST, GH_REPO and the enterprise
tokens.
F-T663-6 and F-T663-7: plain limit and refusal texts, each with a next step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… offs with an image, plain refusals (T663)

- F-T663-10: a start mark saves only for the root thread, by the gate's threadOf;
  a start that cannot show its record is the root thread's never puts line 0 over a mark.
- F-T663-12: a resume whose record cannot be counted saves no mark and removes the old one.
- F-T663-13, F-T663-16: the limit lines name the folder that failed and the next step.
- F-T663-11: an off phrase sent with an image counts, as it switches the sage hook off.
- F-T663-14: each record refusal gives a plain cause and one step, the detail last.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@erickb336
erickb336 merged commit f3e57e6 into main Nov 7, 2026
1 check passed
@erickb336
erickb336 deleted the sage/t663-codex-autopilot branch November 7, 2026 21:49
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