Skip to content

fix(agent): nested agent start loses assigned name — list/send fall back to folder-PID identity #402

Open

Description

@codeaholicguy

Summary

ai-devkit agent start executed from inside a sandboxed/nested context (e.g. a lead agent's sandboxed shell) reports success with the assigned name but the entry is invisible to agent list/agent send, which instead see a synthesized fallback identity {cwd-folder}-{pid} (e.g. slug-lib-75800).

Repro (deterministic, any harness)

HOME=/tmp/fakehome ai-devkit agent start --type pi --name tests --cwd .../slug-lib
# → ✔ Agent "tests" started (PID 1769863); Attach: tmux attach -t tests

ai-devkit agent list    # from the real HOME
# → slug-lib-1769863    ← {cwd-folder}-{pid} fallback — the reported identity
#   send --id tests → No agent found

Terminal-started agents keep their names; only sandboxed callers with a divergent filesystem view lose them.

Root cause (code-verified)

agent start does not use the daemon. The path is:

start.command.ts → startAgent() [ManagedAgentRuntime.ts:89]
  → AgentRegistry.default() → DEFAULT_REGISTRY_PATH = os.homedir()/.ai-devkit/agents.json (+ SQLite)

The registry write resolves from the calling process's view — under a sandbox that is an overlay the daemon never sees (sandbox flavors either redirect HOME or overlay out-of-workspace writes). The daemon discovers only the process and synthesizes {folder}-{pid}. This is the last major legacy direct-write bypass of the sole-writer daemon architecture.

Fix direction (approved)

  1. Route agent start through the daemon — new daemon RPC agent.start (type, name, cwd, mode): daemon-side validation (name regex, name-in-use, cwd exists), session creation, and registry write under the daemon's store. The CLI becomes a thin client with fast pre-checks. This covers both divergence flavors (HOME rewrite and write overlay) because the write happens inside the daemon's sane view.
  2. Round-trip verification + loud failure — after start (both the daemon path and the legacy daemon-down fallback), verify the entry is visible to the identity authority before reporting success. On divergence, fail with a clear sandbox/divergent-environment diagnostic instead of a false ✔.
  3. Autostart guard — never auto-spawn a daemon from a divergent/sandboxed environment; error loudly with guidance.

Deferred (phase 2, only if reported in the wild): HOME-independent socket resolution chain (XDG_RUNTIME_DIR → /tmp/ai-devkit-$UID → legacy). Normal machines have one HOME and one socket; the chain only matters for sandboxes that rewrite HOME specifically.

Related: #400 (send --wait no-session failure) occurs in the same nested-dispatch flow and composes with this fix.

Acceptance criteria

  • Sandboxed/nested agent start either succeeds with the assigned name visible to list/send, or fails loudly with a divergent-environment diagnostic — never a silent fallback identity
  • No false success in any mode, including the daemon-down fallback path
  • No daemon auto-spawn from divergent environments
  • e2e regression covering the fake-HOME sequence (succeed-via-daemon or fail-loud, never folder-PID)

Activity

  1. changed the title [-]fix(agent): opencode agents listed under OpenCode's own session name instead of the assigned --name[/-] [+]fix(agent): nested agent start loses assigned name — list/send fall back to folder-PID identity[/+] on Oct 17, 2026
  2. added 3 commits that reference this issue on Oct 17, 2026
    ba933d9
    84972f2
    5be480d
  3. codeaholicguy commented on Oct 17, 2026

    @codeaholicguy
    OwnerAuthor

    Scope update in #403 per review: the HOME-independent socket chain is deferred to phase 2 (socket stays $HOME/.ai-devkit/daemon.sock). What ships now:

    • agent.start RPC in devkitd — daemon-side validation, tmux session creation, pid polling, registry write under the daemon's own store; CLI start delegates when the socket answers. Both HOME-divergence and write-overlay flavors covered since the write happens inside the daemon's sane view.
    • Loud failure instead of false success: local fallback refuses before starting under divergent HOME when the account store exists, warns when self-consistent, and round-trips the registry write before reporting success.
    • Autostart guard: ensureDaemon never spawns a twin daemon from a divergent HOME — loud diagnostic instead.
    • Synthesized identities marked unregistered:<folder>-<pid>; spawned child procs fold into their parent; session titles stay metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions