Skip to content

[AUDIT SINK PART 2] File implements audit Sink Trait - #1190

Open
HatemMn wants to merge 5 commits into
feat/audit-sink-refactorfrom
feat/audit-sink-generalize
Open

HatemMn wants to merge 5 commits into
feat/audit-sink-refactorfrom
feat/audit-sink-generalize

Conversation

@HatemMn

@HatemMn HatemMn commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Overview

feat/audit-sink-generalize

One commit. This is where the file backend actually adapts to the new public AuditSink trait instead of a private mock one.

Small diff but this is the one place old behavior could have silently shifted during the refactor.

Got its own PR instead of getting buried in the split commit before it.

@HatemMn
HatemMn marked this pull request as ready for review September 11, 2026 15:44
@HatemMn
HatemMn changed the base branch from develop to feat/audit-sink-refactor September 11, 2026 15:44
@HatemMn
HatemMn added this pull request to stack #1128 September 11, 2026 15:47
@HatemMn
HatemMn removed this pull request from stack #1128 September 11, 2026 15:49
@HatemMn
HatemMn added this pull request to stack #1196 September 15, 2026 08:52
@HatemMn
HatemMn force-pushed the feat/audit-sink-generalize branch from d3c0bee to 33a2aec Compare September 15, 2026 12:53
@HatemMn
HatemMn deployed to xks-remote-approval September 15, 2026 12:53 — with GitHub Actions Active
@HatemMn
HatemMn force-pushed the feat/audit-sink-generalize branch from 33a2aec to 94866c5 Compare September 15, 2026 13:49
@HatemMn HatemMn changed the title [AUDIT SINK PART 2] Feat/audit sink generalize [AUDIT SINK PART 2] File implements audit Sink Trait Sep 15, 2026
@Manuthor
Manuthor removed this pull request from stack #1196 September 15, 2026 16:28
@HatemMn
HatemMn requested a review from Manuthor September 15, 2026 17:50
@HatemMn
HatemMn added this pull request to stack #1200 September 16, 2026 12:33
@HatemMn
HatemMn force-pushed the feat/audit-sink-generalize branch from 8ac88da to b51becd Compare September 16, 2026 14:18

@Manuthor Manuthor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review for PR #1190 (feat/audit-sink-generalize against feat/audit-sink-refactor):

The generalization of AuditStore over the async AuditSink trait is clean and sound. Moving recovery and exclusive lock handling into FileSink::resume() preserves the non-blocking startup contract. Below are specific in-scope suggestions.

Comment thread crate/server/src/core/audit/file_sink.rs Outdated
)
.await;
}
Err(e) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In AuditFileStore::start_with_max_size(), if sink.resume().await returns an error (e.g. if an unforeseen non-recoverable error occurs in a third-party sink), the error is logged and the spawned task terminates. However, any callers who subsequently call enqueue() will have their events queued up to channel capacity and then dropped with channel full warnings. Consider exposing or tracking a sink failure state so enqueue() or health checks can distinguish between a busy channel and a dead writer task.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Consider exposing or tracking a sink failure state so enqueue() or health checks can distinguish between a busy channel and a dead writer task.

Implementing that function wasn't hard but did you in an indirect manner suggest to modify health.rs by adding the audit as a dependency ? I see that database is already added as dependency

image

I will push my code to another branch, please tell me this is what your required or not because I am not so sure (without that, the 'addition' will become dead code)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replace the private, file-only mock AuditSink trait with the public async
cosmian_kms_interfaces::AuditSink defined in the previous commit:

- FileSink: AuditSink wraps the file backend (lock+recover retry loop moves
  from writer_supervisor into FileSink::resume(), never returns Err in
  practice — preserves the always-start/self-heal behavior exactly).
- write_failure_is_fatal() = false (preserves the file backend's historical
  log-and-continue behavior).
- Added AuditSink::is_write_capacity_exceeded() (default false) so the
  generic writer loop can skip a write without an error-per-event log spam;
  FileSink is the only implementor that ever returns true (max_size_bytes cap).
- writer_loop/write_draft_to_chain are now generic over any AuditSink and
  fully backend-agnostic (no file-specific cap/path knowledge left).
- Added AuditEventDraft::finalize() (cosmian_kms_access) to share the
  draft->AuditEvent+row_hash computation between the async steady-state
  writer and the sync recovery-time sentinel writer (torn-write/reanchor),
  which runs inside spawn_blocking with no async runtime available.
- AuditFileStore's public API (start/start_with_max_size/enqueue/flush/
  new_disconnected) is unchanged; no consumer (middleware, kms/mod.rs,
  tests) needed changes.

All 47 audit tests (access + core::audit + middleware + integration) green,
clippy clean, no behavior change observed in file-backend tests.
update_log_index.py --check was failing on this branch: 2 stale entries (superseded by the resume() rewrite) and 4 new entries (from the earlier resume()/store.rs fixes) were undocumented. Not caused by the rebase — pre-existing gap from an earlier direct fix that never ran the doc-sync tool.
…unparsable

Caught by the typos pre-commit hook (not installed until now, hence never enforced on this stack). Same misspelling already exists on develop's file_store.rs, unrelated to this rebase. The one other repo occurrence (crate/clients/clap/src/actions/audit.rs) is a static test fixture string, not coupled to this enum — left untouched.
@HatemMn
HatemMn force-pushed the feat/audit-sink-generalize branch from b51becd to 90dce08 Compare September 21, 2026 13:08
@HatemMn
HatemMn deployed to xks-remote-approval September 21, 2026 13:08 — with GitHub Actions Active
@HatemMn
HatemMn deployed to xks-remote-approval September 21, 2026 14:09 — with GitHub Actions Active

@HatemMn HatemMn left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

)
.await;
}
Err(e) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@HatemMn HatemMn assigned HatemMn and Manuthor and unassigned Manuthor Sep 21, 2026
@HatemMn HatemMn removed their assignment Sep 21, 2026

This branch was successfully deployed

1 active deployment
xks-remote-approval 914d8d75 Deployed Sep 21, 2026 by HatemMn via main / test / AWS XKS — remote server #8713
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