agentleFS
fritzprixfritzprix/libr-agent/.agents/skills/sync-pending-approvals/SKILL.md

sync-pending-approvals

Skill11 starsChanged 20 days agoMITView on GitHub

Code recipes and explanation for synchronizing Rust backend pending tool approvals (YOLO mode/manual approval) to the frontend React UI when a user resumes or opens an existing agent session. Use this skill when modifying the AgentSession state to maintain approval channels or when fixing UI bugs related to missing pending tool executions upon page reload/session switch.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When subagent sessions (or inactive sessions) require tool approval:

    line 12
  2. Very specific:

    When the frontend explicitly opens a session, it calls agent_resume_session.

    line 30
  3. Very specific:

    Update the tool execution loop (src-tauri/src/agent/llm/tool_execution.rs) to store the struct instead of just the sender.

    line 45
  4. Very specific:

    Update src-tauri/src/commands/agent_commands.rs (specifically the agent_resume_session handler) to re-emit the events.

    line 46
  5. Very specific:

    Update src/context/AgentSessionContext.tsx to handle deduplicate insertions into the pending array.

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Sync Pending Approvals

This skill is designed to solve a synchronization issue where an agent spawns a tool requiring user approval, but the user switches away from the session in the UI, or the UI is reloaded. Because the approval request was sent while the session was not active in the UI, the frontend misses the event, and the backend blocks indefinitely waiting for the oneshot::channel response.

Problem Context

When subagent sessions (or inactive sessions) require tool approval:

  1. Rust backend emits a ToolExecutionRequiresApproval event and awaits a oneshot channel response.
  2. The UI (AgentSessionContext.tsx) filters out events for inactive sessions.
  3. The background task deadlocks.

The Solution

To solve this, we must cache the approval details in the Rust session state and re-emit the event when the frontend resumes the session.

1. Update AgentSession State

Currently, pending_approvals only stores the Sender<bool>. It needs the context (tool_name and arguments) to recreate the event.

See rust-state-changes.md for the exact code modifications required for AgentSession and ToolExecutionStarted.

2. Re-emit Events on Session Resume

When the frontend explicitly opens a session, it calls agent_resume_session. We must hook into this phase to read the pending_approvals map and fire the events again.

See rust-resume-logic.md for the exact code modifications.

3. Frontend Deduplication

The frontend needs to ensure that if these events fire again, they don't create duplicate entries in the pending list.

See frontend-dedup.md for the required changes.


Instructions for the Agent applying this skill

  1. Locate AgentSession struct definition (usually in src-tauri/src/agent/state.rs or similar). Apply the new struct and update all initialization sites.
  2. Update the tool execution loop (src-tauri/src/agent/llm/tool_execution.rs) to store the struct instead of just the sender.
  3. Update src-tauri/src/commands/agent_commands.rs (specifically the agent_resume_session handler) to re-emit the events.
  4. Update src/context/AgentSessionContext.tsx to handle deduplicate insertions into the pending array.
  5. Compile and test that the tool approval modal correctly appears when switching back to a session that was waiting for approval.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.