Skip to content

Preserve managed exec policy after rules parse errors - #31188

Merged
etraut-openai merged 5 commits into
mainfrom
etraut/preserve-managed-exec-policy
Jul 7, 2026
Merged

Preserve managed exec policy after rules parse errors#31188
etraut-openai merged 5 commits into
mainfrom
etraut/preserve-managed-exec-policy

Conversation

@etraut-openai

@etraut-openai etraut-openai commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Why

Cleanup for #31179 exposed a core fallback bug that the TUI had been handling locally. When a custom .rules file fails to parse, nonfatal clients warn and continue, but load_exec_policy_with_warning replaced the entire policy with Policy::empty() before managed requirements were merged. App-server and desktop clients could therefore silently lose required prompt and forbidden rules.

This fix is intentionally separate from #31179 so the TUI cleanup does not depend on it.

What changed

  • Preserve the managed requirements exec policy when custom file rules fail to parse, while returning the existing warning and discarding the file-based policy.
  • Use the same nonfatal fallback when loading network proxy policy.
  • Keep parse errors fatal for strict clients such as codex exec.

}
Err(err) => return Err(err.into()),
};
let (exec_policy, warning) = load_exec_policy_with_warning(&config_layer_stack).await?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a proxy-state regression for this path? The helper test covers command policy, but not that malformed custom rules still preserve a managed denied domain here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

}

#[tokio::test]
async fn malformed_custom_rules_preserve_requirements_exec_policy() -> anyhow::Result<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a test_codex regression here that starts a real session with malformed custom rules and a managed forbidden prefix, then verifies the command is rejected? This test only exercises the helper.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done.

etraut-openai added a commit that referenced this pull request Jul 6, 2026
## Why

App-server initialization captures exec-policy parse warnings only once.
Each `thread/start` then reloads config for that thread's cwd and
rereads its `.rules` files, so rules that become malformed after
initialization—or belong to a different project—are dropped without a
fresh warning to the requesting client.

## What changed

- Validate exec-policy rules against the freshly loaded per-thread
config during `thread/start`.
- Send the existing structured `configWarning` only to the connection
that requested the thread.
- Preserve nonfatal startup and avoid repeating an identical warning
already delivered during initialization.

This is intentionally separate from the TUI `legacy_core` cleanup in
#31179 and the managed-requirements fallback fix in #31188.
@etraut-openai
etraut-openai merged commit 831c14f into main Jul 7, 2026
35 checks passed
@etraut-openai
etraut-openai deleted the etraut/preserve-managed-exec-policy branch July 7, 2026 02:28
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants