Skip to content

fix: reload persist rule into in-memory Policy immediately#3716

Merged
esengine merged 3 commits into
esengine:main-v2from
HorusJiang:fix/always-allow-persist-all-tools
Jun 9, 2026
Merged

fix: reload persist rule into in-memory Policy immediately#3716
esengine merged 3 commits into
esengine:main-v2from
HorusJiang:fix/always-allow-persist-all-tools

Conversation

@HorusJiang

Copy link
Copy Markdown
Contributor

问题描述

用户点击"总是允许"(Allow Persistently)后,权限规则通过 OnRemember 写入了 reasonix.toml 配置文件,但内存中的 Policy.Allow 没有被同步更新。导致以下情况:

  • ✅ 规则已持久化到磁盘,重启会话后生效
  • ✅ 当前会话走 Approver 路径(controller.granted)能正常工作
  • ❌ 但如果有代码路径直接调用 Policy.Decide(),会漏掉刚写入的 allow 规则,仍然弹窗

修复方案

permission.goGate.Check() 中,OnRemember 将规则写入磁盘后,立即将解析后的规则追加到 g.Policy.Allow 切片中,使内存中的 Policy 同步更新。

这样确保内存中的 Policy 与持久化配置保持实时一致,无需重启会话即可生效。

改动范围

internal/permission/permission.go — 新增 8 行代码。

Closes #3607

Problem

When a user clicks "Always allow" (Allow Persistently) on a tool approval prompt, the rule is persisted to reasonix.toml via OnRemember, but the in-memory Policy.Allow is not updated. This means:

  • ✅ The rule survives a session restart (config loads it)
  • ✅ The current session's Approver path works (controller.granted covers it)
  • ❌ Any code path that consults Policy.Decide() directly would still see the old policy and miss the new allow rule

Fix

In permission.go Gate.Check(), after OnRemember writes the rule to disk, also parse and append the rule to g.Policy.Allow so the in-memory Policy reflects the persisted rule immediately.

This ensures the in-memory Policy stays consistent with the on-disk config without requiring a session restart.

Diff

Only internal/permission/permission.go — 8 lines added.

Closes #3607

When user clicks 'Always allow' (Allow Persistently) on a tool approval
prompt, the current code only remembers the grant for that specific tool
(e.g. write_file). Later in the same session, other tools like bash still
trigger permission prompts, confusing the user.

This fix makes 'Always allow' set a wildcard session grant (c.granted['*'])
so all writer tools are auto-allowed for the rest of the session without
further prompting. The actual on-disk config rule is still written as before
via OnRemember for cross-session persistence.

The normal 'Allow for this session' remains tool-specific as before.
After OnRemember writes an 'always allow' rule to the on-disk config,
also append the parsed rule to the Gate's in-memory Policy.Allow slice
so it takes effect in the current session without requiring a restart.

Previously, clicking 'Always allow' on a tool (e.g. write_file) would:
1. Write the rule to reasonix.toml ✅
2. Set c.granted['write_file'] = true for the Approver path ✅
3. BUT: the Gate's Policy was not updated in memory ❌
   → Any code path consulting Policy.Decide() directly would still see
     the old policy and not match the new allow rule

This fix adds the parsed rule to g.Policy.Allow after writing to disk,
so the in-memory Policy stays consistent with the persisted config.

Ref: esengine#3607
@github-actions github-actions Bot added the v2 Go rewrite (1.x) — main-v2 branch, active development label Jun 9, 2026

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

端到端验证通过:复现了 #3607(always-allow 后直接走 Policy.Decide 仍会再次弹窗),打上本 PR 后 Decide 立即返回 Allow,permission 包回归全绿。规则同步与持久化语义一致,合并。感谢!

@esengine esengine enabled auto-merge (squash) June 9, 2026 15:10
@esengine esengine merged commit 48d21d5 into esengine:main-v2 Jun 9, 2026
14 checks passed
SuMuxi66 pushed a commit to SuMuxi66/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…3716)

* fix: always allow (persist) now grants all tools for the session

When user clicks 'Always allow' (Allow Persistently) on a tool approval
prompt, the current code only remembers the grant for that specific tool
(e.g. write_file). Later in the same session, other tools like bash still
trigger permission prompts, confusing the user.

This fix makes 'Always allow' set a wildcard session grant (c.granted['*'])
so all writer tools are auto-allowed for the rest of the session without
further prompting. The actual on-disk config rule is still written as before
via OnRemember for cross-session persistence.

The normal 'Allow for this session' remains tool-specific as before.

* Revert "fix: always allow (persist) now grants all tools for the session"

This reverts commit f90ba6f.

* fix: reload persist rule into in-memory Policy immediately

After OnRemember writes an 'always allow' rule to the on-disk config,
also append the parsed rule to the Gate's in-memory Policy.Allow slice
so it takes effect in the current session without requiring a restart.

Previously, clicking 'Always allow' on a tool (e.g. write_file) would:
1. Write the rule to reasonix.toml ✅
2. Set c.granted['write_file'] = true for the Approver path ✅
3. BUT: the Gate's Policy was not updated in memory ❌
   → Any code path consulting Policy.Decide() directly would still see
     the old policy and not match the new allow rule

This fix adds the parsed rule to g.Policy.Allow after writing to disk,
so the in-memory Policy stays consistent with the persisted config.

Ref: esengine#3607

---------

Co-authored-by: HorusJiang <horusjiang@users.noreply.github.com>
dorokuma pushed a commit to dorokuma/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…3716)

* fix: always allow (persist) now grants all tools for the session

When user clicks 'Always allow' (Allow Persistently) on a tool approval
prompt, the current code only remembers the grant for that specific tool
(e.g. write_file). Later in the same session, other tools like bash still
trigger permission prompts, confusing the user.

This fix makes 'Always allow' set a wildcard session grant (c.granted['*'])
so all writer tools are auto-allowed for the rest of the session without
further prompting. The actual on-disk config rule is still written as before
via OnRemember for cross-session persistence.

The normal 'Allow for this session' remains tool-specific as before.

* Revert "fix: always allow (persist) now grants all tools for the session"

This reverts commit f90ba6f.

* fix: reload persist rule into in-memory Policy immediately

After OnRemember writes an 'always allow' rule to the on-disk config,
also append the parsed rule to the Gate's in-memory Policy.Allow slice
so it takes effect in the current session without requiring a restart.

Previously, clicking 'Always allow' on a tool (e.g. write_file) would:
1. Write the rule to reasonix.toml ✅
2. Set c.granted['write_file'] = true for the Approver path ✅
3. BUT: the Gate's Policy was not updated in memory ❌
   → Any code path consulting Policy.Decide() directly would still see
     the old policy and not match the new allow rule

This fix adds the parsed rule to g.Policy.Allow after writing to disk,
so the in-memory Policy stays consistent with the persisted config.

Ref: esengine#3607

---------

Co-authored-by: HorusJiang <horusjiang@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 桌面端点击"总是允许"后,同一会话内后续其他工具调用仍然弹窗

2 participants