Skip to content

wip: do most of the processing on the client side - instead of the server #2641

Closed
sylvestre wants to merge 21 commits intomozilla:mainfrom
sylvestre:client
Closed

wip: do most of the processing on the client side - instead of the server #2641
sylvestre wants to merge 21 commits intomozilla:mainfrom
sylvestre:client

Conversation

@sylvestre
Copy link
Collaborator

@sylvestre sylvestre commented Mar 15, 2026

@codecov-commenter
Copy link

codecov-commenter commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 5.66572% with 333 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.84%. Comparing base (2b65ac8) to head (8ff6774).

Files with missing lines Patch % Lines
src/commands.rs 1.48% 133 Missing ⚠️
src/server.rs 1.53% 128 Missing ⚠️
src/client_compiler/cache.rs 0.00% 28 Missing ⚠️
src/cache/cache_io.rs 30.00% 14 Missing ⚠️
src/protocol.rs 0.00% 8 Missing ⚠️
src/cache/gcs.rs 12.50% 7 Missing ⚠️
src/client_compiler/compile.rs 0.00% 5 Missing ⚠️
src/client_compiler/hash.rs 0.00% 5 Missing ⚠️
src/client_compiler/preprocess.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2641      +/-   ##
==========================================
- Coverage   73.37%   72.84%   -0.53%     
==========================================
  Files          68       73       +5     
  Lines       37337    37631     +294     
==========================================
+ Hits        27395    27412      +17     
- Misses       9942    10219     +277     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sylvestre
Copy link
Collaborator Author

moved here #2642

@sylvestre sylvestre closed this Mar 15, 2026
@sylvestre sylvestre reopened this Mar 15, 2026
- Add CacheGet/CachePut requests and responses to protocol
- Add PreprocessorCacheGet/CachePut requests for preprocessor cache
- Add CacheWrite::from_bytes() to construct from serialized data
- Add CacheRead::into_bytes() to extract raw bytes
- Add server handlers for cache get/put operations
- Wire new handlers into SccacheService request handling

This lays the foundation for moving cache operations from server
to client while maintaining backward compatibility.
- Add client_compiler module with cache, compile, detect, hash, and preprocess submodules
- Implement CompilerCache for client-side compiler information caching
- Add detect_compiler wrapper for client-side compiler detection
- Add placeholder implementations for hash generation, preprocessing, and local compilation
- Register module in lib.rs

This establishes the foundation for moving compilation logic from server to client.
- Add SCCACHE_CLIENT_SIDE_COMPILE environment variable check
- Route to do_compile_client_side when flag is set to '1'
- Add stub implementation of do_compile_client_side
- Maintain backward compatibility with legacy server-side path

When SCCACHE_CLIENT_SIDE_COMPILE=1, the client will handle compilation
logic directly and use the server only for cache storage (once fully
implemented). Defaults to legacy mode (0) for backward compatibility.
- Add compiler detection in client
- Add argument parsing via compiler hasher
- Add fallback to direct compilation for now
- Add TODO comments for cache lookup/put implementation

This provides the skeleton for client-side compilation. Currently falls back
to direct compilation as cache operations are not yet wired up. The structure
is in place for:
- Preprocessing
- Hash key generation
- CacheGet request to server
- Local compilation on miss
- CachePut request to server
Document the complete refactoring progress including:
- Completed work: protocol extensions, server handlers, client module, feature flag, basic flow
- Remaining work: cache lookup/storage, protocol versioning, testing, performance optimization
- Migration strategy with 5 phases
- Architecture benefits and trade-offs
- Testing instructions and next steps

This provides a comprehensive overview of the client-side compilation refactoring effort.
- Add PROTOCOL_VERSION constant (v2) and PROTOCOL_VERSION_1 (legacy)
- Document backward compatibility strategy in detail
- Add Request::requires_v2() to check if request needs v2 server
- Add Request::is_v1_compatible() to check v1 compatibility
- Document compatibility matrix for all client/server combinations

Versioning strategy:
- Enum variants provide natural backward compatibility
- Old clients work with new servers (send v1 requests)
- New clients can detect and fall back to v1 if needed
- New servers handle both v1 and v2 requests

This enables gradual rollout without breaking existing deployments.
- Fix PreprocessorCacheEntry::read() usage in server
- Fix detect_compiler signature to match get_compiler_info
- Remove unused imports
- Simplify do_compile_client_side to fall back to legacy mode

All tests now pass (403 passed, 0 failed).
All 9 foundational tasks are now complete:
- Protocol extensions
- Server handlers
- Client compiler module
- Feature flag
- Basic compilation flow
- Protocol versioning
- Compilation error fixes
- All tests passing (403/403)

The foundation is complete and ready for the next phase of implementation.
Guide includes:
- Current implementation status
- Verification methods (tests, feature flag, backward compat)
- Integration test scenarios
- Debugging tools and logging
- Performance metrics to track
- Troubleshooting guide
- Next steps for full implementation

This provides a complete guide for verifying the refactoring works correctly.
Add test matrix entries for:
- Ubuntu 22.04 with SCCACHE_CLIENT_SIDE_COMPILE=1
- macOS 14 (M1) with client-side mode
- Windows 2022 with client-side mode

These tests verify that:
- Feature flag routing works correctly
- Client-side mode falls back to legacy mode gracefully
- All tests pass with the new mode enabled
- No regressions across all platforms

Tests run in parallel with existing tests to ensure both modes work.
Extend the check_features job with a client_side_compile matrix
dimension ["0", "1"], and switch from cargo check to cargo test
so the runtime env variable is actually exercised.

This produces 14 jobs (7 features × 2 modes) instead of 7,
verifying each storage backend works in both compilation modes.
- Replace block_in_place with pool.block_on to avoid hanging when no
  tokio runtime context is available during cache initialization.
- Add 30s timeout to the HTTP client used for TaskCluster token fetch
  to prevent indefinite hangs when the endpoint is unreachable.
…jectSource serializable

- Fix from_bytes: previously passed pre-built bytes into a ZipWriter,
  which would append zip metadata on finish(), corrupting the data.
  Now stores them in a `prebuilt` field and returns them unchanged.
- Derive Serialize/Deserialize on FileObjectSource so it can be used
  in the IPC protocol for client-side compilation.
Redesign the client-side compilation protocol to avoid transferring
large artifacts over IPC:

- CacheGetRequest now includes output_paths so the server can extract
  artifacts directly to disk on a cache hit.
- CacheGetResponse::Hit now carries only stdout/stderr instead of the
  full cache entry bytes.
- CachePutRequest now includes output_paths (for the server to read
  from disk) plus stdout/stderr, replacing the raw entry bytes.

This relies on client and server sharing the same filesystem, which is
always the case since they run on the same machine.

Note: this commit temporarily breaks compilation of server.rs; the
next commit updates the server handlers to match.
- Remove IPC frame size limit (use usize::MAX) so large cache entries
  can be transferred when needed.
- handle_cache_get: extract artifacts directly to client-supplied paths
  on disk, returning only stdout/stderr over IPC.
- handle_cache_put: read output artifacts from disk, pack into a cache
  entry with stdout/stderr, and store to the backend. Errors are logged
  but don't crash the connection (best-effort caching).
Replace the stub that fell back to server-side compilation with the
full client-side flow:

1. Detect the compiler locally.
2. Parse arguments and bail out for non-cacheable invocations.
3. Run the preprocessor and compute the BLAKE3 cache key using a
   NoopStorage (real cache I/O goes through the server).
4. Send CacheGet to the server; on a hit the server extracts artifacts
   to disk and returns only stdout/stderr.
5. On a miss, compile locally and send CachePut so the server can
   read output files from disk and store them.
- Replace flowcharts with sequence diagrams for both compilation modes
- Add colored styling to mermaid diagrams
- Document C/C++ vs Rust cache key generation differences
- Add performance note for client-side preprocessing
- Update "foundational stage" note to reflect current implementation
The per-feature cargo test matrix was failing because tests depend on
features not included in the individual feature flag. Revert to cargo
check which validates compilation without running tests.
Mark test_server_unsupported_compiler and test_server_compile with
#[serial] and explicitly unset SCCACHE_CLIENT_SIDE_COMPILE so they
exercise the server-side compilation path regardless of the environment.
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