Skip to content

fix(hooks): serialize nested hook metadata in native hook files - #3199

Closed
Mohammed Alkindi (MohammedAlkindi) wants to merge 1 commit into
microsoft:mainfrom
MohammedAlkindi:fix/hook-nested-metadata-json
Closed

Mohammed Alkindi (MohammedAlkindi) wants to merge 1 commit into
microsoft:mainfrom
MohammedAlkindi:fix/hook-nested-metadata-json

Conversation

@MohammedAlkindi

Copy link
Copy Markdown
Contributor

Description

Nested hook metadata such as an env object fails install/update with Object of type mappingproxy is not JSON serializable: renderers shallow-copied the frozen IR. A recursive _thaw() now rebuilds plain dicts and lists at the render boundary, keeping the IR immutable. New unit and apm install e2e tests: 14 passed.

Issue and approved scope

Issue: #3167

Human scope-approval comment: #3167 (comment)

Fixes #3167, completing it.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass (full suite not run cleanly)
  • Added tests for new functionality (if applicable)

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via uv run --extra dev python -m tests.spec_conformance.gen_statement and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

The hook IR freezes dicts into MappingProxyType and lists into tuples.
Claude, Codex, Gemini and Antigravity rendering copied handler and
binding metadata with a shallow dict() and appended raw entries as-is,
so a nested value such as an env object reached json.dumps as a
mappingproxy and install/update failed.

Render through a recursive _thaw() that rebuilds plain dicts and lists,
so output is JSON-serializable and independent of the frozen IR.

Fixes microsoft#3167

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.

🟢 Approval recommended

The fix consistently covers all affected rendering paths with focused regression tests and matching documentation.

0 open findings

What changed in this PR

Fixes native hook serialization by recursively converting frozen IR metadata into mutable JSON-compatible containers.

Changes:

  • Adds recursive metadata thawing across native hook renderers.
  • Adds unit and install-level regression coverage.
  • Updates hook authoring documentation and changelog.
File Description
src/​apm_cli/​integration/​hook_native_formats.py Recursively materializes metadata before rendering.
tests/​unit/​integration/​test_hook_native_formats.py Covers serialization, metadata preservation, and isolation.
tests/​integration/​test_hook_nested_metadata_install_e2e.py Verifies installation writes nested metadata.
docs/​src/​content/​docs/​producer/​author-primitives/​hooks-and-commands.md Documents nested metadata preservation.
CHANGELOG.md Records the bug fix.

🧠 Review effort: Balanced


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

Daniel Meppiel (danielmeppiel) added a commit to abhishekacharya200/apm that referenced this pull request Oct 16, 2026
Select nonredundant regression assets from microsoft#3199 commit b36ed0f for the approved microsoft#3167 scope. Keep microsoft#3211 as the sole implementation and its canonical _thaw unchanged. Prove binding/raw/source independence and normal approved local install/update without executing hooks.

Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com>

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
Daniel Meppiel (danielmeppiel) added a commit to abhishekacharya200/apm that referenced this pull request Oct 19, 2026
Faithfully integrate released main and its registry mutation matrix repair. Preserve the dated release text, original contributor history, and the sole microsoft#3211 hook-rendering implementation with credited microsoft#3199 tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f79e464c-180e-4be3-9056-0773aa679a1a
@MohammedAlkindi

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3211, which merged with the regression tests from this PR.

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.

[BUG] APM 0.33.0: apm update fails to integrate Azure Skills because frozen hook metadata is not JSON serializable

3 participants