Skip to content

Conversation

@p1-0tr
Copy link

@p1-0tr p1-0tr commented Sep 5, 2025

Not decided yet if this is the best way to handle the issue. But this fixes sandboxing for local (dev) builds of DMR.

Summary by Sourcery

Introduce a configurable resource path for sandboxed processes by adding an updatedBinPath parameter to sandbox creation across all platforms, replacing hard-coded Docker inference paths with [UPDATEDBINPATH] and [UPDATEDLIBPATH] placeholders, and propagating the new path into the llamacpp backend run command.

New Features:

  • Add updatedBinPath argument to Create functions in sandbox implementations for Darwin, Windows, and other platforms
  • Replace hard-coded Docker inference subpaths with [UPDATEDBINPATH] and [UPDATEDLIBPATH] placeholders in sandbox profiles
  • Pass the configured updatedServerStoragePath into the llamacpp backend Run invocation

Tests:

  • Update sandbox tests to supply a sample updatedBinPath to the Create function

@p1-0tr p1-0tr force-pushed the ps-updated-resources-in-sandbox branch from 4db1ae5 to 8565b96 Compare September 5, 2025 11:36
@p1-0tr p1-0tr marked this pull request as ready for review September 23, 2025 07:33
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 23, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enable configurable sandbox resource paths by extending Create() to accept an updatedBinPath, replacing hardcoded subpaths with placeholders ([UPDATEDBINPATH] and [UPDATEDLIBPATH]), and propagating the new parameter to tests and the llamaCpp backend.

File-Level Changes

Change Details Files
Extend sandbox.Create signature to accept updatedBinPath and update callers
  • Added updatedBinPath parameter to Create() in Darwin, generic, and Windows implementations
  • Adjusted test Create() calls to include the updatedBinPath argument
pkg/sandbox/sandbox_darwin.go
pkg/sandbox/sandbox_other.go
pkg/sandbox/sandbox_windows.go
pkg/sandbox/sandbox_test.go
Replace static Docker subpaths with template placeholders and implement substitution
  • Replaced hardcoded subpath entries with [UPDATEDBINPATH] and [UPDATEDLIBPATH] in ConfigurationLlamaCpp
  • Added ReplaceAll calls to substitute [UPDATEDBINPATH] and derive [UPDATEDLIBPATH] via filepath.Join
  • Imported path/filepath for computing the lib path
pkg/sandbox/sandbox_darwin.go
Propagate new updated path into llamaCpp backend Run invocation
  • Inserted l.updatedServerStoragePath as an argument in the sandbox.Run call
pkg/inference/backends/llamacpp/llamacpp.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Ensure every invocation of Create is updated to supply the new updatedBinPath argument so you don’t introduce build or runtime errors from missing parameters.
  • Validate or guard against empty updatedBinPath before deriving UPDATEDLIBPATH, since filepath.Dir("") yields “.” and could result in unintended sandbox paths.
  • Consider refactoring the expanded Create signature into a configuration struct or builder pattern to keep the API clear as more path parameters get added.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Ensure every invocation of Create is updated to supply the new updatedBinPath argument so you don’t introduce build or runtime errors from missing parameters.
- Validate or guard against empty updatedBinPath before deriving UPDATEDLIBPATH, since filepath.Dir("") yields “.” and could result in unintended sandbox paths.
- Consider refactoring the expanded Create signature into a configuration struct or builder pattern to keep the API clear as more path parameters get added.

## Individual Comments

### Comment 1
<location> `pkg/sandbox/sandbox_other.go:39` </location>
<code_context>
 // function allows for an optional callback (which may be nil) to configure the
 // command before it is started.
-func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
+func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
 	// Look up the user's home directory.
 	currentUser, err := user.Current()
</code_context>

<issue_to_address>
**suggestion:** updatedBinPath parameter is unused in this implementation.

If updatedBinPath is included for cross-platform consistency, please document this in the code. Otherwise, consider removing it to avoid confusion.

```suggestion
/*
updatedBinPath is included for cross-platform consistency with other platform-specific implementations.
It may not be used in this implementation, but is retained to keep the function signature uniform.
*/
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
```
</issue_to_address>

### Comment 2
<location> `pkg/sandbox/sandbox_windows.go:68` </location>
<code_context>
 // function allows for an optional callback (which may be nil) to configure the
 // command before it is started.
-func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
+func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
 	// Look up the user's home directory.
 	currentUser, err := user.Current()
</code_context>

<issue_to_address>
**suggestion:** updatedBinPath parameter is unused in this implementation.

If updatedBinPath is included only for interface consistency, please document this or refactor to prevent confusion.

Suggested implementation:

```golang
/*
Create initializes a new Sandbox instance.

configuration: Pre-defined configuration value.
modifier: Optional callback to configure the command before it is started (may be nil).
updatedBinPath: Included for interface consistency with other platforms; currently unused in this implementation.
name: Name of the command to execute.
arg: Arguments to pass to the command.
*/
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {

```

```golang
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
	// updatedBinPath is intentionally unused in this implementation.
	// Parse the configuration and configure limits.
	limits := []winjob.Limit{winjob.WithKillOnJobClose()}
	tokens := limitTokenMatcher.FindAllString(configuration, -1)

```
</issue_to_address>

### Comment 3
<location> `pkg/sandbox/sandbox_test.go:13` </location>
<code_context>
 	var err error
 	if runtime.GOOS == "windows" {
-		sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "go", "version")
+		sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "/some/path/bin", "go", "version")
 	} else {
-		sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "date")
</code_context>

<issue_to_address>
**suggestion (testing):** Test does not verify the effect of configurable resource paths.

Please add assertions to confirm that the sandbox configuration uses the provided path and its derived lib path as intended.

Suggested implementation:

```golang
	if err != nil {
		t.Fatal("unable to create sandboxed process:", err)
	}

	// Assert that the sandbox uses the provided bin path
	if sandbox.BinPath != "/some/path/bin" {
		t.Errorf("expected BinPath to be '/some/path/bin', got '%s'", sandbox.BinPath)
	}

	// Assert that the sandbox uses the derived lib path
	expectedLibPath := "/some/path/bin/lib"
	if sandbox.LibPath != expectedLibPath {
		t.Errorf("expected LibPath to be '%s', got '%s'", expectedLibPath, sandbox.LibPath)
	}

```

If the `Sandbox` struct does not have `BinPath` or `LibPath` fields, you will need to adjust the field names to match your implementation. If the derived lib path logic is different, update `expectedLibPath` accordingly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

// function allows for an optional callback (which may be nil) to configure the
// command before it is started.
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: updatedBinPath parameter is unused in this implementation.

If updatedBinPath is included for cross-platform consistency, please document this in the code. Otherwise, consider removing it to avoid confusion.

Suggested change
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
/*
updatedBinPath is included for cross-platform consistency with other platform-specific implementations.
It may not be used in this implementation, but is retained to keep the function signature uniform.
*/
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {

// function allows for an optional callback (which may be nil) to configure the
// command before it is started.
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: updatedBinPath parameter is unused in this implementation.

If updatedBinPath is included only for interface consistency, please document this or refactor to prevent confusion.

Suggested implementation:

/*
Create initializes a new Sandbox instance.

configuration: Pre-defined configuration value.
modifier: Optional callback to configure the command before it is started (may be nil).
updatedBinPath: Included for interface consistency with other platforms; currently unused in this implementation.
name: Name of the command to execute.
arg: Arguments to pass to the command.
*/
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
	// updatedBinPath is intentionally unused in this implementation.
	// Parse the configuration and configure limits.
	limits := []winjob.Limit{winjob.WithKillOnJobClose()}
	tokens := limitTokenMatcher.FindAllString(configuration, -1)

var err error
if runtime.GOOS == "windows" {
sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "go", "version")
sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "/some/path/bin", "go", "version")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Test does not verify the effect of configurable resource paths.

Please add assertions to confirm that the sandbox configuration uses the provided path and its derived lib path as intended.

Suggested implementation:

	if err != nil {
		t.Fatal("unable to create sandboxed process:", err)
	}

	// Assert that the sandbox uses the provided bin path
	if sandbox.BinPath != "/some/path/bin" {
		t.Errorf("expected BinPath to be '/some/path/bin', got '%s'", sandbox.BinPath)
	}

	// Assert that the sandbox uses the derived lib path
	expectedLibPath := "/some/path/bin/lib"
	if sandbox.LibPath != expectedLibPath {
		t.Errorf("expected LibPath to be '%s', got '%s'", expectedLibPath, sandbox.LibPath)
	}

If the Sandbox struct does not have BinPath or LibPath fields, you will need to adjust the field names to match your implementation. If the derived lib path logic is different, update expectedLibPath accordingly.

@p1-0tr p1-0tr merged commit 8e14fdd into main Sep 23, 2025
5 checks passed
@p1-0tr p1-0tr deleted the ps-updated-resources-in-sandbox branch September 23, 2025 08:23
doringeman pushed a commit to doringeman/model-runner that referenced this pull request Oct 2, 2025
…ounting-support

Add AI accelerator device mounting support in CreateControllerContainer
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.

4 participants