Skip to content

Fix Go patch delivery, audits, and reinstalls - #1698

Draft
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
fix/go-patch-delivery-e2e
Draft

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
fix/go-patch-delivery-e2e

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

The pgx/v5 smoke test exposed local Go patches that could be attested while Go built vulnerable bytes from native vendor/, a missing warning in agent get, and rollback that stopped building after go mod tidy removed upstream checksums. Reapplying an intact agent patch after deleting the module cache also failed with package_not_installed. The production Go canaries passed without proving delivery.

Changes

  • Verify the native vendor tree Go selects before VEX attestation and in apply --check / vendor --check. Cover workspace markers, quoted and double-hyphen GOFLAGS, unused replacements, package selection, ignored files, embedded assets, and dependency-only patches.
  • Reuse an intact project-local agent copy after module-cache deletion, checking patch hashes, selected version, and replacement wiring. Refuse corrupt copies without deleting them or claiming success.
  • Forward Go consumer synchronization warnings through nested agent operations.
  • Save upstream checksum lines beside local artifacts and restore them on rollback. Refuse checksum conflicts while preserving the active replacement and copy, including orphan reconciliation. Preserve dry-run behavior and checksum backups across mode changes.
  • Replace empty production canaries with the real github.com/jackc/pgx/v5@v5.7.0 patch d8941a4c-4bcd-4756-b0aa-239ec9c81b0f: require a delivery event and reject the malformed decoder input without a panic. Exercise get/scan, fresh caches, cache removal, same-version go get, go mod download/tidy/verify, consumer tests, repeated native vendoring, offline rollback after tidy, and explicit cold-cache agent failure followed by recovery. Hosted/vendored workspace tests also exercise go work sync and go work vendor when supported.

The cold-cache false applied result from the older smoke-test revision was already fixed on current main; this PR adds a live regression guard for the corrected failure behavior.

Validation

  • Real production pgx patch: agent and vendored get/scan/workspace/native-vendor smoke cases passed, including fresh checkouts and rollback after tidy. Live reinstall canaries passed on macOS Go 1.24.13 and 1.26.3 and on Linux ARM64 as UID 1000 with Go 1.21.13, 1.24.13, and 1.26.3. Native-vendor tampering is rejected by audit and VEX in both modes.
  • Controlled hosted pgx delivery passed with a local Go proxy using the real patched artifact, including fresh readonly builds, both file hashes, manifest-free VEX, and wrong-checksum rejection. This is not a production hosted pass.
  • Go E2E suites passed on macOS ARM64 with Go 1.24.13 and 1.26.3 and Linux ARM64 as UID 1000 with Go 1.18.10, 1.21.13, 1.24.13, and 1.26.3 (109 checks per four-suite run; Go 1.18 uses compatible synthetic fixtures because pgx requires Go 1.21). The compatibility workflow is disabled in GitHub, and dispatch was refused; these are local runs, not GitHub compatibility-job passes.
  • Focused core checks, formatting, and the CI-equivalent workspace/all-features Clippy command passed. The final macOS Go 1.26 run passed all 109 checks; the final core run passed 459 unit tests plus the matching integration checks.
  • Draft PR checks are green on 5c4066702 (32 settled checks). Heavy draft-gated jobs were validated locally. Two high-effort Codex CLI reviews were run; confirmed findings were fixed and given regression coverage.

Rollout dependency

Companion backend PR: https://github.com/SocketDev/depscan/pull/28901

Keep this PR in draft until the backend is deployed and the existing legacy pgx patch is regenerated through the existing package-reset/admin workflow. The strict production hosted canary currently fails with redirect_golang_unsupported, because production has not published that patch's /v5 hosted module. It must pass before this PR is ready to merge; do not replace it with an empty-consumer success.

No production deployment or patch regeneration was performed. Existing checkouts created by older CLI releases without a checksum backup may still need go mod download <module>@<version> after rollback; newly patched checkouts restore their saved checksums offline.


Note

High Risk
Changes attestation and CI audit paths for Go patches plus offline rollback/checksum handling; incorrect vendor or sum logic could false-pass or false-fail security verification.

Overview
Go local patches now treat native vendor/ as part of the security boundary: when Go would build from vendored modules, apply --check, vendor --check, and VEX compare that tree to the manifest (including workspace trees, GOFLAGS -mod=, embeds, build constraints, and dependency-only patches) and fail with go_vendor_content_mismatch if runtime bytes drift.

Agent apply can reuse an existing .socket/go-patches/ copy when the module cache is empty, after validating hashes and replace wiring; corrupt copies fail without deleting the tree. Upstream go.sum lines are stored in .upstream-go.sum beside the patch copy, restored on rollback, and checksum conflicts block rollback/reconcile without dropping the active replacement.

Production e2e canaries swap empty Go stubs for a real pgx/v5 v5.7.0 delivery proof (get/scan, native vendor, cold-cache agent, reinstall/tidy/rollback). Docs describe reinstall behavior, checksum backups, and native vendor audits.

Reviewed by Cursor Bugbot for commit 5c40667. Configure here.


Generated by Claude Code

Verify the native vendor tree selected by Go before attesting patches.
Account for workspaces, GOFLAGS, selected packages, embedded assets,
and dependency-only fixes. Forward consumer synchronization warnings
through nested agent get operations.

Preserve upstream checksum lines with local patch artifacts and restore
them on rollback after tidy. Refuse checksum conflicts without removing
an active replacement or its copy, including orphan reconciliation.

Replace empty production Go canaries with pgx/v5 execution proofs for
hosted, vendored, and agent delivery, fresh caches, cold agent failure
and recovery, and rollback. Add real Go regressions for native drift
and the lifecycle failures reproduced by the smoke repository.

Assisted-by: Codex:GPT-6
Reuse verified project-local agent copies after clearing the Go module
cache. Refuse corrupted copies without an upstream rebuild source.
Exercise get, scan, dependency maintenance, repeated native vendoring,
and workspace synchronization with the patched pgx decoder.

Assisted-by: Codex:gpt-6-astra
@mikolalysenko Mikola Lysenko (mikolalysenko) changed the title Fix Go patch audits, rollback, and delivery E2Es Fix Go patch delivery, audits, and reinstalls Oct 23, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Burn-down agent: draft CI is green on 5c406670 (6 passed, 31 skipped/draft-gated; heavy jobs were validated locally per the description). I'm not marking this ready because the description says it must stay a draft until the backend companion SocketDev/depscan#28901 is deployed and the legacy pgx patch is regenerated, and the strict production hosted canary must pass first.

Question for a human: once depscan#28901 is deployed and the pgx /v5 hosted module is published, mark this ready for review (full CI will run then). Until that happens, the burn-down agent will leave this PR alone.


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but none of the reported issues met your autofix severity threshold.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5c40667. Configure here.

}

removed
Ok(removed)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teardown leaves dangling Go replace

Medium Severity

Failed redirect teardown deletes the patched copy first, then calls drop_replace_entry, which now restores checksums and aborts on conflict before removing the replace. That error is ignored, so go.mod can keep pointing at a directory that no longer exists and every subsequent go build fails.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5c40667. Configure here.

}
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backup merges conflicting checksum lines

Medium Severity

save unions live go.sum lines with an existing .upstream-go.sum via reinsert_lines, which treats different h1 values as distinct lines. A later rollback after go mod tidy can write both hashes back, producing an invalid go.sum instead of refusing the conflict.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5c40667. Configure here.

let mut parts = version.split('.');
let major = parts.next()?.parse::<u64>().ok()?;
let minor = parts.next()?.parse::<u64>().ok()?;
(major > 1 || major == 1 && minor >= 14).then_some(dir)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RC go lines skip vendor audit

Low Severity

native_vendor_dir parses the go directive with u64 on each dotted field. A valid line such as go 1.21rc1 fails that parse, so the function returns None and VEX plus --check skip native vendor/ verification while Go still auto-selects that tree.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5c40667. Configure here.

Resolve conflicts with main's advisory-warning refactor (#1722) and the
global Go tool tests (#1717). apply.rs keeps main's advisory_warning_codes
loop (it covers ownership_not_restored too) and drops main's
nested_skip_warnings, because this branch already reports those skips
through run_warnings. e2e_golang_build.rs keeps both sides' new tests.

Co-Authored-By: Claude <noreply@anthropic.com>
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Burn-down agent: merged origin/main (8b32765) into this branch at e3eb1e0 to clear the merge conflict.

  • apply.rs: kept main's advisory_warning_codes loop (Fix stale Python bytecode after apply (#819) #1722), which also emits ownership_not_restored, and dropped main's nested_skip_warnings, since this branch already reports nested user-patch skips through run_warnings.
  • tests/e2e_golang_build.rs: kept both sides' new tests (this branch's rollback/vendor tests and main's global-tool tests from Fix global Go apply leaving installed tools stale (#422) #1717).
  • Local: cargo check -p socket-patch-cli --all-targets clean; cargo test -p socket-patch-cli --lib 934 passed; --test e2e_golang_build 33 passed (Go 1.24).

Draft hold and agent:needs-human unchanged; awaiting CI on the new head.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants