Skip to content

ci: pre-populate synthtool cache to avoid race condition#17230

Merged
ohmayr merged 4 commits into
googleapis:mainfrom
suztomo:fix-synthtool-race
May 22, 2026
Merged

ci: pre-populate synthtool cache to avoid race condition#17230
ohmayr merged 4 commits into
googleapis:mainfrom
suztomo:fix-synthtool-race

Conversation

@suztomo
Copy link
Copy Markdown
Member

@suztomo suztomo commented May 22, 2026

This PR resolves a blocking parallel generation issue on GitHub Actions and updates Spanner's post-processing config to align with recent template updates.

1. Fix GHA parallel generation race condition

When running librarian generate --all in GHA, multiple libraries are generated in parallel. They concurrently invoke synthtool, which races to clone/update the templates repository (googleapis/synthtool) in the shared cache directory ~/.cache/synthtool/synthtool.

This results in either:

  • A clone race: One process starts cloning, and others see the half-created directory, assume it's valid, and fail with fatal: failed to resolve HEAD as a valid ref when running git branch.
  • An update race: Multiple processes try to run git checkout / git pull concurrently, failing with fatal: Unable to create ... index.lock: File exists.

Fix:
We now clone googleapis/synthtool once sequentially at the beginning of the workflow (Clone Synthtool Templates), and configure SYNTHTOOL_TEMPLATES environment variable globally to point to this local directory. This completely bypasses all concurrent git clone/pull operations during parallel generation, resolving the race conditions and speeding up the build.

2. Fix Spanner post-processing AssertionError

We removed the obsolete Supported Python Versions replacement block from .librarian/generator-input/client-post-processing/spanner-integration.yaml.

Why it was needed:

  • On May 19, 2026 (commit 2408166fec), Python 3.7-3.9 support was dropped specifically for Spanner. Because the synthtool templates still generated Python >= 3.9 in README.rst by default, a post-processing workaround was added to force it to 3.10.
  • On May 21, 2026 (commit e643ce8 in googleapis/synthtool), synthtool templates were updated globally to drop Python 3.9 support for all mono-repo libraries.
  • As a result, the freshly generated README.rst for Spanner now already defaults to Python >= 3.10. The May 19 workaround became obsolete and failed with AssertionError: Replaced 0 rather than 1 instances because the "before" pattern (expecting 3.9) no longer exists.

TAG=agy
CONV=acb0ee9b-3d87-4b9e-b3c6-0d4aa3efbd35

Temporarily add pull_request trigger to verify the fix.

TAG=agy

CONV=acb0ee9b-3d87-4b9e-b3c6-0d4aa3efbd35
@suztomo suztomo requested a review from a team as a code owner May 22, 2026 01:40
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented May 22, 2026

@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented May 22, 2026

It failed.

suztomo added 3 commits May 22, 2026 01:57
… conflict

This avoids parallel git checkout/pull race conditions by cloning the templates once and pointing SYNTHTOOL_TEMPLATES to it.

TAG=agy

CONV=acb0ee9b-3d87-4b9e-b3c6-0d4aa3efbd35
The templates now default to Python 3.10, so this workaround is no longer needed and causes AssertionError.

TAG=agy

CONV=acb0ee9b-3d87-4b9e-b3c6-0d4aa3efbd35
We have verified the fix works. Reverting the temporary trigger before merge.

TAG=agy

CONV=acb0ee9b-3d87-4b9e-b3c6-0d4aa3efbd35
@suztomo
Copy link
Copy Markdown
Member Author

suztomo commented May 22, 2026

@ohmayr ohmayr merged commit 4d64ebc into googleapis:main May 22, 2026
34 checks passed
@suztomo suztomo mentioned this pull request May 22, 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