Skip to content

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

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

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.

This branch has not been deployed

No deployments
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

2 participants