Skip to content

feat(coding-agent): let root agents create sibling sessions (RES-1256) - #1996

Open
sethkarten wants to merge 3 commits into
mainfrom
res-1256-rlm-root-session
Open

feat(coding-agent): let root agents create sibling sessions (RES-1256)#1996
sethkarten wants to merge 3 commits into
mainfrom
res-1256-rlm-root-session

Conversation

@sethkarten

@sethkarten sethkarten commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add await rlm.create_session(prompt, name=..., cwd=..., model=..., thinking=...) for daemon-backed depth-0 agents
  • create a separate resident root session through the existing supervisor create and prompt operations
  • keep normal rlm(...) calls recursive and reject root creation from nested or inline sessions
  • return a typed Python handle with the new session identifiers, path, name, and model
  • require the updated runtime during kernel bootstrap and document the operation in the root-agent prompt

Test plan

  • npm run check
  • env -u RLM_DEPTH -u RLM_MAX_DEPTH -u RLM_SESSION_DIR npx tsx ../../node_modules/vitest/dist/cli.js --run test/agent-session-recursion.test.ts test/daemon-mode.test.ts test/system-prompt.test.ts test/ipython-bootstrap.test.ts test/kernel-bootstrap.test.ts
  • uv run python -m unittest test/test_create_session.py test/test_subagent_registry.py

Note

Medium Risk
Spawns new daemon sessions with model/auth and supervisor RPC; misconfiguration or partial failure is mitigated by validation and kill-on-error, but session lifecycle and naming still affect multi-agent orchestration.

Overview
Adds rlm.create_session so depth-0, daemon-backed root agents can spin up a separate resident top-level session (a sibling root), not a recursive child via rlm(...).

The coding-agent wires a new kernel host request rlm.create_session to AgentSession.createRlmSession, which validates prompt, optional name / model / thinking / cwd, enforces depth-0 and a host with createRlmRootSession, then delegates to the daemon. The daemon worker talks to the supervisor with create (lifecycle: resident) and prompt, returns session identifiers, and kills the new session if prompting fails.

The Python prime-agent-runtime exposes await rlm.create_session(...) (and on rlm.rlm) returning RLMCreateSessionHandle. Kernel bootstrap now requires callable create_session. Depth-0 RLM system prompts document the API. Shared RLM kwargs normalizers accept an operation label so error messages apply to both rlm.run and rlm.create_session.

Reviewed by Cursor Bugbot for commit 0c9c883. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add rlm.create_session API for daemon-backed root agents to create sibling sessions

  • Depth-0 daemon-backed agent sessions can now create a separate resident root session with an optional name, model, thinking level, and working directory, and receive its session IDs and file path.
  • The new rlm.create_session Python API dispatches a host request through the kernel and returns an RLMCreateSessionHandle typed result.
  • Runtime readiness probes now require callable rlm.create_session on both the top-level RLM module and its callable namespace.
  • AgentDaemon.createRlmRootSession connects to the supervisor, creates and prompts the resident session, and cleans up partially-created sessions on failure.
  • Risk: runtimes missing the required rlm.create_session entry points now fail RUNTIME_READY_CHECK in bootstrap.ts; nested, disposed, or inline sessions reject the operation via AgentSession.createRlmSession in agent-session.ts.

Macroscope summarized 0c9c883.

Comment thread packages/coding-agent/src/core/prompts/rlm.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
@sethkarten
sethkarten requested a review from snimu September 4, 2026 03:35
@snimu

snimu commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

rlm.create_session sidesteps the spawn policy that rlm.run enforces. _startRlmChildRun refuses to spawn once _rlmDepth >= _rlmMaxDepth, but createRlmSession (agent-session.ts ~L10796) has no equivalent gate, and the siblings it creates are fresh roots: default rlmMaxDepth 2 plus their own create_session, so an agent with spawning disabled can still grow the session tree without bound. The prompt paragraph advertising create_session (prompts/rlm.ts ~L149) is gated on depth === 0 && hasIpython only, so a spawn-disabled agent is actively told about it. This is a resource guard, not a security boundary — bash can reach the supervisor socket anyway — but the inconsistency is worth closing.

Minimal fix:

  • reject in createRlmSession when _rlmMaxDepth === 0
  • gate the prompt paragraph on allowRecursion too

[written by prime-agent, checked by snimu]

@snimu

snimu commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

createRlmRootSession (daemon-mode.ts ~L2501) sends a hand-built config subset — cwd, agentDir, sessionDir, provider, model, thinking, telemetryDisabled — with no launchEnv and no apiKey. The normal root-create path (main.ts ~L1007) sends the full config plus launchEnv: collectDaemonLaunchEnv(). The model preflight runs in the parent worker against the parent's credentials, but the sibling launches from the supervisor's ambient env, which can be older: after a new PRIME_API_KEY, --api-key, or custom provider env, create_session succeeds and the sibling's first prompt fails auth.

Suggested fix: forward the current worker's filtered launch env and spread runtimeConfig.apiKey into the config, same pattern as the existing sessionDir/telemetryDisabled spreads.

[written by prime-agent, checked by snimu]

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.

2 participants