Skip to content

[blocked on core release] Best-of-N attempt comparison, codex driver, keyless operation in agent hosts - #19

Merged
marceloceccon merged 2 commits into
mainfrom
feat/compare-attempts
Nov 20, 2026
Merged

marceloceccon merged 2 commits into
mainfrom
feat/compare-attempts

Conversation

@marceloceccon

@marceloceccon marceloceccon commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Draft — blocked on core release. Needs ai-consensus-core@0.13.0 (entropyvortex/ai-consensus-core#6), which is not published. package.json asks for ^0.13.0, so CI's npm install fails until the release; there is no lockfile to refresh. Everything below was verified locally against a packed tarball of the core branch.

What changed

Best-of-N attempt comparison (stdio only; never offered over HTTP or Workers).

  • consensus_list_attempts: branches, most recent first, with ahead/behind against a base (input, else origin/HEAD, main, master, HEAD), their worktree, and its uncommitted count. Makes no branch-naming assumption.
  • consensus_compare_attempts:
    • Inputs: task, attempts: [{ref, label?, checks?}] (2–6), repoPath (default cwd), base (default merge-base), and the existing panel / participantIds / judge / maxRounds (default 1) / randomSeed knobs.
    • Plus deadlineMs, maxTokens, diffTokenBudget, includeUncommitted and opt-in testCommand.
  • Git access:
    • The server computes each diff itself with git through execFile, with no shell, so diffs never pass through the agent's context.
    • Refs go through rev-parse --verify --end-of-options, and anything starting with - is refused.
    • Read-only: --no-ext-diff --no-textconv, fsmonitor off, GIT_OPTIONAL_LOCKS=0.
    • A branch checked out in a worktree is compared with its uncommitted and untracked changes.
  • Diff budgeting: lockfiles, generated (dist/, *.min.js, linguist-generated, …) and binary files are skipped. Whole files are dropped past the per-attempt token budget. Jurors get a header listing what was left out, and the result lists it too.
    • The header lists at most 20 paths per reason and counts against the budget.
    • The structured result caps file lists at 50, with exact totals.
  • Blinding: changes under agent tool directories (.claude/, .codex/, .grok/, .cursor/, …) are skipped and shown to jurors as a count only, since their paths can name the agent that produced the attempt.
  • Judging: blind, through core's AdjudicationEngine. Progress notifications are sent per juror, and a deadline or token ceiling returns a partial result.
  • Output: a short markdown verdict with the recommended ref first, or "no clear winner" and why. structuredContent carries the typed result plus per-attempt diff coverage, but no juror raw output and no diff bodies.
  • testCommand: an argv array run in each attempt's own worktree, in its own process group, with a timeout; the exit status becomes a check. It executes repository code, so it is refused unless serve --allow-test-command, which in turn is refused together with --http.

Keyless operation inside agent hosts.

  • Codex driver on codex exec (previously refused at resolve). The flags were checked against the installed codex exec --help / codex --help 0.170.0:

    • -c approval_policy="never" (the documented exec route; -a is top-level only);
    • --sandbox read-only;
    • --disable shell_tool --disable unified_exec;
    • --ignore-user-config (no config.toml, so no MCP servers; auth still uses CODEX_HOME);
    • --ignore-rules --ephemeral --skip-git-repo-check --json;
    • prompt on stdin, schema via --output-schema, answer read from -o.

    The probe requires codex login status to succeed and refuses API-key auth.

  • CLI drivers are now a uniform interface with a per-call JSON Schema ("JSON mode"). Juror verdicts are enforced by the CLI (--json-schema / --output-schema) instead of the {answer, confidence} oracle schema, and come back untouched. The judge stays on the oracle schema.

  • Recursion guard: every CLI child gets AI_CONSENSUS_MCP_DEPTH = parent + 1, and serve refuses to start when it is ≥ 1.

  • "envFile" config key:

    • a KEY=VALUE file read for provider keys;
    • refused if it is not a regular file, is owned by another user, or has any group/other mode bit;
    • values are never logged;
    • the environment wins over the file;
    • file-loaded configs only (CONSENSUS_CONFIG_JSON / Workers rejects it).
  • Missing key: the error now names the variable, the provider and the allowlist cause ([feat]: Let users extend the agent env allowlist (MCP credentials referenced as ${VAR} are stripped) generalaction/emdash#3103), and points to envFile. It still starts with the old text.

  • Wizard: detects claude / grok / codex on PATH (no execution) and, for a new config, offers a keyless panel first. Codex is now offered in the CLI form. "modelId": "default" omits -m for codex and grok, because model names rotate: grok 1.0.89 no longer lists grok-4.

  • Host timeouts (README): Codex gives an MCP tool call 60 s by default, so the README says to raise tool_timeout_sec. Claude Code's limits are long, and its stdio idle limit resets on progress notifications. Values are from their docs, read today.

  • Docs: skills/best-of-n-verdict/SKILL.md (Agent Skills format: list, compare, report, never merge or delete; shipped in files) and a "Using with Emdash" README section (Custom MCP setup, the skill, credentials).

Why

In Emdash's best-of-N flow every attempt is a worktree off one base, and the user picks the winner by hand. This lets the agent in any attempt ask a blind panel instead. Emdash starts agents (and so MCP servers) with an allowlisted environment, so the server must work from signed-in CLIs, or from keys it loads itself, and must say so clearly when a key is missing.

How it was verified

  • CI gates: npm run check (typecheck, eslint, prettier, 656 tests with coverage thresholds), npm run build, npm run test:smoke and the wrangler preflight all pass on Node 24 [executed]. Tests also pass on Node 20.20.2 [executed].
    • Coverage 85.5 / 74.7 / 87.3 / 87.3 (thresholds 78 / 66 / 83 / 80).
    • The smoke test lists both new tools on stdio.
  • Git fixture: a temp repository with three attempt branches, a worktree with uncommitted and untracked edits, a lockfile, generated and binary files, an oversized file, a refs/heads/-evil branch and an orphan. Covered:
    • refusal of -evil;
    • merge-base semantics when the base moves on;
    • filtering, budget truncation and the omission header;
    • worktree mode;
    • no index write. A mutation check confirmed this test fails without GIT_OPTIONAL_LOCKS=0 [executed].
  • Compare tool:
    • unit tests with blind fake jurors that recognise candidates by content only;
    • a full-stack test MCP client → server → git → core → HTTP adapter, with mocked fetch;
    • the tools are absent unless the stdio entry enables them.
  • CLI drivers through real stub executables: one node script installed as claude, grok and codex records argv, stdin or prompt file, cwd, scratch contents and env. Checked:
    • prompts never on argv;
    • empty scratch cwd;
    • depth variable set and API keys absent;
    • oracle vs JSON mode;
    • codex's exact argv, -o answer and usage;
    • all three readiness probes, plus a signed-out codex.
  • CLI help: flags checked against installed help: claude 2.1.329, grok 1.0.89, codex 0.170.0 [executed].
  • Codex argv: the exact final argv emitted by buildCodexArgv, with and without -m, was accepted by a real codex exec that reached the API and failed only on auth. A bogus flag fails at parse [executed].
  • Wizard: the keyless new-config path runs in a scripted test (stubbed PATH → keyless chosen → saved → re-validated and resolved with no keys), as does the no-CLI path [executed].
  • Grok recursion guard: grok starts MCP servers with its full environment. Observed with an isolated GROK_HOME and grok mcp doctor: a stub server received AI_CONSENSUS_MCP_DEPTH=1 and an arbitrary canary variable, and the user's grok config was unchanged [executed]. A live grok session spawning servers is assumed to behave the same [assumed].
  • Live checks on the signed-in subscriptions: two small runs, two jurors each, on a two-branch repo through the built code [executed]:
    • claude 2.1.329 (haiku) and grok 1.0.89 (grok-4.7-build-fast) in JSON mode both returned strictly valid verdicts;
    • each juror had one quote-verified finding; W = 1.00; "keep good";
    • each grok call reported ≈47k input tokens of the CLI's own context (now noted in the README).

Deviations from the brief

  • CLI driver interface already existed (CliDriver probe/run with claude and grok). This PR adds codex and JSON mode rather than introducing the interface.
  • Grok's prompt stays in the 0600 --prompt-file inside the empty scratch dir, not stdin: grok 1.0.89 advertises no stdin mode. It is still never on argv.
  • Grok has no flag to skip the user's MCP servers. Recursion into this server is blocked by the verified depth guard. Other user MCP servers may start inside a grok juror, constrained by --permission-mode dontAsk; I did not verify how grok treats MCP tool calls under that mode.
  • Codex tools: "no tool use" is enforced by disabling shell_tool and unified_exec plus the read-only sandbox. I found no flag that turns off every codex tool.
  • Codex has not answered live: no signed-in codex account was available, so no live codex verdict has been observed.
  • Codex API-key refusal: it matches the text of codex login status; the exact wording for an API-key login was never observed [assumed].
  • Juror free text (issue, summary) can still mention juror-local labels in the judge and rebuttal prompts. Jurors are told not to, but this is not enforced (core limitation).
  • Windows: the envFile permission check is skipped, since there are no POSIX mode bits.
  • Version: not bumped (CONTRIBUTING: releases are cut separately). The CHANGELOG has an [Unreleased] entry.

What is left

  • Release core 0.13.0, then mark ready.
  • A live codex juror run once a signed-in account is available.
  • Optional: ratchet the coverage thresholds (current values exceed them by 7–9 points).

…n in agent hosts

consensus_compare_attempts and consensus_list_attempts (stdio only).
The server computes each attempt's diff with git via execFile, so diffs
never pass through the calling agent's context:
- refs validated with rev-parse --verify --end-of-options, and refused
  when they start with "-"
- read-only: --no-ext-diff --no-textconv, fsmonitor off,
  GIT_OPTIONAL_LOCKS=0
- a checked-out attempt includes uncommitted and untracked changes
- lockfiles, generated and binary files skipped; whole files dropped past
  a per-attempt token budget; omissions listed for jurors and the result
The panel judges blind via ai-consensus-core's AdjudicationEngine (one
round plus judge by default, deadline and token ceiling return partial
results, progress per juror). Output: a short markdown verdict with the
recommended ref first, plus the typed result in structuredContent.
Optional testCommand (argv, no shell, per worktree, timeout) EXECUTES
REPOSITORY CODE and is refused unless serve --allow-test-command.

Keyless operation:
- codex driver on `codex exec`, flags checked against the installed
  0.170.0 help and accepted by a real run (approval never via
  -c approval_policy, read-only sandbox, shell tools disabled,
  --ignore-user-config, stdin prompt, -o answer)
- CLI JSON mode: the CLI enforces the juror verdict schema
- recursion guard AI_CONSENSUS_MCP_DEPTH on every CLI child; a server
  started with it >= 1 refuses to run
- "envFile" config key (must not be group/world accessible, values never
  logged); the missing-key error names the allowlist cause
- the wizard detects claude/grok/codex on PATH and offers a keyless
  panel first; "default" modelId omits -m for codex and grok

Also skills/best-of-n-verdict/SKILL.md and a "Using with Emdash" README
section. Tests that pinned the old "codex is refused" contract now pin
the new one; unregistered-driver tests use a fake driver name.
ai-consensus-core ^0.13.0 (unreleased).
…st timeouts

- Changes under agent tool directories (.claude/, .codex/, .grok/,
  .cursor/, .gemini/, …) are skipped as "agent-files"; jurors see a count
  only, because the paths can name the agent that produced the attempt.
- The jurors' omission header lists at most 20 paths per reason ("+N
  more") and counts against the per-attempt token budget, so a vendored
  directory cannot flood every prompt; the structured result caps file
  lists at 50 with exact totals.
- README "Using with Emdash": Codex's 60 s default MCP tool timeout
  (raise tool_timeout_sec) vs Claude Code's long per-call limit and
  progress-reset stdio idle limit.
- Codex probe: the API-key refusal matches status text whose exact
  wording was never observed; say so. The final argv (with and without
  -m) was re-run against codex 0.170.0 and reached the API.
- envFile permission check skipped on Windows (no POSIX mode bits).
- Subscription example seats grok with modelId "default" (grok 1.0.89 no
  longer lists grok-4); README no longer implies codex cannot be seated.
- Tests: the wizard's keyless and no-CLI new-config paths, a noisy
  fixture attempt (vendored files + agent settings file).
@marceloceccon
marceloceccon marked this pull request as ready for review November 20, 2026 23:00
@marceloceccon
marceloceccon merged commit 1ee2317 into main Nov 20, 2026
4 of 6 checks passed
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