Skip to content

Move permissions guidance into World State - #31602

Closed
sayan-oai wants to merge 2 commits into
mainfrom
sayan/permissions-world-state
Closed

Move permissions guidance into World State#31602
sayan-oai wants to merge 2 commits into
mainfrom
sayan/permissions-world-state

Conversation

@sayan-oai

@sayan-oai sayan-oai commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Why

Permissions guidance is model-visible state, but initial context and later turns currently build and compare it through separate paths. That comparison covers only selected TurnContext fields, missing changes such as refreshed catalog text and requiring reviewer-specific persistence like #31309.

What changed

  • add a persisted permissions World State section keyed by model and a fingerprint of the rendered guidance
  • build it from the active permission profile, reviewer, model-catalog messages from Use model catalog approval messages #31312, and exec policy
  • remove the separate initial-context and turn-update permissions paths
  • reconcile legacy, resumed, and forked histories through the existing World State machinery
  • update prompt snapshots for the resulting World State ordering

This supersedes #31309 by persisting what the model was actually shown rather than one input to that rendering.

Known Tradeoffs

  • Ordering: permissions move after skills/extensions/context-window guidance
  • Cost: every World State build rerenders permissions and performs some synchronous filesystem metadata checks
  • Prefix gap: flag-off same-turn compaction may lose newly approved-prefix guidance until the next turn; enforcement remains correct

@sayan-oai
sayan-oai requested a review from a team as a code owner July 8, 2026 16:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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.

💡 Codex Review

InitialContextInjection::BeforeLastUserMessage(Arc::clone(&world_state)),

P2 Badge Refresh world state before mid-turn compaction

When DeferredExecutor is off (its feature default is false), this passes the turn-start world_state into mid-turn compaction. Execpolicy approvals mutate services.exec_policy later in the same turn, but the cached world_state is only refreshed under DeferredExecutor before sampling, so a context-limit/new_context compaction after an approval rebuilds replacement history with stale permissions and drops the separate ApprovedCommandPrefixSaved guidance that compaction does not retain. The remainder of that turn can therefore lose the newly approved prefix guidance; rebuild the world state here or keep the approval fragment through compaction.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +110 to +112
self.instructions
.clone()
.map(|instructions| Box::new(instructions) as Box<dyn ContextualUserFragment>)

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.

P0 Badge Cap permissions diffs before re-emitting them

For OnRequest/granular sessions, a permissions refresh now emits the entire PermissionsInstructions body from this world-state diff path. That body includes the full approved exec-policy prefix list via approved_command_prefixes_text(exec_policy), and this new update path has no hard cap; after many saved approvals a single developer item can exceed 1k tokens every time permissions refresh. Please cap or summarize the rendered permissions diff before boxing it.

AGENTS.md reference: AGENTS.md:L97-L99

Useful? React with 👍 / 👎.

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.

the World State RFC says we will render the full block on each change.

@sayan-oai

Copy link
Copy Markdown
Contributor Author

💡 Codex Review

InitialContextInjection::BeforeLastUserMessage(Arc::clone(&world_state)),

P2 Badge Refresh world state before mid-turn compaction
When DeferredExecutor is off (its feature default is false), this passes the turn-start world_state into mid-turn compaction. Execpolicy approvals mutate services.exec_policy later in the same turn, but the cached world_state is only refreshed under DeferredExecutor before sampling, so a context-limit/new_context compaction after an approval rebuilds replacement history with stale permissions and drops the separate ApprovedCommandPrefixSaved guidance that compaction does not retain. The remainder of that turn can therefore lose the newly approved prefix guidance; rebuild the world state here or keep the approval fragment through compaction.

ℹ️ About Codex in GitHub

rebuilding worldstate before inline compaction would lead to history rewrites (replacement history says env A was always ready if it went from starting -> ready after first request but before mid-turn compaction).

but this finding is correct that this is currently a regression as written for flag off behavior; before this change compaction used the live ExecPolicy to rebuild the current approved command prefixes mid-turn. seeing if there's a better way we can preserve this behavior for flag off.

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant