-
Notifications
You must be signed in to change notification settings - Fork 0
Jnewhouse/write path #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacksonrnewhouse
wants to merge
4
commits into
markovejnovic/some-decent-performance
Choose a base branch
from
jnewhouse/write_path
base: markovejnovic/some-decent-performance
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37f6b54
refactor: use async fn syntax for SsfsBackend impl
jacksonrnewhouse 138ea09
fix: use actual uid/gid from current process
jacksonrnewhouse 9d7b0ce
feat: add write support with immediate commits to remote
jacksonrnewhouse 125015d
refactor: extract commit worker into dedicated module
jacksonrnewhouse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,4 @@ rand = "0.9.2" | |
| rustc-hash = "2.1.1" | ||
| scc = "3.4.16" | ||
| base64 = "0.22" | ||
| nix = "0.29.0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| //! Background worker for processing commit requests. | ||
| //! | ||
| //! This module handles asynchronous commits to the remote repository via the Mesa API. | ||
|
|
||
| use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; | ||
| use mesa_dev::Mesa; | ||
| use mesa_dev::models::{Author, CommitEncoding, CommitFile, CommitFileAction, CreateCommitRequest}; | ||
| use tokio::sync::mpsc; | ||
| use tracing::{error, info}; | ||
|
|
||
| /// A request to create a commit, sent to the background worker. | ||
| pub enum CommitRequest { | ||
| /// Create a new file with the given content. | ||
| Create { | ||
| /// Path to the file to create. | ||
| path: String, | ||
| /// Content of the file. | ||
| content: Vec<u8>, | ||
| }, | ||
| /// Update an existing file with new content. | ||
| Update { | ||
| /// Path to the file to update. | ||
| path: String, | ||
| /// New content of the file. | ||
| content: Vec<u8>, | ||
| }, | ||
| /// Delete a file. | ||
| Delete { | ||
| /// Path to the file to delete. | ||
| path: String, | ||
| }, | ||
| } | ||
|
|
||
| /// Configuration for the commit worker. | ||
| pub struct CommitWorkerConfig { | ||
| /// Mesa API client. | ||
| pub mesa: Mesa, | ||
| /// Repository organization/owner. | ||
| pub org: String, | ||
| /// Repository name. | ||
| pub repo: String, | ||
| /// Branch to commit to. | ||
| pub branch: String, | ||
| /// Author information for commits. | ||
| pub author: Author, | ||
| } | ||
|
|
||
| /// Spawns a background task that processes commit requests from the given receiver. | ||
| /// | ||
| /// The task will run until the channel is closed (all senders are dropped). | ||
| pub fn spawn_commit_worker( | ||
| rt: &tokio::runtime::Runtime, | ||
| config: CommitWorkerConfig, | ||
| mut commit_rx: mpsc::UnboundedReceiver<CommitRequest>, | ||
| ) { | ||
| let mesa = config.mesa; | ||
| let org = config.org; | ||
| let repo = config.repo; | ||
| let branch = config.branch; | ||
| let author = config.author; | ||
| rt.spawn(async move { | ||
| while let Some(request) = commit_rx.recv().await { | ||
| let (message, files) = match request { | ||
| CommitRequest::Create { path, content } => { | ||
| // Use "." for empty files to work around Mesa API bug with empty content | ||
| let content_bytes = if content.is_empty() { | ||
| b".".as_slice() | ||
| } else { | ||
| &content | ||
| }; | ||
| ( | ||
| format!("Create {path}"), | ||
| vec![CommitFile { | ||
| action: CommitFileAction::Upsert, | ||
| path, | ||
| encoding: CommitEncoding::Base64, | ||
| content: Some(BASE64.encode(content_bytes)), | ||
| }], | ||
| ) | ||
| } | ||
| CommitRequest::Update { path, content } => { | ||
| // Use "." for empty files to work around Mesa API bug with empty content | ||
| let content_bytes = if content.is_empty() { | ||
| b".".as_slice() | ||
| } else { | ||
| &content | ||
| }; | ||
| ( | ||
| format!("Update {path}"), | ||
| vec![CommitFile { | ||
| action: CommitFileAction::Upsert, | ||
| path, | ||
| encoding: CommitEncoding::Base64, | ||
| content: Some(BASE64.encode(content_bytes)), | ||
| }], | ||
| ) | ||
| } | ||
| CommitRequest::Delete { path } => ( | ||
| format!("Delete {path}"), | ||
| vec![CommitFile { | ||
| action: CommitFileAction::Delete, | ||
| path, | ||
| encoding: CommitEncoding::Base64, | ||
| content: None, | ||
| }], | ||
| ), | ||
| }; | ||
|
|
||
| let create_commit_request = CreateCommitRequest { | ||
| branch: branch.clone(), | ||
| message: message.clone(), | ||
| author: author.clone(), | ||
| files, | ||
| base_sha: None, | ||
| }; | ||
|
|
||
| info!("about to commit the following: {:?}", create_commit_request); | ||
|
|
||
| let result = mesa | ||
| .commits(&org, &repo) | ||
| .create(&create_commit_request) | ||
| .await; | ||
|
|
||
| match result { | ||
| Ok(_) => info!(message = %message, "commit pushed"), | ||
| Err(e) => error!(message = %message, error = %e, "commit failed"), | ||
| } | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "workaround" replaces every empty file with a single
'.'byte before base64 encoding (lines 65‑78 and 82‑95). That means any zero-length file we create or truncate is committed with one byte of content, so the file is no longer empty when it reaches Mesa/GitHub. Unless the server really does a special-case replacement onLg==, this corrupts empty files.If the Mesa API cannot accept an empty string today, we need a server-side fix or a different protocol knob (e.g., send
content: Some(String::new()), or add an explicit flag) rather than mutating user data on the client.Prompt for Agent