Skip to content

Revert "[9.4](backport #7794) refactor: clone ParsedPolicy in process… - #7805

Merged
ebeahan merged 1 commit into
elastic:9.4from
ebeahan:revert/9.4/pr-7794
Sep 11, 2026
Merged

Revert "[9.4](backport #7794) refactor: clone ParsedPolicy in process…#7805
ebeahan merged 1 commit into
elastic:9.4from
ebeahan:revert/9.4/pr-7794

Conversation

@ebeahan

@ebeahan ebeahan commented Sep 11, 2026

Copy link
Copy Markdown
Member

…Policy to prevent shared-state races (#7802)"

This reverts commit d8b6a04.

…processPolicy to prevent shared-state races (elastic#7802)"

This reverts commit d8b6a04.
@ebeahan ebeahan self-assigned this Sep 11, 2026
Copilot AI lite review requested due to automatic review settings September 11, 2026 13:19
@ebeahan
ebeahan requested a review from a team as a code owner September 11, 2026 13:19
@ebeahan
ebeahan requested review from macdewee and swiatekm and removed request for a team September 11, 2026 13:19

Copilot AI 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.

🟡 Changes recommended

Critical concurrency issues in exporter cloning and monitor lock scope remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Reverts the ParsedPolicy fan-out cloning refactor and restores shared policy dispatch.

Changes:

  • Removes ParsedPolicy.Clone() and its isolation test.
  • Moves policy-data and secret-key copying into processPolicy.
  • Restores shared dispatch and broad monitor locking.
  • Reverts deep cloning of nested policy and OTel maps.
File summaries
File Summary Review findings
internal/pkg/policy/parsed_policy.go Removes ParsedPolicy.Clone. None.
internal/pkg/policy/parsed_policy_test.go Removes clone isolation coverage. None.
internal/pkg/policy/monitor.go Restores shared dispatch and broad mutex scope. Critical (3 votes): The mutex remains held during rate limiting and channel sends, blocking subscriptions, unsubscriptions, and policy updates (lines 277 and 314).
internal/pkg/model/ext.go Reverts nested OTel map cloning. Critical (3 votes): Only outer maps are cloned; inner exporter configs remain shared and can race during mutation (lines 99 and 144).
internal/pkg/api/handleCheckin.go Adds local policy-data and secret-key copies. Nit (2 votes): The updated comment is ungrammatical and unclear (line 1166).
internal/pkg/api/handleCheckin_test.go Tests concurrent processing with the shared policy. None.
Review details

Suppressed comments (2)

internal/pkg/model/ext.go:144

  • maps.Clone(v) only copies each output's top-level map, so nested maps remain shared with the cached policy. ProcessOutputSecret can follow a path secret into an existing nested map and mutate it, allowing concurrent check-ins to race and leak one agent's substituted secret into another response. This needs a recursive clone for output values before processing.
		r[k] = maps.Clone(v)

internal/pkg/policy/monitor.go:314

  • Sending the cached ParsedPolicy without cloning reintroduces shared mutable state across fan-out subscribers. processPolicy runs concurrently for these deliveries, and the reverted ClonePolicyData only shallow-copies nested maps, so secret/output/OTel preparation can mutate another agent's policy and race. Keep the clone at this dispatch boundary or otherwise guarantee a complete deep copy before delivery.
		case s.ch <- &policy.pp:
  • Files reviewed: 6/6 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/pkg/model/ext.go
Comment thread internal/pkg/policy/monitor.go
Comment thread internal/pkg/api/handleCheckin.go
@ebeahan
ebeahan enabled auto-merge (squash) September 11, 2026 13:52
@ebeahan
ebeahan merged commit 7c08856 into elastic:9.4 Sep 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants