Repository navigation
Description
[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L111) while running an agent-mode patch through a real Composer project. Run on main at cfc870f with the binary built from it, Composer 2.8.12, PHP 8.3.6 and psr/log 3.0.0, against a stand-in patch API.
Problem
Agent mode patches a Composer package in place under vendor/ and then does nothing else. Composer is the one in-place ecosystem with no arm in dispatch_fixup_with (core patch/sidecars/mod.rs, lines 187 to 215: Cargo and NuGet get a fixup, PyPI, RubyGems and Go an advisory, Maven both, Composer falls to _ => None on line 214). Two things Composer keeps beside the package then disagree with the patched files, and nothing in the run's output says so:
- An authoritative classmap does not know a class the patch adds.
composer install --classmap-authoritative(orcomposer dump-autoload -a, or"classmap-authoritative": trueinconfig) writes every class tovendor/composer/autoload_classmap.phpand tells the loader to look nowhere else. A patch that adds a class file (a record whose file has an emptybeforeHash, which the contract describes) is written to disk, the patched code that uses the class runs, and PHP stops withClass "…" not found.applyexits 0 with no warning,apply --checksays the patches are in sync, andvexattestsnot_affected. - A source install is left with uncommitted changes. When Composer installed the package as a git checkout (
--prefer-source,preferred-install: source, or its own fallback when the dist download fails, which happened in this sandbox on the first install:Failed to download psr/log from dist: Could not authenticate against github.com. Now trying to download from source), the patched file is a modified tracked file. The next non-interactive Composer command that has to update or remove that package exits 1 withSource directory vendor/psr/log has uncommitted changes.
Who it hurts:
- A PHP team that deploys with an authoritative classmap (Composer's "optimization level 2/A", which Symfony's performance guide recommends for production) and follows the scan's own next step,
Run \socket-patch apply` after every `composer install``. The image builds, every socket-patch check is green, and the request that reaches the patched code path gets a fatal error. In PHP a new class is a new file, so a fix that adds an exception or a validator class is this shape. - A developer or a CI job with a kept
vendor/whose package is a source install: after a lock bump (a teammate's upgrade, or the upgrade to the fixed release itself)composer install --no-interactionfails until someone runssocket-patch rollbackor discards the changes by hand. The message names the directory, not socket-patch.
The same class of problem has been fixed for the other in-place ecosystems, one at a time: stale Python bytecode (77683cc, #1722), Cargo's fingerprints and checksum file (7306ec6, #1307), a gem's compiled extension (7bde3ba, #1998). The word classmap appears nowhere in the source, CLI_CONTRACT.md or docs/; docs/ecosystems.md (line 30) lists Composer's agent mode as "in place (vendor/)" with no limit.
Evidence
A project that requires psr/log 3.0.0 and an app.php that calls (new Psr\Log\NullLogger())->info('hello') and prints app ok. The patch changes src/NullLogger.php to call SocketGuard::check($message) and adds src/SocketGuard.php (the class prints guard ran).
1. The classmap, in the order the next steps give for CI:
$ socket-patch scan --mode agent --yes
Applied 1 patch.
HIGH psr/log@3.0.0 CVE-2026-0001
Next steps:
1. Commit .socket/ to keep the patches.
2. Run `socket-patch apply` after every `composer install`, locally and in CI. A fresh install removes the patches.
$ rm -rf vendor && composer install --no-dev --classmap-authoritative --no-interaction
- Installing psr/log (3.0.0): Extracting archive
Generating optimized autoload files
$ socket-patch apply; echo "exit $?"
Patched packages:
pkg:composer/psr/log@3.0.0 (via blob)
Summary: 1 of 1 targeted patch applied, 0 already patched, 0 not found on disk
exit 0
$ socket-patch apply --check; echo "exit $?"
Patches are in sync (1 patch checked).
exit 0
$ php app.php; echo "exit $?"
PHP Fatal error: Uncaught Error: Class "Psr\Log\SocketGuard" not found in vendor/psr/log/src/NullLogger.php:28
exit 255
$ socket-patch vex --product pkg:composer/acme/app@1.0.0 -O - | jq -c '.statements[] | [.vulnerability.name, .status, .justification]'
["GHSA-aaaa-bbbb-0001","not_affected","inline_mitigations_already_exist"]
$ socket-patch apply --json | jq -c '[.status, .warnings]'
["success",null]
The same scan over the same project, by how the autoloader was written before it:
composer dump-autoload … |
scan | apply --check |
php app.php |
|---|---|---|---|
| (plain) | exit 0 | exit 0 | guard ran, app ok |
-o |
exit 0 | exit 0 | guard ran, app ok |
--apcu |
exit 0 | exit 0 | guard ran, app ok |
-a |
exit 0 | exit 0 | Class "Psr\Log\SocketGuard" not found, exit 255 |
After composer dump-autoload -a the -a row prints guard ran, and after socket-patch rollback it prints app ok again. An authoritative install leaves a line a run can read: $loader->setClassMapAuthoritative(true); in vendor/composer/autoload_real.php.
2. The source install, with a patch that only changes src/NullLogger.php:
$ ls -d vendor/psr/log/.git
vendor/psr/log/.git
$ socket-patch scan --mode agent --yes --json | jq -c '[.status, .warnings]'
["success",null]
$ git -C vendor/psr/log status --short
M src/NullLogger.php
$ # composer.lock now names psr/log 3.0.2 (a teammate's upgrade)
$ composer install --no-interaction; echo "exit $?"
Package operations: 0 installs, 1 update, 0 removals
- Syncing psr/log (3.0.2) into cache
In VcsDownloader.php line 268:
Source directory vendor/psr/log has uncommitted changes.
exit 1
$ socket-patch rollback --yes && composer install --no-interaction; echo "exit $?"
- Upgrading psr/log (3.0.0 => 3.0.2): Checking out f16e1d5863 from cache
exit 0
Paths are shortened to the project. composer update psr/log --no-interaction fails the same way. Composer looks at tracked files only: the same update over a checkout that holds one untracked file and no change succeeds, so a file a patch adds does not count and a file it changes does.
Not run: Composer 1, a classmap-autoloaded package (as against PSR-4), a patch that removes a class file, --apcu-autoloader with a warm APCu, and the interactive prompt Composer shows a developer (it offers to discard or stash the changes).
Planned fix
Give Composer its arm in the sidecar dispatch, next to the advisory-only ones, with no change to exit codes or status (the contract calls new warning codes additive):
- After an apply or a rollback that added or removed a
.phpfile of a Composer package, readvendor/composer/autoload_real.phpof the vendor directory the package was found in. When it sets the classmap authoritative, raise a warning that names the classes' files and the command that brings the classmap in line (composer dump-autoload --classmap-authoritative, with--no-devwheninstalled.phpsays the install was one). - When the package directory is a git checkout (
installation-sourceissourceininstalled.json, or it holds.git), raise an advisory at apply time that Composer will refuse to update the package non-interactively while it is patched, and thatsocket-patch rollbackbefore the update clears it.
Two things a maintainer may want beyond the warning, which it does not need: for the first case, refusing such a patch under an authoritative classmap ("when a patch can't be applied safely it skips with a clear message") or writing the classmap entries directly; and whether apply --check and vex should hold back until the classmap lists the added file.
Generated by Claude Code
Activity
refactor: #2387 filed; Composer agent mode ran