agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

restore: session-level permissions lost when resuming from dashboard card

Open harsh-batheja opened this issue 7 months ago • 3 comments

Summary

When a session is restored (via the dashboard card "Restore" action, or any other path that triggers `session-manager.ts`'s restore flow), the agent gets re-launched with project-default permissions instead of the permissions the session was originally spawned with. If the user ran the session under `--permissions permissionless` (or anything other than the project default), resume loses that setting and the agent starts requiring approvals again — or worse, vice versa.

Affected agents

Any plugin whose `getRestoreCommand` reads `project.agentConfig?.permissions`:

  • `@aoagents/ao-plugin-agent-claude-code` — `packages/plugins/agent-claude-code/src/index.ts:830`
  • `@aoagents/ao-plugin-agent-codex` — `packages/plugins/agent-codex/src/index.ts:736`
  • `@aoagents/ao-plugin-agent-opencode` — `packages/plugins/agent-opencode/src/index.ts:~430`
  • `@aoagents/ao-plugin-agent-kimicode` — `packages/plugins/agent-kimicode/src/index.ts:~575`

(Aider + cursor are unaffected — they return `null` from `getRestoreCommand`.)

Root cause

`packages/core/src/session-manager.ts:2764-2778` resolves the effective launch config correctly:

```ts const agentLaunchConfig = { sessionId, projectConfig: projectConfigForLaunch, issueId: session.issueId ?? undefined, permissions: selection.role === "orchestrator" ? "permissionless" : selection.permissions, // ← resolved per-session, not project default model: selection.model, subagent: selection.subagent, };

if (plugins.agent.getRestoreCommand) { const restoreCmd = await plugins.agent.getRestoreCommand(session, projectConfigForLaunch); launchCommand = restoreCmd ?? plugins.agent.getLaunchCommand(agentLaunchConfig); } else { launchCommand = plugins.agent.getLaunchCommand(agentLaunchConfig); } ```

The bug is on the second line: `getRestoreCommand` only receives `(session, projectConfigForLaunch)` — not the resolved `agentLaunchConfig`. So each plugin's restore path falls back to reading `project.agentConfig?.permissions`, which is just the project default. The per-session override (`selection.permissions`) is invisible to the plugin.

The `--model` and `--subagent` restore-time choices have the same issue — they're resolved on `selection` but the plugin can only see project-level defaults.

Reproducer

  1. In `agent-orchestrator.yaml`, set `projects..agentConfig.permissions: suggest`.
  2. Spawn a session with an override: `ao spawn --permissions permissionless`.
  3. Watch the agent run with auto-approvals (correct).
  4. Kill or restart the orchestrator.
  5. Resume the session (dashboard card "Restore" or `ao session resume`).
  6. Actual: agent is now prompting for approvals (`suggest` mode) — the `permissionless` override was silently dropped.
  7. Expected: agent resumes with `permissionless` — the original effective permissions.

Fix direction

Change the `Agent.getRestoreCommand` signature in `packages/core/src/types.ts:507` to accept the full `AgentLaunchConfig`:

```ts getRestoreCommand?( session: Session, config: AgentLaunchConfig, // ← new: carries resolved permissions / model / subagent ): Promise<string | null>; ```

Update `session-manager.ts:2774` to pass `agentLaunchConfig` instead of `projectConfigForLaunch`, then update each plugin's `getRestoreCommand` to prefer `config.permissions` / `config.model` / `config.subagent` over the project defaults.

Keep `project` accessible via `config.projectConfig` so plugins don't lose anything.

Acceptance criteria

  • [ ] `Agent.getRestoreCommand` signature updated in core types
  • [ ] `session-manager.ts` passes the full `agentLaunchConfig` on restore
  • [ ] All four affected plugins (claude-code, codex, opencode, kimicode) read permissions + model + subagent from `config`, falling back to project defaults only when unset
  • [ ] Unit test per plugin: restoring a session spawned with a non-default `permissions` emits the correct approval flag
  • [ ] Regression test in `session-manager` that asserts `getRestoreCommand` receives the resolved permissions

Out of scope

  • Persisting the original spawn permissions on `Session` itself (we resolve via `selection` on every restore — the gap here is plumbing, not storage).
  • Auditing what else on `selection` never reaches the plugin (model and subagent have the same issue, but at least model is often identical between project default and per-session override).

Discovered in

Follow-up to #1384 / PR #1390 (kimicode plugin) while testing the restore-from-card flow on a real kimi-cli install.

harsh-batheja avatar Apr 22 '26 21:04 harsh-batheja

Related to the per-session permissions resolution gap, but on the spawn side rather than the restore side: when agentConfig.permissions is absent entirely from the project config, the resolved default drifts unpredictably between workers spawned by identical ao spawn invocations.

Repro from our Day 8 testing:

  1. agent-orchestrator.yaml had no agentConfig block at all (project just had name, sessionPrefix, repo, path, defaultBranch, tracker keys).
  2. Two parallel ao spawn ... --agent claude-code calls (cd-7, cd-8).
  3. cd-7 hit a Bash permission prompt for mkdir and gh pr diff (read-only commands). cd-8 ran with --dangerously-skip-permissions and didn't prompt.

Same command, different outcome — likely the same selection.permissions resolution path you describe in the restore case, but at spawn time, with the default falling back to a value that varies based on something we couldn't pin down (cached state? plugin defaults? environment difference between the two sessions?).

We worked around it by adding agentConfig.permissions: bypass explicitly under defaults in our yaml. The drift went away. But the underlying gap is the same shape as the restore case: permissions resolution that should be deterministic from the config + per-session override flag has a fallback path that produces inconsistent results.

If the fix you proposed (passing the full agentLaunchConfig to getRestoreCommand) is symmetrical — i.e., the spawn path also reads from a single resolved config rather than reaching back to project defaults inside the plugin — this might fall out for free.

Tonedeath avatar Apr 29 '26 10:04 Tonedeath

@yyovil any updates on this?

harsh-batheja avatar May 17 '26 11:05 harsh-batheja

Related to #1900 — "Launch Orchestrator (clean context)" button. If a restored session loses permissions, the clean-context button needs to ensure the new session initializes with correct permissions from scratch.

OrcInc avatar May 17 '26 12:05 OrcInc

This looks like the same class of bug as "dashboard card state drift": the UI knows which session the user clicked, but the restore path rehydrates from project defaults instead of the exact live/session launch contract.

I would add one restore receipt that both CLI and dashboard can display/log:

  • session_id
  • project_id
  • original effective permissions, model, and subagent
  • restore-time effective values
  • selected plugin restore command
  • restored_same_session_contract: true/false

That would make this visible as a contract break instead of only as a later approval prompt surprise.

Faryo handles a narrower version of the same invariant: a phone/browser action is successful only when the same live tmux-backed session consumes it, not when the web/dashboard layer merely accepts the action. Public proof shape: https://github.com/Snailflyer/faryo/releases/download/v1.0.7/faryo-public-redacted-same-session-handoff-walkthrough-20260528-0120.gif

Snailflyer avatar May 31 '26 00:05 Snailflyer