Skip to content

Codex workflow engine (M0) + code-review panel workflow — v7.37.0 - #43

Merged
SSFSKIM merged 82 commits into
mainfrom
codex-workflow-engine
Aug 4, 2026
Merged

SSFSKIM merged 82 commits into
mainfrom
codex-workflow-engine

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Aug 3, 2026

Copy link
Copy Markdown
Owner

What this ships

The general `workflow` verb on the codex-companion runtime — Claude Code's Dynamic-Workflow counterpart for the Codex runtime: a JS orchestration script executor whose workers are codex threads, running as ONE detached, headless, harness-independent process.

  • Hooks: `agent` (schema-forced turns, engine-side validation, same-thread repair capped at two turns), `review` (native review with per-worker `-c` overrides — effort + `developer_instructions` lens), `parallel`/`pipeline` (Workflow-tool-matching null semantics), leaf-level concurrency semaphore (default 6).
  • Resume: event-sourced sealed journal, content-keyed successes-only cache, re-entrant run lease with atomic dead-holder breaking, content-aware fail-closed repo+script fingerprint.
  • Jobs: ledger mutation now atomic + serialized for ALL writers (closes the documented `state.json` lost-record race); real cancel (worker-pid tracking + signal handlers), lazy dead-pid liveness repair, canonical statuses.
  • M0 is read-only by design; docs at `skills/codex-companion/references/workflows.md`.

First consumer: `workflows/code-review.mjs` — the multi-lens review panel: adaptive diff-derived scalpel lenses (≤5, each ≤2 sentences) on steered native review + a lens-free sweep (all sol/xhigh), strict extraction with drift guards and a live-validated marker-finding clean sentinel, one binding sol/high verifier under mechanical postconditions, coverage-honest deterministic assembly (a lost sweep or verifier can never launder into a clean verdict).

Quality gates

  • X1 bench: PASS (audited) — seeded recall 17/17 (= codex baseline), FP +1 (exactly the allowed bound); independent adjudication audit re-judged all 25 findings; caveats (zero margin, n=1, exclusion sensitivity) recorded inline in the spec. Run: `tests/review-bench/results/2026-08-03-panel-x1/`.
  • Adversarial review at every level: spec (5/5 findings adopted), plans (11/11), per-task Opus reviews with fix loops, final whole-branch codex review (4 P1 + 2 P2 fixed) + no-P1 confirmation round (3 P2 polish).
  • Five live probes committed as evidence under `tests/review-bench/results/` (devinstr transport, clean-render prose, sentinel channel, plus the X1 runs).
  • Suites: workflow runner (9 test files incl. adversarial resume + panel flow), node suite 85/85, skill tests PASSED, shell lint clean.

Spec: `docs/doperpowers/specs/2026-08-03-codex-workflow-engine-design.md` (v2.3 + retrospective). Plans: `docs/doperpowers/plans/2026-08-03-codex-workflow-engine.md`, `2026-08-03-codex-review-panel-workflow.md`.

🤖 Generated with Claude Code

SSFSKIM added 30 commits August 3, 2026 05:17
…odex-companion runtime, code-review panel as first consumer
…tive review; devinstr transport probe PASS on app-server path (evidence committed)
…ssion-verifier and spec-context-deriver variants deferred
…ersal ledger lock, content-aware fingerprint, atomic lease, status-gated turns, canonical job lifecycle, strict extraction trichotomy, unconditional sweep-loss interrupt
…ession tripwire; token-list assert on the fresh-dir race
…ds, signal cleanup, cancel/liveness awareness
… critical section no longer wedges the ledger
…nalize never skips exit; liveness probes agree
…he next event

A run killed mid-append leaves a half-written last line. loadJournal already
skipped it, but the next append glued its event onto the wreck, so the FIRST
event a resume wrote (the re-run call's `started`) was lost with it. Seal the
line before the resumed run writes anything.
…print — editing an ad-hoc script refuses stale cache
…fingerprint, job scoping, exit codes + script-drift resume test
… finders carry a format-only clean sentinel (probe committed)
…el hardened both sides; verifier sees the lens map
SSFSKIM added 21 commits August 4, 2026 04:52
…ing a shell

npm installs codex as codex.cmd, and Node >= 18.20 refuses to spawn a .cmd
without a shell (EINVAL) — so dropping the shell left Windows unable to start
codex at all. A shell is still not the answer: the config overrides carry
arbitrary prose, and a command line is where prose becomes code. Resolve the
real target instead (`where codex`): an .exe or a .js is spawned directly, and
only a batch shim goes through cmd.exe /d /s /c, with the shim path and every
codex argument staying discrete argv elements. Other platforms are untouched.
…back in

The gap between mkdirSync and the holder stamp is the same window the unstamped
TTL declares abandoned, so a claimer stalled past it wakes to find its lock
broken and retaken — and its stamp then landed in the SUCCESSOR's directory,
putting two writers in one critical section. Now the stamp is written "wx" (it
cannot overwrite a successor that has already stamped) and the directory's inode
is re-checked afterwards (catching the successor that has not stamped yet).
Either way the claim is simply lost and nothing is removed.

Same reason the ENOENT path stops calling rmSync: a stamp that fails because our
directory vanished is a lost race, and the directory standing there now is the
successor's lock, not ours to delete.
…t fatal

A ledger written before run ids were validated can carry one that is not a path
segment — `--resume ../state` wrote exactly that. Both passes that turn a row's
id back into a file path then throw: saveState's prune (so EVERY later mutation
fails, and the poisoned row cannot be removed by the pass whose job is removing
rows) and repairDeadWorkflowJobs (so every status, result and cancel fails).
Both now skip such rows; saveState drops them from the ledger, and deletes
nothing they name — acting on a traversal id is the traversal all over again.
Both writes set pid: null and left pidStart behind, so a cancelled row still
carried the instance of a process it no longer claims — the stamp is exactly
what every liveness check reads beside that number.
… record

One state root is one lock, and an older runtime reads a newer holder record as
unreadable — so it waits the lock out instead of breaking it. Names the symptom
(a state lock timeout) so it is not mistaken for a wedge.
…else

Two renders read CLEAN that had a defect in them. A top-level list item
that carries no [P#] tag and no `path:line` tail matched neither drift
guard, so a plain defect bullet beside the clean marker was absorbed as
the marker's body and the lane reported clean; and any number of marker
findings passed the "no real findings" test, though the instruction asks
for exactly one.

Both are now extraction failures: any top-level list item that is not a
parseable head counts as drift (indented bullets stay body text, which
is what a render lists its own points with), and the clean verdict is
believed only when a single marker stood alone.
A REFUTED verdict may carry duplicateOf — the postconditions forbid
pointing AT a refuted finding, not being one — and the assembly credited
every duplicate in the chain as a source. The published finding then
named a second reviewer as corroboration under a claim that reviewer's
own verdict denied.

sourcesOf now counts confirmed duplicates only. Deliberately not a new
postcondition: rejecting the set costs a full repair round, and the
panel itself if the repair is no better, over a contradiction that is
free to read correctly here.
The lens deriver is the one lane with nothing diff-derived in its cache
identity: the engine keys every review call on the commit it resolved,
but an agent call is keyed on its prompt, and that prompt said only
"main". So a resume taken after the merge base moved — a rebased or
force-pushed base branch leaves HEAD, the working tree and the untracked
files untouched, which is all the run fingerprint watches — served
lenses derived from the old range while every finder reviewed the new
one. The new pin-resume case reproduces exactly that: unpinned, the
resumed deriver is a cache hit.

The panel now resolves `git merge-base <base> HEAD` once at start (the
same command the engine journals a review call under) and names that
commit in the deriver and verifier prompts, so the range is one range
for the whole panel and the deriver's cache identity moves with it. The
repository is the one the verb resolved --cwd to, read off argv because
the engine hands a script no cwd; it is used for the pin alone and never
handed to a worker, so a wrong guess costs a cache key rather than a
misdirected review. An unresolvable base logs the loss and runs
unpinned, exactly as before.
cmd.exe re-parses the command line it is given, so `&`, `|` and `%VAR%`
inside a config override (a review lens is arbitrary prose) become
separators and expansions no argv discipline can prevent. Windows is not
a supported platform for this fork; a hard refusal naming the fix
(install a native codex binary) beats an injectable path.
Four changes to the one identity rule:

- The linux token folds in /proc/sys/kernel/random/boot_id. Jiffies are
  boot-relative, so a record that outlives a reboot could match the same
  pid at the same tick after it. A token without a boot id (darwin, or a
  record written before this) still compares on the half both formats
  share, so upgrading the runtime under a live process cannot make it
  read as dead.
- Every kill path (cancel, the worker sweep, SessionEnd teardown) now
  uses pidInstanceVerified: unstamped or unreadable proves nothing, and
  what cannot be proven is not signalled. Liveness keeps the opposite
  default — ignorance never costs anyone a lock, a lease or a run.
- SessionEnd stops dropping a row whose group signal delivered nothing. A
  workflow run is a foreground child, not a group leader, so kill(-pid)
  raises ESRCH; the hook now falls back to signalling the pid directly
  and sweeps workers.json, exactly as cancel does.
- The 250ms start-time cache serves only the state lock's retry loop.
  Kill decisions and spawn stamps read fresh: the cached window is
  exactly the one in which a pid is reused.

pid.mjs also loses its raw NUL bytes, which made `file` call it data and
`git diff` call it binary.
…ledger row

A transition writes the per-job file and then the ledger row, so a crash
between the two leaves a terminal record beside a running row. The repair
pass let the row win and rewrote a completed run as failed, discarding
the result. The terminal record is the authority; the row is reconciled
to it.

Finalizing a genuinely dead run now also sweeps its workers.json. They
are children of a process that is gone, and cancel cannot reach them —
it repairs first, and a repaired row is no longer cancelable.
A SIGKILLed run reaps nothing: the app-servers it spawned keep running.
Replaying its unfinished leaf on top of them duplicates the work and its
side effects. The resume sweeps workers.json under the lease it just
took, using the same instance-guarded kill as cancel, and says how many
it signalled.
…built in place

A holder stamp and a break token are claims by existence, and an O_EXCL
create leaves them VISIBLE while still empty. A rival reading that window
sees no owner: it treats a held lock as holderless, or deletes a live
break token and joins the breaker inside it. Both now go through the same
temp-file + hard-link publish the run lease uses, so a reader sees the
complete record or nothing.
…ms by value

Two independent correctness bugs:

- repoFingerprintParts ran ls-files and hash-object from the caller's
  cwd. git scopes ls-files to the invoking subdirectory, so untracked
  files elsewhere in the checkout never entered the fingerprint even
  though the workers read them. The reads are anchored at the repository
  root, which the function already resolves.
- validateSchema compared enum members with Array#includes. An object or
  array member can never be reference-equal to a parsed value, so every
  structurally correct payload was rejected and the run's single repair
  turn was spent proving it. Membership is now a structural walk, with
  object key order treated as irrelevant.
…alf-connected server

- completionLostToExit waited a fixed 50ms after the child's exit event
  before deciding the turn was lost. Lines buffered in the pipe are
  delivered after that event, so under load a turn that had completed was
  failed and retried. It now waits for the stdout stream to close, capped
  at 2s so a wedged pipe costs a leaf rather than the run.
- connect() spawns the app-server and then initializes it. A failure in
  between (a rejected initialize, a throwing onSpawn) returned no client,
  so the caller's finally had nothing to close and the process survived
  the session. connect closes what it spawned, and the exit handlers are
  attached before caller code runs so close() always has a path to
  settle.
…teardown will not signal

- Ignored files are outside the repository-content fingerprint by design:
  they are derived artifacts, and hashing them would make every rebuild
  between a run and its resume a refusal. Stated plainly next to the
  fingerprint scope, since it is the one input change a resume misses.
- The kill rule (only a provable instance is signalled) and what it means
  on Windows, where no start time is readable and teardown is therefore
  best-effort.
- The spec's residual list picks up the deferred malformed-response hang,
  which is the same class as the already-deferred per-turn watchdog.
…re it answers

The review panel resolved a merge-base commit at start and then let the
whole run drift underneath it. Three ways it lost the target:

- an unresolvable base was treated as an optimization miss, so the panel
  ran unpinned and could return `correct` about a range nobody had
  established. It now ends the round before spending a worker, naming the
  base it could not resolve.
- the feature tip was never pinned at all. The engine's per-leaf identity
  is merge-base..tip-of-the-base-branch, which a commit added to the
  branch under review leaves untouched, so nothing anywhere noticed.
- a base ref that moved between the pin and a leaf's own key, or after the
  last leaf finished, left every leaf agreeing with itself and the panel
  publishing a verdict about a different diff.

The pin is now the pair (merge base, HEAD), re-read at assembly. Any
movement makes the verdict unconditionally `interrupted` — the
coverage-honesty pattern already used for a lost sweep and a lost
verifier — with the drift named and the confirmed findings attached as
partial evidence. What rides the wire to each finder is unchanged: the
engine already fails a leaf whose target moves mid-leaf, and this closes
the panel-level window around it.

Covered by test-panel-flow.sh cases unpinnable-base, head-drift and
base-drift; the last two move a ref mid-run through a `codex` shim, which
is the only way a scenario file can express a ref moving during a panel.
@SSFSKIM

SSFSKIM commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

Dogfood fix campaign (v7.37.1)

The panel workflow reviewed its own PR three times, gating a fix loop:

  • Round 1 (vs ec2c2669): verdict incorrect, 17 confirmed findings (11 P1) — shell injection via lens text, --resume path traversal, mid-turn app-server hangs, false-clean extraction bypass, pid-reuse group-kills, fingerprint gaps. All 17 fixed across 3 waves; adversarial reviews of those waves surfaced +12 more (incl. the unguarded broker pid and the Linux clock-step liveness inversion) — also fixed.
  • Round 2 (vs 1be1794d): incorrect, 18 findings (9 P1), mostly against round-1 fix code. 16 fixed, 1 accepted+documented, 1 deferred into the watchdog follow-up.
  • Round 3 (vs cf5771fb): interrupted — the new head-drift gate correctly caught a mid-run commit (accidental live validation). Verifier attached 18 findings (13 P1), overwhelmingly narrow TOCTOU windows in round-2 code. Loop stopped by predeclared rule; findings archived as triage backlog in tests/review-bench/results/2026-08-04-pr43-dogfood-loop/.

Suites: workflow runner green (16 files), runtime node suite 105/105, shell lint clean. Spec's living tail records the full campaign and the stop rationale.

🤖 Generated with Claude Code

SSFSKIM added 3 commits August 4, 2026 11:21
…and a cancelled job stays cancelled

`task --background` spawned the detached worker and wrote its pid into the
queued row without the instance stamp beside it. Every kill path in this
runtime is fail-closed on purpose — it signals only a pid it can prove still
names the recorded process — so a row with a bare number was a row cancel
could never act on. Cancelling a task that had not yet reached `running`
therefore recorded "cancelled" and signalled nothing; the worker woke up,
transitioned the job back to running, and a --write task carried on editing
the repository after the user had been told it stopped.

Both halves are closed. The queued row now carries the child's start time,
read at spawn time while the pid indisputably belongs to the child we just
created — the same stamp the broker spawn path already takes. And
`task-worker` refuses any record that is not `queued`, which is what protects
rows written by builds that predate the stamp: even with nothing able to
signal it, the worker will not write over a decided job.
…not the liveness one

`brokerInstanceIsOurs` required a stored stamp but handed the comparison to
`pidInstanceAlive`, which answers "alive" whenever the current start time
cannot be read. That is deliberate for liveness — ignorance must never cost a
live process its lock or its lease — and wrong for a kill: broker.json is
durable state that outlives a reboot, so its pid may already belong to a
stranger, and `terminateProcessTree` signals a whole process group. One
unreadable start time was enough to authorize it.

Teardown now uses `pidInstanceVerified`, the fail-closed predicate every other
signal path in the runtime already uses. Unverifiable means never signalled;
the stale record is still deleted, which was always the rest of the job.
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