Skip to content

Restore compatibility with current Codex and Claude Code - #1

Merged
imcitius merged 8 commits into
masterfrom
codex/modern-agent-compatibility
Sep 25, 2026
Merged

imcitius merged 8 commits into
masterfrom
codex/modern-agent-compatibility

Conversation

@imcitius

@imcitius imcitius commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Stoneforge's Codex integration used a removed CLI flag and outdated app-server response shapes, so startup could fail, cancellation omitted the required turn ID, and failed turns could be reported as successful. This updates startup/resume, model discovery, cancellation and error handling. Failed headless requests now release their sessions and report a non-zero exit.

Agent environment overrides, including SF_ENTITY_ID and the workspace root, now reach each Codex thread independently, including resumed threads. Previously they were dropped by the shared app-server integration, so task commands could use the operator identity instead of the running agent.

Claude Agent SDK is updated from 0.2.45 to 0.3.282. Session launches and model discovery strip the inherited nested-session marker, and closing a session terminates the SDK process and its transports. Codex resume IDs discovered during graceful shutdown are retained in session history; invalid legacy IDs are rejected.

The branch preserves authorship of fixes from stoneforge-ai#104, stoneforge-ai#116 and stoneforge-ai#118. Additional fixes, regression tests, opt-in live checks, documentation and changesets are included.

Validation:

  • pnpm typecheck and pnpm build passed after the latest changes. The new orchestration script also passes a standalone strict TypeScript check.
  • Smithy: 1,605 passed, 19 skipped, no failures. The unchanged Core, Storage and Quarry suites passed earlier on this branch: 2,737, 137 and 4,260 tests respectively.
  • Both live headless pipelines passed on macOS using Codex CLI 0.157.0 and Claude Agent SDK 0.3.282: Claude Director → Codex Worker → Claude Merge Steward, and Codex Director → Claude Worker → Codex Merge Steward.
  • The live pipelines use production service initialization and dispatch, actual CLI task operations, fresh Git worktrees and a local bare origin. Checks cover correct agent identities, immutable acceptance tests run successfully by both worker and steward, the merged commit, synchronized main checkout, worktree cleanup and session termination. Task transitions are performed by the agents, not injected by the test.
  • Earlier live catalog/start/close/resume checks passed with Codex CLI 0.154.0 and Claude Agent SDK 0.3.282, verifying retained conversation history. Regression tests cover cancellation races, nested failures, pagination/defaults, per-thread environment overrides, late process exits and failed initialization.
  • git diff --check passed. These are local results; the fork currently has no GitHub Actions workflows.

Live checks use model quota and require authenticated CLIs:

bun scripts/check-agent-compatibility.ts codex
bun scripts/check-agent-compatibility.ts claude-code
bun scripts/check-agent-orchestration.ts codex
bun scripts/check-agent-orchestration.ts claude-code

Limitations: interactive terminal conversations, GitHub approval workflows and Windows/Linux execution have not been tested live. The orchestration fixture covers a successful single-task local merge, not conflict resolution, rate-limit recovery or sustained concurrent workload. No release or deployment is included.

komoreka and others added 8 commits September 26, 2026 00:15
… spawns

When stoneforge runs from inside a Claude Code session (any user invoking
sf from the bash tool, or a director running in Claude Code), the
spawned claude subprocess inherits CLAUDECODE=1 from process.env. The
explicit `CLAUDECODE: '1'` in the env spread re-asserts it. Recent
versions of the claude binary refuse to start when CLAUDECODE is set,
emitting "Claude Code cannot be launched inside another Claude Code
session" to stderr and exiting 1. The Anthropic SDK surfaces this as
"Claude Code process exited with code 1", which the spawner swallows as
the cryptic "Session exited before init".

Strip CLAUDECODE from the inherited env before passing to the SDK
(headless) and node-pty (interactive). Stoneforge IS the parent of the
spawned claude; the spawned claude is a fresh top-level session, not
nested.

This reverses the intent of stoneforge-ai#32 for the macOS/Linux case but keeps the
spawn-env construction shape that stoneforge-ai#32 fixed for Windows. If there is a
Windows-specific reason CLAUDECODE must be set, gate it on platform.

Refs stoneforge-ai#32 (the original Windows fix that introduced CLAUDECODE='1').

(cherry picked from commit 18c9238)
…trip tests

Move the env construction (process.env merge, overrides, CLAUDECODE strip,
optional STONEFORGE_ROOT) from headless.ts and interactive.ts into a
shared helper at packages/smithy/src/providers/claude/env.ts. Both
providers now call buildClaudeSpawnEnv() rather than duplicating the
shape.

Adds 7 unit tests for the helper (env.bun.test.ts) covering the
CLAUDECODE strip from inherited env, the strip from caller-supplied
overrides, override precedence, STONEFORGE_ROOT injection, and input
non-mutation. Also adds 2 integration-style tests in headless.bun.test.ts
to verify the headless provider actually invokes the helper correctly
(SDK options.env reflects the strip).

Refs stoneforge-ai#103.

(cherry picked from commit 5b1ef3d)
Extract the Codex interactive argument construction into buildCodexInteractiveArgs so the unit test exercises the same production arg-building logic used by spawn instead of duplicating that logic in the test. The helper preserves the existing working-directory, resume, and model behavior.

Codex now documents --sandbox workspace-write as the replacement for the deprecated --full-auto shortcut, so use the documented sandbox flag for fresh and resumed interactive sessions.

Refs stoneforge-ai#114.

(cherry picked from commit 9baf6e9)
(cherry picked from commit f745d57)
@imcitius
imcitius marked this pull request as ready for review September 25, 2026 21:44
@imcitius
imcitius merged commit bb5f967 into master Sep 25, 2026
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.

3 participants