Skip to content

Add fallback-mode option for subset#1308

Merged
takanabe merged 4 commits into
mainfrom
fallback-mode
Jun 2, 2026
Merged

Add fallback-mode option for subset#1308
takanabe merged 4 commits into
mainfrom
fallback-mode

Conversation

@takanabe
Copy link
Copy Markdown
Contributor

@takanabe takanabe commented May 28, 2026

Background

When the subset API errors or returns isBrainless=true, users can now opt into 'stop' (exit non-zero to halt CI) or 'random-sample' (split locally using --target) instead of the default run-all behavior. The option is hidden and off by default so existing pipelines are unaffected.

Changes

  • Add --fallback-mode option for subset command

When the subset API errors or returns isBrainless=true, users can now
opt into 'stop' (exit non-zero to halt CI) or 'random-sample' (split
locally using --target) instead of the default run-all behavior.
The option is hidden and off by default so existing pipelines are unaffected.
Comment thread smart_tests/commands/subset.py Outdated
elif self.fallback_mode == FallbackMode.RANDOM_SAMPLE:
target_fraction = float(self.target) if self.target is not None else 1.0
click.echo(
"Warning: Smart Tests could not retrieve a subset. Falling back to local random sample.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since users may use options other than --target e.g.) --confidence, it might be helpful to include the target percentage in the warning message as well.

Or, if --fallback_mode is specified and the user is using an option other than --target, we could return an error in the validation arera

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds prudent. Let me consider

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

handled with #1308

sampled = random.sample(test_paths, min(count, len(test_paths)))
sampled_set = {id(t): t for t in sampled}
rest = [t for t in test_paths if id(t) not in sampled_set]
return cls(subset=sampled, rest=rest, subset_id='', summary={}, is_brainless=False, is_observation=False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is is_brainless=False intentionally?

Copy link
Copy Markdown
Contributor Author

@takanabe takanabe Jun 1, 2026

Choose a reason for hiding this comment

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

Yes, is_brainless=False is intentional. The random sample result is locally generated, not from the brainless model. I hope the behavior matches with this implementation ea8477a

Copy link
Copy Markdown
Contributor

@Konboi Konboi Jun 2, 2026

Choose a reason for hiding this comment

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

OK 👍
Could you add a comment that why we update the brainless mode value from true to false here?

I misunderstood the data flow, you don't have to add comment, sorry

Comment thread tests/commands/test_api_error.py Outdated
result = self.cli(*self._subset_args(rest_file.name, ("--fallback-mode", "random-sample")), mix_stderr=False)
self.assert_success(result)
all_tests = result.stdout.strip().split("\n") + Path(rest_file.name).read_text().strip().split("\n")
all_tests = [t for t in all_tests if t]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q: What is this loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a filter. "".split("\n") returns [""] rather than []. So if either stdout or the rest file is empty, the concatenation produces empty strings and the count assertion would be wrong.

Probably, there is a better way. I'll consider again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I treated the empty string as the edge case but let me drop the filter for the test for simplicity 0451d3a

# TODO(Konboi): split subset isn't provided for smart-tests initial release
# if split:
# click.echo("subset/{}".format(subset_result.subset_id))
if subset_result.is_brainless:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In Brainless mode, we're already splitting requests between subset and rest on the server side.

I can understand the stop behavior, but for sampling, do you mean re-sampling the tests on the CLI side?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, you are right. this is redundant if we split tests on server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

handled with ea8477a

@takanabe takanabe requested a review from Konboi June 1, 2026 23:47
Copy link
Copy Markdown
Contributor

@Konboi Konboi left a comment

Choose a reason for hiding this comment

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

LGTM


I left a comment but it's nits comment so I'll approve this PR

@takanabe takanabe merged commit dcbf804 into main Jun 2, 2026
3 checks passed
@takanabe takanabe deleted the fallback-mode branch June 2, 2026 19:01
@github-actions github-actions Bot mentioned this pull request Jun 2, 2026
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.

2 participants