|
| 1 | +[agent] 2026-12-04: architecture refactor |
| 2 | + |
| 3 | +**`main`:** cd7c5c5 (unchanged since the last entry). The run started at 22:55Z. |
| 4 | + |
| 5 | +### Chosen |
| 6 | +No PR this run. Three routine PRs were open at the start and at 23:28Z: #2453, #2458 and #2461, each `ready`, none updated since 12-02. No maintainer has commented on the discussion. With three open, step 3 applied: open none, verify leads. |
| 7 | + |
| 8 | +No lead was marked `to verify`, and the only `arch-audit` issues changed since the last sweep were this routine's own #2513 and #2516. So the run took an area no entry names: the two readers of a Gemfile's `gem` calls, against Bundler. Hosted mode appends an option to the user's declaration (`formats/gem/declarations.rs`); vendored mode rewrites the line (`plan_gemfile_edit` in `vendor/gem.rs`). Both are ports of what Ruby and Bundler read, and neither had been compared with Bundler over generated input. |
| 9 | + |
| 10 | +| What | How | Result | |
| 11 | +|---|---|---| |
| 12 | +| The hosted rewrite of a declaration | 13,300 generated Gemfiles through `rewrite_registry_redirect`; Bundler 4.0.18 and 2.5.22 (`Bundler::Dsl`, the frozen check) on each input and output | **an option whose value is an `if` or `unless` expression is split: the Gemfile no longer parses: filed #2517** (L216). The other 10,084 rewrites are right (L219) | |
| 13 | +| The same through the binary | the hosted gem capstone with one line changed, real Bundler 4.0.18 | `success`, `applied: 1`, then `bundle install` fails on a syntax error; `rollback` restores the pair | |
| 14 | +| The vendored rewrite of a declaration | 4,000 generated Gemfiles through `plan_gemfile_edit`; `Bundler::Dsl` on each input and output; 13 hand-written lines through both modes | **a trailing options Hash (`{ require: false }`, `OPTS`) is dropped as a version requirement: filed #2518** (L217) | |
| 15 | +| The same through the binary | a test added to the vendored gem capstone, real Bundler 4.0.18, `Bundler.require` before and after | `success`, `applied: 1`; rack is then loaded at boot and in the default group | |
| 16 | +| A `gem` line inside a `=begin` block, a heredoc or after `__END__` | the vendored planner; the binary on a `=begin` block | **the planner takes it for the declaration; through the binary a `=begin` block: `success`, the comment edited, the lock given a dependency the Gemfile lacks, and a frozen install fails: a section of #2518** (L218) | |
| 17 | +| A second hosted run over its own output | 4,581 rewritten pairs | none changed (L220) | |
| 18 | + |
| 19 | +### PR |
| 20 | +None opened. #2453, #2458 and #2461 await review. No code was pushed anywhere. |
| 21 | + |
| 22 | +### Leads and issues |
| 23 | + |
| 24 | +**L216, confirmed, filed #2517 (`bug`): a hosted scan splits a `gem` option whose value is an `if` or `unless` expression, and the Gemfile no longer parses.** To find the end of a declaration's arguments the reader stops at a trailing `if`, `unless`, `while`, `until` or `rescue`, which it takes for a statement modifier. In `gem "rack", "2.2.3", require: if ENV["X"] then "rack/x" else "rack" end` the `if` is the option's value. The reader ends the arguments after `require:` and the option lands between the key and its value: `require:, source: "…" if ENV["X"] then …`. |
| 25 | + |
| 26 | +Through the binary (the capstone `gem_hosted_conditional_declaration_redirects_in_place_and_installs` with its Gemfile line changed to `gem "vuln-gem", require: if ENV["WITH_VULN"] != "0" then "vuln_gem" else false end`, Bundler 4.0.18): the scan exits 0 with `status: success` and `applied: 1`; `bundle install` then fails with "There was an error parsing `Gemfile`: syntax error, unexpected `then'". `rollback pkg:gem/vuln-gem@1.0.0` exits 0 and restores the Gemfile and the lock byte for byte. |
| 27 | + |
| 28 | +Six hand-written spellings break (`key: if`, `key: unless`, `:key => if`, `platforms: if`, the `if` body on lines of its own, the option on a continuation line). The parenthesized value, the ternary and a real modifier are right. The positional form (`gem "rack", if … end`), `case` and `begin` are refused today. |
| 29 | + |
| 30 | +In 13,300 generated Gemfiles, 10,160 were rewritten and 3,140 refused. 76 of the rewritten ones no longer parse, all with an `if` expression as an option value. A unit test beside the reader fails on `main` with the four split declarations in its message. |
| 31 | + |
| 32 | +It is the third kind (a broken project after `success`) and the fifth: #340 was this class, and the reader that replaced its fix (#2052) tells a modifier from a hash label, refuses the positional `if` and refuses a line that ends on a label. The value position on the same line was left out. `complete` is true once the argument has any text, so `require:` counts as complete. |
| 33 | + |
| 34 | +A trial build of the plan (21 lines in `declarations.rs`: a modifier word after a label, a `=>` or an operator starts a value, so the declaration is refused): in three of the batches again (13,000 Gemfiles) and the hand-written rows no result fails to parse; 79 results go from rewritten to refused, each an `if`-expression declaration; 6 keep a refusal under this code; nothing else changes. The unit test passes, and so do the 718 other tests of the core crate with `gem` in their name. Checked out again after. |
| 35 | + |
| 36 | +**L217, confirmed, filed #2518 (`bug`): `vendor` drops a declaration's options when they are a Hash, and says `success`.** The vendored rewrite keeps what it reads as keyword arguments (`key:`, `"key":`, `=>`, `**opts`) and drops every other argument as a version requirement the exact pin supersedes (#847). Bundler takes a trailing Hash as the options. So `gem "rack", "~> 3.1", { require: false }` and `OPTS = { require: false, group: :web }` with `gem "rack", "~> 3.1", OPTS` both become `gem "rack", "3.2.9", path: "…"`. |
| 37 | + |
| 38 | +Through the binary (a test on the capstone's `staged_rack_project`, Bundler 4.0.18, a frozen install after `vendor`, then `Bundler.require`): |
| 39 | + |
| 40 | +| Line | `vendor` | rack loaded by `Bundler.require`: before → after | Group: before → after | |
| 41 | +|---|---|---|---| |
| 42 | +| `gem "rack", "~> 3.1", { require: false }` | exit 0, `success`, `applied: 1` | no → **yes** | default → default | |
| 43 | +| `gem "rack", "~> 3.1", OPTS` | exit 0, `success`, `applied: 1` | no → **yes** | `web` → **default** | |
| 44 | +| `gem "rack", "~> 3.1", require: false` (control) | exit 0, `success`, `applied: 1` | no → no | default → default | |
| 45 | + |
| 46 | +The frozen install passes in every row, so nothing fails. `vendor --revert` exits 0 and restores the Gemfile byte for byte in each. |
| 47 | + |
| 48 | +Thirteen hand-written lines through both modes: the vendored planner drops the hash in eight (a `{ … }` literal with `require`, `platforms` or `group`; a constant; a local variable), and hosted mode refuses all eight. A `{ platforms: :jruby }` dropped makes the gem a dependency on MRI, where Bundler skipped it. In 4,000 generated Gemfiles, 27 of the 696 in-place rewrites lost options. |
| 49 | + |
| 50 | +It is the first kind: two readers split one `gem` call into requirements and options. The hosted one (#2052) knows a trailing hash, or a last argument it cannot read, may be the options (`ArgKind::Dynamic`, `opaque_last`, and the count of requirements in the lock's entry). The vendored one (#849) does not. A comment in the vendored code says a hash literal is kept after `path:`; only the splat is. The contract's "Gem rewrite." paragraph says any option is kept verbatim. And hosted mode's refusal of the `{ … }` line names `--mode vendored` as the way out. |
| 51 | + |
| 52 | +The plan on the issue: read the declaration with the hosted reader before a rewrite in place, and refuse (`gemfile_declaration_not_editable`) a `{ … }` literal as the last argument, or a last positional the lock does not show as a requirement. Not tried on a build. |
| 53 | + |
| 54 | +**L218, confirmed, a section of #2518: `vendor` rewrites a `gem` line that is not code.** The vendored planner reads line by line and skips only lines that start with `#`; the hosted reader works on a copy with comments, strings and heredoc bodies blanked. A Gemfile with `=begin`, `gem "rack", "~> 3.1"`, `=end` and `gem "rack-test"` (rack 3.2.9 its dependency), through the binary: `vendor` exits 0 with `success` and `applied: 1`, the line inside the comment becomes `gem "rack", "3.2.9", path: "…"`, and the lock gains a `PATH` section and `rack (= 3.2.9)!` under `DEPENDENCIES`. `BUNDLE_FROZEN=true bundle install` then fails ("You have deleted from the Gemfile: * rack (= 3.2.9)"), and `vendor --check` exits 1 with `vendor_check_failed` ("wiring missing … re-run `socket-patch vendor` to rewire it") straight after the successful run. In the 4,000 generated Gemfiles the planner rewrote such a line in 230 (a `=begin` block, a heredoc body, a line after `__END__`): 179 where the gem is not declared, 51 where its declaration is one the line grammar does not read. It takes a block comment that holds a top-level `gem` line for the patched gem, so it sits in #2518 and not in an issue of its own; the plan there (find the declaration with the hosted reader) covers it. |
| 55 | + |
| 56 | +**L219, rejected: the hosted rewrite changes what a Gemfile means in some other way.** With L216 set aside: 10,084 rewrites, each loaded by `Bundler::Dsl` before and after. Every other dependency reads the same (requirement, source, groups, platforms, `autorequire`), the patched gem has the Socket index as its one source, and Bundler's frozen check accepts the output pair wherever it accepted the input pair. The declarations covered parentheses, continuation lines with comments and `\`, modifiers, `;`, one-line `do … end` and `{ … }` blocks, seventeen enclosing places, CRLF, and decoys in comments, strings, a regex and heredocs. A gem the Gemfile does not declare got its one added line (1,914 of 2,130), or a refusal when the file ends in an `__END__` section (216, `redirect_gem_inconsistent_plan`). |
| 57 | + |
| 58 | +**L220, rejected: a second hosted run rewrites its own output.** 4,581 rewritten pairs run again: none changed. |
| 59 | + |
| 60 | +**Seen and not filed:** |
| 61 | +- The hosted reader refuses more than it must: `gem "rack", "~> 2.2", **OPTS`, an option value with an interpolation that nests quotes, a one-line `group :test do gem "rack" end`. Each is a refusal with a remedy, and nothing is written. |
| 62 | +- Vendored mode refuses every `if` it sees on the line as a modifier, the value form included. |
| 63 | + |
| 64 | +No issue closed. No lead is marked `to verify`. |
| 65 | + |
| 66 | +### Areas examined |
| 67 | +- **The hosted Gemfile declaration reader against Bundler**: L216, L219, L220. |
| 68 | +- **The vendored Gemfile rewrite against Bundler**, and against the hosted reader on the same lines: L217, L218. |
| 69 | +- **Both through the binary** with real Bundler 4.0.18: #2517, #2518. |
| 70 | +- Read: `formats/gem/declarations.rs` (the argument scan, `MODIFIERS`, `BREAKERS`, `opaque_last`), `formats/gem/gemfile.rs` (`trailing_options`, `inert_positionals`), `vendor/gem.rs` (`plan_gemfile_edit`, `split_kept_tail`, `rest_blocks_edit`, `apply_gemfile_plan`, `refuse_append_of_direct_dependency`), `patch/redirect/mod.rs` (`plan_gem_redirect`: the options-hash rule and its refusals), `tests/e2e_redirect_gem_build.rs` (the drivers, `redirect_scanned_project`), `tests/e2e_vendor_gem_build.rs` (`staged_rack_project`, the #847 capstone), `tests/redirect_golden.rs`, the contract's "Gem hosted wiring" and "Gem rewrite." paragraphs, #340 and #847. |
| 71 | +- Not run: the hosted unwind over the generated rewrites (one capstone row only); `gems.rb`; `get <uuid>` in either mode; Bundler 1.17 to 2.4 and 2.6 to 2.7; a Gemfile with `eval_gemfile`, a `gemspec` directive or two top-level sources in the generator; the vendored lock edit (the probe ran the Gemfile planner alone); a trial build of #2518's plan; the Gemfile `source` reader (`rubygems_sources`, `top_level_source_count`) against Bundler; the NuGet strong-name and Authenticode advisory (`patch/sidecars/nuget_signing.rs`, never run under this charter); Windows and macOS. |
| 72 | + |
| 73 | +### Lessons |
| 74 | +- **A rewriter of a programming language's file wants a generator and the language's own reader.** The capstones pin about thirty declaration forms by hand. A seeded generator and `Bundler::Dsl` gave 13,300 in a minute, and the one broken class was a spelling no one had written down. |
| 75 | +- **Ask the tool what the result means, not whether it loads.** The vendored rewrite passes every frozen install. Only the dependency's `autorequire`, groups and platforms, read back from Bundler, showed the options were gone. |
| 76 | +- **Run one input through both modes.** The hosted refusal ("it may be an options hash") was the specification the vendored copy lacked. |
| 77 | +- **Follow the remedy across modes.** A hosted refusal that names `--mode vendored` sends its input to the other reader. |
| 78 | +- **A public rewriter runs from an example.** `rewrite_registry_redirect` is `pub`: an example in the core crate builds in a minute after a CLI build and needs no test build. `DepOverride` reads from JSON in the golden fixtures' shape. |
| 79 | +- **Bundler's frozen check runs without a network.** `Bundler::Definition.build(gemfile, lock, nil).ensure_equivalent_gemfile_and_lockfile(true)` under `BUNDLE_FROZEN=true`, in one process for a whole batch, after `Bundler.reset!` and `BUNDLE_GEMFILE`. A lock template with `DEPENDENCIES` from `Bundler::Dependency#to_lock` passes it. |
| 80 | +- **Check the oracle on a known pair first.** The golden fixture's input and expected pairs both passed before any generated case ran. The first batch still raised 36 false alarms (a gem the rewrite adds is a new dependency by design). |
| 81 | +- The register: #2517 and #2518 joined Next PR after #2516, L216 to L220 their rows, "Gemfile readers" the Areas row, one note a sentence; three sentences of the notes went to make room (11,990 characters). |
| 82 | +- The run, roughly: loading state and the first build 6 minutes; choosing an area 5; the probes, the generator and the oracle 6; the batches 4; the two capstone rows 6; the unit tests and the trial build 7; the issues 4; the ledger the rest. |
| 83 | + |
| 84 | +<details><summary>The fixtures</summary> |
| 85 | + |
| 86 | +**The rewriter probes.** `crates/socket-patch-core/examples/<name>.rs`, removed after. One reads each case directory (`Gemfile`, `Gemfile.lock`, `overrides.json` with one `rubygems-compact-index` override for `rack` 2.2.3), calls `rewrite_registry_redirect`, and writes the pair as the run leaves it and the warnings. The other calls `plan_gemfile_edit`, `refuse_append_of_direct_dependency` and `apply_gemfile_plan` (four items made `pub` in the working tree for the build, checked out again before any binary evidence). |
| 87 | + |
| 88 | +**The generator** (Ruby, seeded). A `source` line in five spellings; constants a declaration may use; zero to two decoys (a commented `gem "rack"` line, a `=begin` block, two heredocs, a regex, `%q{…}`, a string); `rack`, `rake` and `puma` in random order. Each declaration: the name in nine spellings, zero to two requirements in twenty, options in about thirty, commas with or without line breaks, comments and `\`, a call with or without parentheses, a dozen endings, and one of seventeen places. CRLF in one file of twelve. Fifteen in a hundred leave `rack` undeclared, with `puma` depending on it in the lock. `TOP_ONLY=1` keeps 85 in 100 declarations at top level (the vendored batch); `CHECKSUMS=1` writes the lock with a `CHECKSUMS` section and `BUNDLED WITH 2.6.2`. |
| 89 | + |
| 90 | +**The lock.** A template (`GEM` with the three specs, `PLATFORMS`, `BUNDLED WITH`) whose `DEPENDENCIES` are `Bundler::Dependency#to_lock` of what `Bundler::Dsl#eval_gemfile` reads, sorted, one line per name. A Gemfile Bundler does not load is dropped. |
| 91 | + |
| 92 | +**The oracle.** One Ruby process per batch (`gem "bundler", "<version>"` first). For the input and the output: `Bundler::Dsl#eval_gemfile`, then each dependency's name, requirement, source remotes, groups, platforms, `autorequire` and `should_include?`. Hosted: the others equal, the patched gem on the Socket index, and the frozen check on both pairs (an input pair it turns down is skipped). Vendored: the others equal, the patched gem once, on the vendored path, at `= 2.2.3`, its groups, platforms and `autorequire` as before. |
| 93 | + |
| 94 | +**The batches.** Hosted: 300 (seed 1) and 4,000 (seed 2) under Bundler 4.0.18, 6,000 (seed 3) under 2.5.22, 3,000 (seed 4, `CHECKSUMS`) under 4.0.18. Vendored: 4,000 (seed 11, `TOP_ONLY`, a fifth undeclared) under 4.0.18. |
| 95 | + |
| 96 | +**The capstone rows.** Hosted: the Gemfile of `Driver::ScanVexConditionalDeclaration` changed in `tests/e2e_redirect_gem_build.rs`, and before the fixture compares the Gemfile it prints the envelope, runs `bundle install` and the suite's `rollback`. Vendored: a test appended to `tests/e2e_vendor_gem_build.rs` over three Gemfiles (its text is in #2518's fixtures). Both run with `-- --ignored <name>`; both files were checked out again after. |
| 97 | + |
| 98 | +</details> |
| 99 | + |
| 100 | +### Needs a person |
| 101 | +- **#2517 is new.** A hosted scan over a Gemfile whose patched gem has an option with an `if` or `unless` expression as its value (`require: if … end`) says `success` and leaves a Gemfile that does not parse; `rollback` restores it. The fix is small and was tried on a build. |
| 102 | +- **#2518 is new.** `vendor` over `gem "rack", "~> 3.1", { require: false }` or `gem "rack", "~> 3.1", OPTS` says `success` and drops the options: the gem is then loaded at boot, in the default group, on every platform. Hosted mode refuses the same lines and names vendored mode as the way out. The issue also holds a rarer case (a `gem` line inside a `=begin` block is rewritten, and a frozen install fails). It says which fix is planned (refuse, as hosted mode does) and which it leaves to a word from a maintainer (keep the hash as a splat). |
| 103 | +- **Review #2461** (a printed credential, p1), **#2458** (Go workspaces under a named `GOWORK`) and **#2453** (vendored NuGet). Nothing else of this routine's can open until one merges. |
| 104 | +- From earlier runs, unchanged: #2516 (a uv workspace member inside another member); #2513 (a hosted scan of a single pom whose plugin configuration holds a `<build>` or `<profiles>`); #2512 (a precompiled gem under two records); #2509 (Hatch members through a context field); #2510 (a crate below a member with `package.workspace`); #2507 (Cargo members in a directory named `target`); #2505 and #2506 (workspace membership under pnpm, npm and Yarn 1); #2504 (a requirement pinned by a `-c` constraints file); #2503 (a requirements pin dropped by its comment's spelling); #2501 (a two-package NuGet undo leaves the source mapping); #2498 and its comment; #2383's comment; #2496 (a decision: hosted mode on Yarn Plug'n'Play); #2494; #2490 and #2489; #2486 and #2487; #2477; #2480 and #2475 ask for a decision; #2474; #2472; #2467 and #2469 each ask for a word; #2465 is not reachable until the patch service sends `mode` entries; #2348 is unclaimed for Cargo, Go and Composer; the contract sentences for #2453 and #2458 wait for #2459; #2450 and #2413's second point want a word; #2455 wants a word on the warning code; #2366, #2347, #2340, #2309, #2277 and #2297 wait for an answer. |
0 commit comments