Skip to content

Subagents don't inherit the parent's -e extensions or --api-key #577

Open

Description

@m-aebrer

Original Request

From the round-2 review discussion on PR 575:

you're saying that dreb -p -e [extension path] doesn't allow subagents to inherit the extension? feels like a gap worth noting but maybe I agree not a merge blocker here since it'll require a lot more buildout to fix

On a parent started with --api-key:

not sure if there is any issue passing the key forward to children... seems okay to me?

Fold it into the followup issue for -e.

Summary

Each subagent is a separate dreb process started with a fixed argument list. Two things the parent gets only from its own command line never reach that process: extensions loaded with -e/--extension, and an API key supplied with --api-key. Subagents therefore lack the parent's session-only extensions, and they cannot authenticate with a key given only on the command line. PR 575 makes unconfigured subagents inherit the parent's model, so this now affects every default subagent call when the parent's model depends on either.

Current Behavior

  • Spawn arguments: spawnSubagent (packages/coding-agent/src/core/tools/subagent.ts, the args builder) passes only mode, session, model/provider, thinking, tools, system prompt, agent type, parent session, and task. It never passes -e, --no-extensions, or --api-key.
  • Extensions:
    • Subagents load only the extensions they discover themselves (~/.dreb/agent/extensions/, .dreb/extensions/, settings). An extension loaded with -e is missing from every subagent, along with its tools, hooks, and providers.
    • If that extension registered the provider the parent is running on, the parent's pre-spawn check still passes, because the parent's registry has the provider. The subagent then exits with Unknown provider "<name>".
    • The reverse also happens: --no-extensions on the parent does not stop subagents from loading discovered extensions.
  • API key:
    • --api-key is stored only in the parent's memory, as a runtime override for the selected model's provider (main.ts, AuthStorage.setRuntimeApiKey).
    • AuthStorage.hasAuth() counts that override, so the parent's pre-spawn auth check passes.
    • The subagent never receives the key. Unless the key is also in auth.json or a provider environment variable, the subagent fails with No API key found for <provider>. This happens in both interactive and print modes.
  • Already true before PR 575: single-model mode (issue 517) always inherited the parent's model. PR 575 makes inheritance the default route.

Proposed Behavior

  • Subagents of a session started with -e <path> load the same session-only extensions. --no-extensions carries over the same way.
  • Subagents can authenticate with a key the parent received through --api-key.
  • Forwarding must not expose the key more widely than it is in the parent:
    • Not on the subagent's command line, which other local users can read through ps.
    • Not in a standard provider environment variable such as OPENAI_API_KEY. The bash tool passes its whole environment to every shell command (packages/coding-agent/src/utils/shell.ts), so the subagent's commands could read a key that the parent's own commands cannot.

Acceptance Criteria

  • A subagent spawned from a session started with dreb -e <path> has that extension's tools, hooks, and providers. This includes a parent running on a model from a provider that extension registers.
  • A subagent spawned from a session started with --no-extensions loads no discovered extensions.
  • If the parent was started with --api-key and has no other credentials for that provider, a subagent on the inherited model authenticates with that key.
  • The forwarded key does not appear in the subagent's command line, and the subagent's tool subprocesses cannot read it from their environment.

Open Questions

  • Should every -e extension load in subagents, or should extensions be able to opt out (for example, UI-only extensions)?
  • Should the other session-only resource flags (--skill, --prompt-template, --no-skills, --no-prompt-templates) follow the same rule?

Technical Notes

  • One possible key transport: a dreb-specific environment variable that the subagent reads and deletes from process.env at startup, before any tool runs.
  • The parent's pre-spawn inheritance check (resolveParentModel in subagent.ts) uses the parent's registry and auth state. As a result it passes in exactly the cases above where the subagent later fails.
  • Found during the round-2 review of PR 575: assessment.

Activity

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