Skip to content

feat: add configuration for model, mode, and thought level#205

Merged
NathanFlurry merged 9 commits intomainfrom
effort-level
Mar 6, 2026
Merged

feat: add configuration for model, mode, and thought level#205
NathanFlurry merged 9 commits intomainfrom
effort-level

Conversation

@NathanFlurry
Copy link
Member

This PR adds end-to-end model/mode/thought-level configuration support across the Sandbox Agent TypeScript SDK, server routing/CLI reporting, and integration tests. It updates agent capability fallback/config extraction and agent config resources so report output includes normalized categories and defaults where available. It also updates docs for sessions/SDK/CLI and the new agent capabilities reference, including Claude-specific effort-level guidance via filesystem configuration before session creation. The branch includes related install/agent-management wiring and supporting type/export updates needed for the new configuration flows.

Bug Fixes Included

This PR also includes three critical bug fixes for the session configuration logic:

1. Session Lifecycle: Prevent Destruction of Pre-existing Sessions

Issue: resumeOrCreateSession would destroy a pre-existing session if configuration (model/mode/thoughtLevel) failed, causing data loss.

Fix: Removed the try-catch destroy block from the resume path. Config errors now propagate without destroying the session. The destroy-on-error pattern remains only in createSession, where destroying a brand-new session on config failure is appropriate.

2. Config Persistence: Sync Modes State in Fallback Path

Issue: When setSessionMode fallback used session/set_config_option to set mode, persistSessionStateFromMethod only updated configOptions but not modes.currentModeId, leaving the SDK's cached state inconsistent.

Fix: Added logic to detect when a mode-category config option is updated via the fallback path and keep modes.currentModeId in sync with the new value.

3. Race Condition: Fix Stale Record Overwrites

Issue: persistSessionStateFromMethod was called with a pre-await session record snapshot. If concurrent session/update events arrived during the RPC call and updated the persisted state via persistSessionStateFromEvent, those updates were silently overwritten by the stale snapshot.

Fix: Changed persistSessionStateFromMethod to take sessionId and re-read the record from persistence, ensuring it always merges against the latest state rather than a stale pre-call snapshot.

NathanFlurry and others added 5 commits March 3, 2026 17:05
Use `.first()` with safe fallback instead of direct `[0]` index access,
which would panic if the Vec is empty and no default is set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- destroySession: wrap session/cancel RPC in try/catch so local cleanup
  always succeeds even when the agent is unreachable
- createSession/resumeOrCreateSession: clean up the remote session if
  post-creation config calls (setMode/setModel/setThoughtLevel) fail,
  preventing leaked orphan sessions
- cli.mdx: fix example output to match current claude.json (model name,
  model order, and populated modes)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- resumeOrCreateSession: Remove destroy-on-error for the resume path. Config
  errors now propagate without destroying a pre-existing session. The destroy
  pattern remains in createSession (where the session is newly created and has
  no prior state to preserve).

- setSessionMode fallback: When session/set_mode returns -32601 and the
  fallback uses session/set_config_option, now keep modes.currentModeId
  in sync with the updated currentValue. Prevents stale cached state in
  getModes() when the fallback path is used.

- persistSessionStateFromMethod: Re-read the record from persistence instead
  of using a stale pre-await snapshot. Prevents race conditions where
  concurrent session/update events (processed by persistSessionStateFromEvent)
  are silently overwritten by optimistic updates.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@railway-app railway-app bot temporarily deployed to sandbox-agent / sandbox-agent-pr-205 March 6, 2026 02:41 Destroyed
@railway-app
Copy link

railway-app bot commented Mar 6, 2026

🚅 Deployed to the sandbox-agent-pr-205 environment in sandbox-agent

Service Status Web Updated (UTC)
website 🕗 Deploying (View Logs) Web Mar 6, 2026 at 8:24 am

…I list

- Replace invalid Codex mode values ("plan", "build") with valid ones
  ("auto", "full-access") in agent-sessions.mdx and sdk-overview.mdx
- Update CLAUDE.md stable method enumerations to include new session
  config methods (setSessionMode, setSessionModel, etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@railway-app railway-app bot temporarily deployed to sandbox-agent / sandbox-agent-pr-205 March 6, 2026 07:09 Destroyed
Keep both session config utility functions (effort-level) and process
log SSE / WebSocket helpers (main).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@railway-app railway-app bot temporarily deployed to sandbox-agent / sandbox-agent-pr-205 March 6, 2026 07:10 Destroyed
…sistence race

Add summary/description to all process management endpoint specs and the
not_found error type. Fix hydrateSessionConfigOptions to re-read from
persistence after the network call, and sync mode-category configOptions
on session/update current_mode_update events.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@railway-app railway-app bot temporarily deployed to sandbox-agent / sandbox-agent-pr-205 March 6, 2026 08:22 Destroyed
# Conflicts:
#	sdks/typescript/src/client.ts
@railway-app railway-app bot temporarily deployed to sandbox-agent / sandbox-agent-pr-205 March 6, 2026 08:23 Destroyed
@NathanFlurry NathanFlurry merged commit c91791f into main Mar 6, 2026
3 of 4 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