Skip to content

fix(native): build from verified local base images - #1112

Open
roodboi wants to merge 38 commits into
codex-hd/build-base-resolutionfrom
codex-hd/offline-build-bases
Open

roodboi wants to merge 38 commits into
codex-hd/build-base-resolutionfrom
codex-hd/offline-build-bases

Conversation

@roodboi

@roodboi roodboi commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

HACK-2566. Stacked on #1105 for the foreground and detached registry diagnostics.

A native build selects its base through the existing recorded resolution and observes the verified config in the guest. The stored proof is rechecked for the manifest pin, platform, compressed-size budget, and ONBUILD. The build key includes the selected digest. A fresh loaded base replaces three metadata requests with local proof verification and guest inspection, with zero registry attempts expected.

Each build journals its scoped random alias before tagging. BuildKit gets only that local alias, pointing at the verified config ID. An approved private cache tag keeps the base when the attempt alias is deleted. The per-key lock protects a live or orphaned worker from cleanup. A later build and reclamation can sweep dead attempts. Pull now scans Dockerfile bases and refreshes them with the same verified load used for service images.

The draft exceeds the initial source-line estimate because it includes the alias journal, cross-project recovery, shared pull scan, and model. The review scope is the zero-request build and its lifecycle.

Linux checks passed without Docker on the build host: Rust fmt/Clippy, 1,775 Rust tests, 502 focused Bun tests, typecheck, lint, privacy, Gitleaks, and TLC with 9 states and three intended counterexamples. The earlier isolated classic-worker fixture established the failure on an untagged loaded base and zero requests with a verified local alias. The exact installed Mac worker still needs the rebuild-ten and interruption verification, including the registry-refusal negative control.


Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hack-docs Ready Ready Preview Nov 23, 2026 4:14am UTC

Request Review

roodboi and others added 10 commits November 22, 2026 14:40
`native-project-builds.ts` imported the detached-up module only to report a
base-image fallback, which closed an import cycle with the backend feature
list: importing the builds module first failed with "Cannot access
'NATIVE_BUILD_FIELDS' before initialization". The start path now passes the
reporter in, and uses the name #1082 gave it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi

roodboi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Please review the current head for native build-base policy, recovery, and retention.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T02:31:45.564071Z 53e5546 Manual request
🔒 Security Review ✅ Completed 2026-11-23T02:34:24.209934Z 53e5546 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2729139f27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 10986ac34b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@roodboi

roodboi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Please verify the current head, including the macOS-only lock helper.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 7046ea1ebe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@roodboi

roodboi commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Ready for lead: 7046ea1ebe0f73e9ccf195e48093a875baa2b796 (verified with git ls-remote).

  • Offline can reuse the verified pre-upgrade build on an uncaused tag miss. Refresh still refuses. Normal legacy reuse accepts only rate limits, server errors, unreachable registries, and stalled requests.
  • Reclaim takes the exclusive image fence and retains service image IDs from current tag records and verified immutable references. Service acquisition holds the shared fence through publication.
  • Tag and cache lock waits report after two seconds. Provider and import lease waits are capped at five seconds. Build layer transfers use the remaining build budget.
  • Local evidence: 146 focused runtime image tests passed on the A–D change. The only subsequent change scopes an unused helper to macOS. Final-head Clippy, privacy, and Gitleaks passed. TLC explored five keeper states and the negative control reproduced deletion during pinning.
  • Local Bun before A–D: tests/native-project-builds.test.ts and tests/native-image-tags.test.ts, 43 passed. The follow-up Bun run is queued. Hosted Linux shards are running the suite.
  • The same independent reviewer approved this exact head. Codex code review reported no findings. Review status: CLEAR at 7046ea1ebe.
  • Mac batch, live VM behavior, and Docker last-tag deletion remain unverified. For the VM fixture, use three build FROM digests A, B and C, an unchanged build declaration, and a separate stopped service project whose pulled image is A. After C, reclaim and verify A remains inspectable and the service starts offline with the same config ID. Repeat without the service pull as a disposable last-tag control.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7046ea1ebe

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@roodboi

roodboi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Local verification finished at 7046ea1ebe0f73e9ccf195e48093a875baa2b796. Root typecheck and lint passed. Focused Bun tests passed 555/555 across:

  • tests/native-project-start.test.ts
  • tests/native-detached-up.test.ts
  • tests/native-image-tags.test.ts
  • tests/native-project-builds.test.ts
  • tests/tla-runtime-models.test.ts

The hosted shards cover the full suite.

@roodboi
roodboi marked this pull request as ready for review November 22, 2026 22:35
@roodboi

roodboi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Please review the image fence wait follow-up on the current head.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 02e1e6cd1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@roodboi

roodboi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Ready for lead: 02e1e6cd1dcb706e12ba9cc345d1c8b711441131 (verified with git ls-remote).

Service and build image acquisition wait for the shared fence before taking a provider lease. Contention reports after two seconds and waits up to 60 seconds, bounded by the remaining build budget where applicable. Reclaim skips a busy exclusive fence before taking a provider lease. The immutable service pin lifetime is documented.

Local checks passed: 147 focused Rust image tests, including both fence contention regressions, and 223 Bun tests in tests/native-project-start.test.ts and tests/native-detached-up.test.ts. Privacy and Gitleaks passed. The same independent reviewer approved this exact head. Codex rereview and hosted shards are pending.

The last-tag harness is ready for the Mac/VM batch. It rotates one build through A, B and C, checks A starts offline as a service after reclaim, and has a fresh-pool control without the service pull. The harness passed Bash syntax checking. Live VM behavior remains to be checked.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 02e1e6cd1d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@roodboi

roodboi commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Ready for lead: 0f8c077c92267b1ddd556c696ac34c4b41366fbd (verified with git ls-remote).

Merged #1106 at 15b888d1f7 as the second parent. Concurrent builds keep the shared image fence, share one verified selection per mutable base reference, and drain canceled siblings. Distinct references can acquire independently. Fallback notices deduplicate across the batch.

Local checks passed: root typecheck, 226 Bun tests across tests/native-project-builds.test.ts and tests/native-project-start.test.ts, 148 focused Rust image tests, and privacy. The concurrent regression exercises two builds sharing one base, and the batch tests cover sibling failure and interrupt. Hosted checks and live VM qualification remain open.

@roodboi

roodboi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Ready for lead to review the temp-path fix: f472316d927e85b5f50cc7143778daff1975198b (verified with git ls-remote).

The CLI resolves the new batch directory once after creating it and uses that physical path for every request. The same helper covers build-base scans, normalized preflight and review files, and start/restart dependency selections. The runtime alias check is unchanged. The Bun regression sends two concurrent requests through an aliased TMPDIR and checks their common physical parent. A source regression checks the other native request producers. The Rust test enters the real runtime handler with both spellings.

Root typecheck, 227 Bun build/start tests, 149 focused Rust image tests (3 ignored), focused lint, formatting, and patch gitleaks passed. Hosted checks and a real Mac run remain pending. The cold-start design needs review before this PR returns to the merge batch.

@roodboi

roodboi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Review the cold-start redesign from f472316d927e85b5f50cc7143778daff1975198b to aa27e42cf24e7917321c2acb0d397a81ae827568. Check read-only receipt reuse, immutable cold and local source policy, post-ready scheduling and its lock interaction with incoming starts and stops, and keeper reclaim. The VM timing and keeper rerun are still pending.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa27e42cf2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +90 to +94
let (lease, _) = pool.try_lease()?;
let _fence = idle_retention_fence(candidate)?;
if pins.insert(pin.clone()) {
let (base, _) = select_build_base(candidate, &pin, &policy, None)?;
retain_verified(&pool, &lease, &base, || {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Release the provider lease during background acquisition

When post-ready retention downloads a large or slow base, it retains the provider mutation lease throughout retain_build_image, and subsequently through tag refresh. Nonwaiting acquisition only prevents retention from entering an already-busy pool; it does not yield to starts or stops arriving afterward. On macOS, startup lease acquisition waits only five seconds, while foreground cleanup through Engine::connect_cleanup_wait waits 30 seconds (lifecycle.rs), so this background work can reject another project's start or make Ctrl-C cleanup fail with services still running. The TypeScript timer cleanup also does not cancel an already-running retention request. Stage network acquisition outside the provider lease, then reacquire and recheck ownership for import/tagging, with cancellation or deferral when foreground work arrives.

Useful? React with 👍 / 👎.

) {
let key = key_with_bases(&inputs.key, &bases.selected)?;
let original = std::mem::replace(&mut inputs.key, key);
let reuse = reuse_receipt(candidate, &pool, &inputs, Some(&bases.selected))?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall through to the bounded fence wait when reuse is busy

When another ready project is reclaiming build images, an unchanged build with recorded base selections now fails immediately: reuse_receipt requests a nonblocking shared image fence, and this ? propagates provider_busy while reclamation holds its exclusive fence. The request never reaches wait_for_image_fence below, which previously handled this contention with a bounded wait. Because every ready startup launches best-effort reclamation, ordinary concurrent starts can encounter this without any stop or conflicting build. Treat fence contention as an unavailable fast path and fall through to the existing wait, or use that bounded wait before receipt reuse.

Useful? React with 👍 / 👎.

@roodboi

roodboi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

VM qualification candidate: 53e5546d7535f9dc0c6243d5dcfd4b1d6aa0dee3. This is still #1112, at 5,762 changed lines. It supersedes aa27e42cf. The separate temp-folder fix is included.

Please run one cold start of the same 11-service project against the earlier matched tree. Use the same private-context and overlap changes as the earlier run so the comparison isolates base acquisition. Record the candidate tree SHA, whole-up and build wall times, the three client start times, and any image import or archive acquisition before the clients. Confirm the candidate removes the foreground preload of missing bases. Include normal build verification and the keeper scenario after retention. In a direct runtime-build fixture, call runtime retain-build-bases --json between the build and keeper assertions because no CLI ready owner schedules maintenance in that fixture.

Local checks on the redesign passed: root typecheck, 227 Bun build/start tests, 154 focused Rust tests with default and all features, candidate binary check, scheduling model and both negative controls, privacy, and gitleaks. The worker admits one attempt per pool, takes the provider lease without waiting, and releases it between pins. It may already hold the lease when a new foreground operation arrives. Check contention separately during qualification. No VM measurements are claimed here.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53e5546d75

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/backends/native-project-start.ts Outdated
"--json",
...nativeImagePolicyArgs(),
],
timeoutMs: 30 * 60_000 + 5000,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Admit the retention timeout in the runtime client

After a native build reaches readiness, this call always requests a 1,805,000 ms timeout, but invokeNativeRuntime in src/backends/native-runtime-client.ts permits more than 600,000 ms only for runtime ensure-images. Consequently, every scheduled retain-build-bases request throws E_CONFIG_INVALID before spawning the runtime. The catch below reduces this to a private lifecycle note and returns false, so deferred retries are not scheduled either. Automatic base retention and tag refresh therefore never run, undermining subsequent offline rebuilds after cold solves. Add a command-specific timeout allowance and cover this path through the real runtime-client admission guard rather than only a mocked invoke.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 53e5546d75

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@roodboi

roodboi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Ready for lead: 6d09a7fe89d79b4a8f70f6da94b3601d80f05688 (verified with git ls-remote). The temp-directory fix and the cold-start review fixes are included. The PR changes 5,948 lines.

On a cold miss, Hack resolves the digest and BuildKit fetches the base during the solve. An unchanged build can verify and reuse a local receipt before base acquisition. Retention runs one attempt per pool after readiness, checks for foreground work, stages registry downloads without the provider lease, and logs failures. An already-admitted guest import holds the provider mutation lease until it settles.

Passed root typecheck, 282 focused Bun build/start/runtime-client tests, 155 focused Rust tests each with default and all features, the scheduling model and both negative controls, staged privacy and gitleaks checks, and keeper harness syntax. The commit hook passed with complexity warnings.

VM qualification is pending. Run one cold start on the same 11-service project and rerun keeper protection after retention. For the direct runtime build fixture, invoke runtime retain-build-bases --json before the keeper assertions. The cold timing improvement and keeper behavior on this head still need VM evidence.

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.

1 participant