Skip to content

Infer direct mode from existing pull requests - #366

Merged
ezyang merged 2 commits into
mainfrom
gh/ezyang/74/head
Jul 29, 2026
Merged

Infer direct mode from existing pull requests#366
ezyang merged 2 commits into
mainfrom
gh/ezyang/74/head

Conversation

@ezyang

@ezyang ezyang commented Jul 29, 2026

Copy link
Copy Markdown
Owner

No description provided.

Move the direct-mode determination out of `__init__` into a new
`_initialize_direct` method that runs after PR info has been
prefetched, so it can consult the existing pull requests in the stack.

Previously direct mode was resolved solely from the `--direct` /
`--no-direct` flags, falling back to the presence of the
`.github/ghstack_direct` marker file. Now, when the user hasn't passed
an explicit flag and the marker doesn't force direct on, we inspect the
base refs of the already-submitted PRs: a `gh/<user>/<n>/base` base ref
indicates non-direct style, anything else indicates direct. If the
stack mixes both styles we bail out with an error asking the user to
pass `--direct` / `--no-direct` explicitly, rather than guessing.

This lets an existing stack that was first submitted in direct mode keep
being updated in direct mode without repeating the flag.

Test plumbing changes to support this:

- `direct` is now `Optional[bool]` throughout `test_prelude.py`; `None`
  means "infer". `check_global_github_invariants` only enforces the
  non-direct base-ref-reuse invariant when `direct is False`.
- `gh_submit` gained a `**submit_kwargs` passthrough and a per-call
  `direct_opt` override so a test can submit one commit with an explicit
  mode and a later update with inference.
- conftest now parametrizes on `direct` as before, but recognizes
  `*.unparametrized.py.test` scripts and runs them once with
  `direct=None`. Collection also matches on the `.py.test` filename
  suffix directly.

New test `test/submit/infer_direct.unparametrized.py.test`: submit a
commit with `direct_opt=True`, then amend and update without specifying
a mode, exercising the inference path.

[ghstack-poisoned]
@ezyang

ezyang commented Jul 29, 2026

Copy link
Copy Markdown
Owner Author

Stack from ghstack (oldest at bottom):

This update reworks how the direct-mode inference is wired in. Rather than
just renaming the `cat-file` result variable, `_initialize_direct` now keeps
the original `direct_r`/`direct` computation and takes a `pr_info_cache`
argument so it can consult existing pull requests. When `--direct`/`--no-direct`
was not passed on the command line and the `.github/ghstack_direct` marker is
absent, it now examines the base ref styles of the already-submitted PRs
(matching against the `gh/<user>/<n>/base` pattern) to infer whether the stack
was previously submitted in direct mode, instead of defaulting to non-direct.
The call in `run()` is updated to pass the prefetched `pr_info_cache`.

Also updates AGENTS.md to document the lint workflow via
`uv run --frozen lintrunner --all-files` (and `lintrunner format` for fixes),
replacing the older black/flake8 instructions.

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jul 29, 2026
ghstack-source-id: 75ca3f5
ghstack-comment-id: 5122316835
Pull-Request: #366
@ezyang
ezyang merged commit f4e9df5 into main Jul 29, 2026
16 of 32 checks passed
@ezyang
ezyang deleted the gh/ezyang/74/head branch July 29, 2026 20:38
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