Skip to content

[WIP] Gracefully handle name conflict corner cases - #6478

Closed
sipsma wants to merge 7 commits into
dagger:mainfrom
sipsma:core-conflict
Closed

sipsma wants to merge 7 commits into
dagger:mainfrom
sipsma:core-conflict

Conversation

@sipsma

@sipsma sipsma commented Jan 23, 2024 •

Copy link
Copy Markdown
Contributor

Opening as draft to start discussion while I work on proposed solution in parallel, only change so far are some new tests that exemplify the problem (and commits from the dagger.json updates PR, which this will be based on).

Related to:

The need for better handling of corner case conflicts between a module's objects and dependencies/core has been on my radar for a while via those issues, but once I started working on what I thought would be relatively straightforward handling, I realized that there's more corner cases and that the solutions are potentially much more annoying for the users than I originally imagined...

These are very much corner cases, but also not obscure enough to ignore. Have a general approach in mind but want to get feedback from others in parallel while I finish implementing it since it's not entirely obvious one way or the other.

Also highly possible I'm caring way too much about obscure corner cases, feel free to let me know if you feel that way.

Example Problems

These are different manifestations of the same set of underlying problems.

An important note is that these problems all exist on the level of the graphql schema and are not specific to implementation details of any single SDK.

Conflicts between a module and a direct dep of the same name

Covered here: #6438

Basically, a module Foo that depends on another module Foo currently results in an error due to the fact modules are loaded with schemas for their own APIs in addition to their dependencies.

Conflicts between two deps with same name prefix

Example:

  • One module is named FooBar
  • Another module is named Foo and defines an object named Bar
  • A Caller module depends on both FooBar and Foo

In this case, the schema for Caller's deps will contain:

  • the FooBar "main module object" from FooBar
  • the FooBar object from Foo (gets that name due to namespacing of Bar

And thus there will be a conflict.

Even worse, say that originally the Foo module didn't have Bar defined, but was updated to in a newer version. Caller may have a bunch of code written that now suddenly stops compiling just because they updated to that new version of Bar (as opposed to getting an error before they even started writing their code, which is at least less painful even if annoying).

Conflicts between a module's types and core types

Say someone authors a module named Foo and we add a type Foo to core at some point in the future.

This will create a conflict on the graphql schema level (i.e. not just the Go SDK codegen).

This is exacerbated by the fact that core is not namespaced, but say we did namespace everything by Core (CoreContainer, CoreDirectory, CoreFile, etc.). There would still be problems if someone had a module named CoreFoo and we added a Foo type to core in the future.

Current Proposed Solution

General considerations I have in mind here:

  1. These cases most likely won't be super common, so it's acceptable if the fixes require the user do something explicitly to resolve the conflict (though the easier the better, and if there's some way to make it disappear entirely that would be the best obviously)
  2. In the case where a conflict like this arises due to a dependency upgrade, it's extra painful if a user has to update names across all the code of a module they have already written a lot of code for (even if it's a bunch of sed -is).. If there are any changes needed, it's worth trying to make it as minimal as possible.

This will come in a few parts, outlined below

Also, as the utter baseline, we obviously need clear+helpful error messages if these cases happen. Probably goes without saying.

Support for aliasing dependencies

Originally suggested this as a solution purely to #6438 but I think now it can probably be used more generally.

Basically, similar to how most languages let you alias an import, we can do the same.

As a strawman, you could imagine

dagger mod install --alias someAlias github.com/org/daggerverse/someMod`

That would result in the module name of someMod to be overwritten to someAlias and thus all the objects would be namedspaced with SomeAlias, allowing any conflicts to be avoided.

Support for aliasing individual objects

This is likely getting obscure enough that we could skip for now and save for the future if really needed, but will mention anyways.

The one catch remaining is the case where a conflict like this arises due to a dependency upgrade. It would really suck if a user had to rewrite all their usage of objects from the dep once they had to change it to an alias.

The only solution I can think of here would be to also support aliasing individual objects from a dependency in addition to aliasing the whole module name. So, again as a strawman, maybe

dagger mod install --alias-object foo bar github.com/org/daggerverse/someMod

would result in the Foo object from someMod to be renamed to Bar and thus allow the caller to not have to rename everything in their code (just at most a few isolated objects).

core is explicit dep in dagger.json + optionally supports aliasing

Complementary to the above, we can support core being an explicit dep in dagger.json and thus have the same aliasing abilities as any other module, which should give a path to also avoiding conflicts with types from it via the exact same mechanism as with user modules.

This is generally complementary to a whole bunch of baby steps we been taking to model core more and more as a module, not actually that big of a leap from the current state in terms of implementation.

Longer term - module author docs

We've discussed this previously, but its importance definitely goes up a bit if we go this route.

Basically, it should be easy to view docs while authoring modules for the generated bindings to all your deps. May just need to be a builtin-sdk feature (or possibly a module of its own that operates on other modules, TBD).

This becomes even more important if alias settings result in the actual names available to you being customized. We don't want users needing to read dagger.json manually to figure stuff like this out.

Other Possibilities

There's an enormous number of other variations and completely different approaches here.

But my favorite alternative is to change graphql schemas for each module to be completely independent schemas, never mixed together when being used as a set of dependencies. Could be queryable via different endpoints on the engine.

  • This is something we've mentioned in passing before, but is probably more feasible than ever thanks to dagql
  • In general, this might be the ideal solution in some ways since the problem could dissolve entirely.
  • However, in practice, it's a fairly significant lift with lots of questions and tradeoffs.
    • Among other things, it would require significant updates to the Go+Python+Typescript SDKs to know how to switch endpoints they are querying depending on which module API they are hitting.

The main reason I'm ruling this out now is partially practicality in terms of time and partially that I can't say for sure that it would actually work in practice; it's too vague and would need more detailing to make a call on.

The proposed solution is much more obvious in the short term and includes things we've wanted to do anyways (such as put core as an explicit dep in dagger.json). So it's relatively low cost. In a hypothetical future where we've changed the graphql servers + SDKs to avoid this problem entirely, then we can just sunset aliasing as a feature.


There's one last alternative solution, which is that I'm severely overthinking obscure corner cases and we can just have clear error messages + docs in these cases for now 😄 I'd honestly be happy to hear others felt that way, but atm to me these cases seem just barely too straightforward to hit that they are hard to ignore, even if relatively obscure.


cc @vito @helderco @jedevc @shykes

In the previous commit I added a bunch of new tests and some extra
validation, but then forgot to run the rest of the tests, which were
failing with validation errors on paths in cases that were actually
okay.

This fixes the validation to allow relative paths provided they don't
escape the root dir, which requires some careful handling to deal with
the fact that e.g. filepath.Join(/, "../..") == "/".

Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Jan 31, 2024

Copy link
Copy Markdown
Contributor Author

Closing this PR out since #6386 ended up adding support for custom names of dependencies and thus fixing the problems of:

  • my mod has the same name as a dep
  • two deps have the same name

Which are also covered in integ tests now (which is all this PR consisted of). We do still need to implement support for being able to rename "core", so will leave #6328 and #6071 open to track that. But can be done backwards compatibly now.

@sipsma sipsma closed this Jan 31, 2024
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