Skip to content

Support per-instance start bypassing assembly#2617

Open
SuperStrongDinosaur wants to merge 2 commits into
google:mainfrom
SuperStrongDinosaur:backend_start
Open

Support per-instance start bypassing assembly#2617
SuperStrongDinosaur wants to merge 2 commits into
google:mainfrom
SuperStrongDinosaur:backend_start

Conversation

@SuperStrongDinosaur

@SuperStrongDinosaur SuperStrongDinosaur commented May 28, 2026

Copy link
Copy Markdown
Collaborator

### Summary

Running cvd start typically triggers assemble_cvd, which regenerates the cuttlefish_config.json for all configured instances. Running this in a shared environment for a single instance can overwrite and corrupt the configuration of already running instances. This change allows starting a specific stopped instance using its existing assembled configuration.

### Key Changes

Assembly Bypass: Modified CvdStartCommandHandler::Handle to detect if a specific instance is targeted via selectors. Added a disk check for cuttlefish_config.json before bypassing assembly. If the configuration is missing, it correctly falls back to the normal group start path, runs assemble_cvd, and boots all instances.
LaunchSingleInstance Implementation: Added LaunchSingleInstance which directly constructs and invokes the run_cvd command for the target instance, bypassing assemble_cvd.
Environment Setup: Ensures LaunchSingleInstance sets up the exact environment variables required for run_cvd to boot the specific instance.
Database Status Update Fix: Updated LaunchSingleInstance to only update the database state for the targeted instance being started, preventing other stopped instances in the group from being incorrectly marked as active.

Bug
b/459780275

Document
go/cuttlefish-per-instance-control

Frontend pr
#2618

@SuperStrongDinosaur SuperStrongDinosaur changed the title feat(backend): support per-instance start bypassing assembly Support per-instance start bypassing assembly May 28, 2026
@SuperStrongDinosaur SuperStrongDinosaur added the kokoro:run Run e2e tests. label May 28, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label May 28, 2026
@SuperStrongDinosaur SuperStrongDinosaur force-pushed the backend_start branch 5 times, most recently from 29a424c to 2d985ec Compare June 2, 2026 15:56
@SuperStrongDinosaur SuperStrongDinosaur force-pushed the backend_start branch 2 times, most recently from 0997443 to ef25374 Compare June 8, 2026 09:25
@SuperStrongDinosaur SuperStrongDinosaur marked this pull request as ready for review June 8, 2026 11:15
@SuperStrongDinosaur SuperStrongDinosaur force-pushed the backend_start branch 2 times, most recently from 066564f to 4cb3d8d Compare June 8, 2026 12:36
auto config_path =
group.AssemblyDir() + "/cuttlefish_config.json";
if (FileExists(config_path)) {
return LaunchSingleInstance(instance, group, request);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: return CF_EXPECT(LaunchSingleInstance(...))

The macro is necessary to add an additional member to the stack trace held inside the Result.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've updated the code to use CF_EXPECT to propagate the stack trace.

Comment on lines +346 to +347
auto config_path =
group.AssemblyDir() + "/cuttlefish_config.json";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: the style guide writes

Use type deduction only if it makes the code clearer to readers who aren't familiar with the project, or if it makes the code safer. Do not use it merely to avoid the inconvenience of writing an explicit type.

The destructuring auto above is fair since it's the only way to write something like that, but in this case it's helpful while reading to know what the types are when possible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

refactored and removed

if (FileExists(config_path)) {
return LaunchSingleInstance(instance, group, request);
} else {
LOG(INFO) << "Group configuration does not exist on disk. Proceeding with normal group start.";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

INFO is kind of high. Any launch from cvd load or cvd create --config_file will trigger this:

options.instance_names = std::vector<std::string>();
for (const auto& instance : config.instances()) {
options.instance_names->push_back(instance.name());
}

Maybe DEBUG?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +346 to +347
auto config_path =
group.AssemblyDir() + "/cuttlefish_config.json";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From the perspective of cvd, whether cuttlefish_config.json exists is an implementation detail of assemble_cvd and it would be better to avoid more dependency on this fact than we already have.

Is it possible to determine the conditions for re-launching an instance through whether cvd start is being invoked on an instance state matching INSTANCE_STATE_STOPPED?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. Replaced the FileExists check on the config file with instance.State() == cvd::INSTANCE_STATE_STOPPED

@SuperStrongDinosaur SuperStrongDinosaur force-pushed the backend_start branch 3 times, most recently from f239b65 to c7ff09b Compare June 9, 2026 12:00
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.

3 participants