Skip to content

⚡ Optimize FileAuditStore::log_async to use spawn_blocking#100

Open
Tuntii wants to merge 1 commit intomainfrom
perf/audit-file-store-async-io-14806398196114527397
Open

⚡ Optimize FileAuditStore::log_async to use spawn_blocking#100
Tuntii wants to merge 1 commit intomainfrom
perf/audit-file-store-async-io-14806398196114527397

Conversation

@Tuntii
Copy link
Owner

@Tuntii Tuntii commented Feb 6, 2026

Refactored FileAuditStore to use an Arc<Inner> internal structure, enabling cheap cloning.
Implemented log_async using tokio::task::spawn_blocking to offload synchronous file I/O to the blocking thread pool, preventing async runtime stalls.
Preserved synchronous log behavior for non-async contexts.


PR created automatically by Jules for task 14806398196114527397 started by @Tuntii

Co-authored-by: Tuntii <121901995+Tuntii@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 6, 2026 03:39
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the FileAuditStore implementation to better support async contexts by preventing async runtime stalls. The refactoring introduces an Arc<Inner> pattern that enables cheap cloning while maintaining shared internal state, and implements log_async using tokio::task::spawn_blocking to offload synchronous file I/O operations to a dedicated thread pool.

Changes:

  • Refactored internal structure to use Arc<FileAuditStoreInner> pattern for efficient cloning
  • Implemented log_async with tokio::task::spawn_blocking to prevent async runtime blocking
  • Added Clone and Debug trait implementations to FileAuditStore

Comment on lines +214 to +224
fn log_async(
&self,
event: AuditEvent,
) -> Pin<Box<dyn Future<Output = AuditResult<()>> + Send + '_>> {
let store = self.clone();
Box::pin(async move {
tokio::task::spawn_blocking(move || store.log(event))
.await
.map_err(|e| AuditError::IoError(format!("Task join error: {}", e)))?
})
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The new log_async method lacks test coverage. Given that the codebase uses comprehensive async testing (as seen in other modules like replay, api_key, circuit_breaker, etc.), and that log_async introduces new behavior with spawn_blocking, it should have dedicated test coverage. Consider adding a test like:

#[tokio::test]
async fn test_file_store_log_async() {
let (store, _dir) = temp_store();
let event = AuditEvent::new(AuditAction::Create).actor("admin");
let id = event.id.clone();
store.log_async(event).await.unwrap();
store.flush().unwrap();
let retrieved = store.get(&id).unwrap();
assert!(retrieved.is_some());
}

This would verify that the spawn_blocking mechanism works correctly and that events logged asynchronously are properly persisted.

Copilot uses AI. Check for mistakes.
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