restore: session-level permissions lost when resuming from dashboard card
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
- In `agent-orchestrator.yaml`, set `projects.
.agentConfig.permissions: suggest`. - Spawn a session with an override: `ao spawn
--permissions permissionless`. - Watch the agent run with auto-approvals (correct).
- Kill or restart the orchestrator.
- Resume the session (dashboard card "Restore" or `ao session resume`).
- Actual: agent is now prompting for approvals (`suggest` mode) — the `permissionless` override was silently dropped.
- 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.
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:
agent-orchestrator.yamlhad noagentConfigblock at all (project just hadname,sessionPrefix,repo,path,defaultBranch,trackerkeys).- Two parallel
ao spawn ... --agent claude-codecalls (cd-7, cd-8). - cd-7 hit a Bash permission prompt for
mkdirandgh pr diff(read-only commands). cd-8 ran with--dangerously-skip-permissionsand 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.
@yyovil any updates on this?
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.
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_idproject_id- original effective
permissions,model, andsubagent - 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