core+agents: JIT bundle resolution stage 1 — R03 flips - #440
Merged
Conversation
Imageless JIT-compiled classes get their Bundle(for:) redirected to the target's built framework wrapper. The hook lives in each agent binary (BundleRedirect objc_library on macOS, AgentApp.swift mirror on iOS) because bridge generations can be torn down while the swizzled IMP must outlive them; the bridge calls previewsmcp_set_resource_wrapper via dlsym before each render, installing once per process and refreshing the path. The wrapper rides BuildContext.resourceWrapperPath from CODESIGNING_FOLDER_PATH on both Xcode capture paths; SwiftPM and Bazel stay nil so the hook never installs there. The stage-opening diagnostic (probe preview through the real JIT) decided the predicate: ORC-materialized classes report class_getImageName == NULL with Bundle(for:) falling back to the agent's main bundle, so the hook redirects exactly that combination. Manual matrix: R03 flips on macOS and iOS (localized title, plist, Core Data model, generated color); R02 stays Spanish with the hook code present; B04's real-image framework class keeps its own wrapper. Unit rows pin the hook decision table (BundleRedirectTests) and the generator emission (BridgeGeneratorRedirectTests); the iOS agent builder hash is re-pinned. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stage 1 of
docs/jit-bundle-resolution.md: imageless JIT-compiled classes get theirBundle(for:)redirected to the target's built framework wrapper, closing R03's resource half (the last row of the dissolved resource-staging cluster).BundleRedirectobjc_library on macOS (alwayslink, ARC-verified via aquery) and a keep-in-sync Swift mirror in the iOS agent app — because bridge generations can be torn down while the swizzled IMP must outlive them.@_silgen_name(theset_preview_vcprecedent) and calls it before setup and before every render, unconditionally: a nil wrapper emits a clearing call, so an agent surviving a mid-session build-system identity flip cannot keep a stale path.BuildContext.resourceWrapperPathfromCODESIGNING_FOLDER_PATHon both Xcode capture paths; SwiftPM and Bazel stay nil so the hook never installs there.class_getImageName == NULLwithBundle(for:)falling back to the agent's main bundle — the hook redirects exactly that combination.Verification
BundleRedirectTestspins the hook decision table (redirect, real-class passthrough, replace, missing-path fallback, clear);BridgeGeneratorRedirectTestspins emission (set call before the view, clearing call on nil, setup-entry ordering, escaping). iOS agent builder hash re-pinned.Xcode resources loaded, plist, Core Data model, and the generated color on macOS and iOS; R02 stays Spanish with the hook code present (inert on SPM); B04's real-image framework class keeps its own wrapper.@_silgen_nameover dlsym, nil-clearing call, setup-entry ordering, iOS nil-class guard, doc placement); both local tiers + manualRegressToolGuardTestsgreen; lint exit 0.Follow-ups (in the design doc)
Stage 2 retires the
Generated*Symbols.swifttext rewrite once the hook's record is clean; stage 3 adds R03's macOS half toRegressGuardTests. Known accepted behaviors documented: runtime-generated imageless classes (KVO subclasses) over-redirect harmlessly; Xcode-embedded resource-bearing SwiftPM packages need their own matrix row before that combination ships.🤖 Generated with Claude Code