forge
Explore
Log in

Don't you dare go Hollow

An approval counts only while the PR head is the commit it was given on, so a push after review needs a new approval

Browse files at this commit

2e6d8a0ee86879c112f87c1fb61727c79e35586cAhmet Kaan Gümüş and ClaudeParent: 9a27aab
Some checks failed
Show checks
  • harden
    • an approval counts only while the PR head is the commit it was given on, so a push after review needs a new approval
    • the merge queue checks reviews again right before it lands an entry
    • a job's artifacts together are capped at 2 GiB (ci.max_job_artifacts_mb, on the limits page)
Show full message
🔒 harden: an approval counts only while the PR head is the commit it was given on, so a push after review needs a new approval; the merge queue checks reviews again right before it lands an entry; a job's artifacts together are capped at 2 GiB (ci.max_job_artifacts_mb, on the limits page)
crates/forge-core/src/config.rsmodified+3 -0
@@ -364,6 +364,8 @@ pub struct CiConfig {
364364 pub max_artifact_mb: u64,
365365 /// Artifacts a single job may upload.
366366 pub max_artifacts_per_job: u32,
367+ /// Largest total size of one job's artifacts, in MiB.
368+ pub max_job_artifacts_mb: u64,
367369 /// Days a job log is kept.
368370 pub log_retention_days: u64,
369371 /// Days an artifact is kept.
@@ -387,6 +389,7 @@ impl Default for CiConfig {
387389 max_log_mb: 16,
388390 max_artifact_mb: 512,
389391 max_artifacts_per_job: 50,
392+ max_job_artifacts_mb: 2048,
390393 log_retention_days: 90,
391394 artifact_retention_days: 30,
392395 artifact_keep_runs: 10,
crates/forge-core/src/server_settings.rsmodified+10 -0
@@ -286,6 +286,14 @@ pub static FIELDS: &[Field] = &[
286286 "Artifacts per job",
287287 "",
288288 ),
289+ f(
290+ "ci.max_job_artifacts_mb",
291+ Limits,
292+ L,
293+ MB,
294+ "Largest total of one job's artifacts (MiB)",
295+ "",
296+ ),
289297 f(
290298 "ci.log_retention_days",
291299 Limits,
@@ -882,6 +890,7 @@ pub fn get(cfg: &Config, key: &str) -> String {
882890 "ci.max_log_mb" => cfg.ci.max_log_mb.to_string(),
883891 "ci.max_artifact_mb" => cfg.ci.max_artifact_mb.to_string(),
884892 "ci.max_artifacts_per_job" => cfg.ci.max_artifacts_per_job.to_string(),
893+ "ci.max_job_artifacts_mb" => cfg.ci.max_job_artifacts_mb.to_string(),
885894 "ci.log_retention_days" => cfg.ci.log_retention_days.to_string(),
886895 "ci.artifact_retention_days" => cfg.ci.artifact_retention_days.to_string(),
887896 "ci.artifact_keep_runs" => cfg.ci.artifact_keep_runs.to_string(),
@@ -996,6 +1005,7 @@ pub fn set(cfg: &mut Config, key: &str, raw: &str) -> Result<()> {
9961005 "ci.max_log_mb" => cfg.ci.max_log_mb = n(v),
9971006 "ci.max_artifact_mb" => cfg.ci.max_artifact_mb = n(v),
9981007 "ci.max_artifacts_per_job" => cfg.ci.max_artifacts_per_job = n(v) as u32,
1008+ "ci.max_job_artifacts_mb" => cfg.ci.max_job_artifacts_mb = n(v),
9991009 "ci.log_retention_days" => cfg.ci.log_retention_days = n(v),
10001010 "ci.artifact_retention_days" => cfg.ci.artifact_retention_days = n(v),
10011011 "ci.artifact_keep_runs" => cfg.ci.artifact_keep_runs = n(v) as u32,
crates/forge-core/src/store/reviews.rsmodified+11 -9
@@ -804,7 +804,7 @@ impl Store {
804804 /// lets the reviewer's earlier, undismissed state count again.
805805 pub async fn review_summary(&self, issue_id: &str) -> Result<ReviewSummary> {
806806 let mut summary = ReviewSummary::default();
807- for (_, name, state) in self.latest_review_states(issue_id).await? {
807+ for (_, name, state, _) in self.latest_review_states(issue_id).await? {
808808 match state {
809809 ReviewState::Approved => summary.approved_by.push(name),
810810 _ => summary.changes_requested_by.push(name),
@@ -816,15 +816,16 @@ impl Store {
816816 }
817817
818818 /// Each reviewer's latest non-commented, non-dismissed submitted state, as
819- /// `(author_id, username, state)`, ordered by author id.
819+ /// `(author_id, username, state, commit_oid)`, ordered by author id. `commit_oid` is the head
820+ /// the review was submitted on.
820821 pub async fn latest_review_states(
821822 &self,
822823 issue_id: &str,
823- ) -> Result<Vec<(String, String, ReviewState)>> {
824+ ) -> Result<Vec<(String, String, ReviewState, String)>> {
824825 let conn = self.read_conn().await;
825826 let rows = fetch_all(
826827 &conn,
827- "SELECT r.author_id, u.username, r.state FROM pull_reviews r \
828+ "SELECT r.author_id, u.username, r.state, r.commit_oid FROM pull_reviews r \
828829 JOIN users u ON u.id = r.author_id WHERE r.issue_id = ?1 \
829830 AND r.state IN ('approved', 'changes_requested') ORDER BY r.submitted_at, r.id",
830831 (issue_id.to_string(),),
@@ -833,18 +834,19 @@ impl Store {
833834 col_text(row, 0)?,
834835 col_text(row, 1)?,
835836 parse_db::<ReviewState>(&col_text(row, 2)?)?,
837+ col_text(row, 3)?,
836838 ))
837839 },
838840 )
839841 .await?;
840842 // Rows are in submission order, so the last one per reviewer is the latest.
841- let mut latest: HashMap<String, (String, ReviewState)> = HashMap::new();
842- for (author_id, name, state) in rows {
843- latest.insert(author_id, (name, state));
843+ let mut latest: HashMap<String, (String, ReviewState, String)> = HashMap::new();
844+ for (author_id, name, state, commit) in rows {
845+ latest.insert(author_id, (name, state, commit));
844846 }
845- let mut out: Vec<(String, String, ReviewState)> = latest
847+ let mut out: Vec<(String, String, ReviewState, String)> = latest
846848 .into_iter()
847- .map(|(id, (name, state))| (id, name, state))
849+ .map(|(id, (name, state, commit))| (id, name, state, commit))
848850 .collect();
849851 out.sort_unstable_by(|a, b| a.0.cmp(&b.0));
850852 Ok(out)
crates/forge-web/src/ci/api.rsmodified+23 -1
@@ -886,7 +886,29 @@ async fn upload(state: &AppState, job: &CiJob, name: &str, body: Body) -> Result
886886 )));
887887 }
888888
889- let max_bytes = state.live().ci.max_artifact_mb.saturating_mul(MIB);
889+ // One artifact is held to its own limit and to what is left of the job's total.
890+ let used: u64 = existing
891+ .iter()
892+ .map(|artifact| u64::try_from(artifact.size).unwrap_or(0))
893+ .sum();
894+ let left = state
895+ .live()
896+ .ci
897+ .max_job_artifacts_mb
898+ .saturating_mul(MIB)
899+ .saturating_sub(used);
900+ if left == 0 {
901+ return Err(Box::new(api::error(
902+ StatusCode::CONFLICT,
903+ "the job's artifacts have reached their total size limit",
904+ )));
905+ }
906+ let max_bytes = state
907+ .live()
908+ .ci
909+ .max_artifact_mb
910+ .saturating_mul(MIB)
911+ .min(left);
890912 let temp_key = format!("ci/tmp/{}", ulid::Ulid::generate());
891913 let mut writer = state
892914 .blobs
crates/forge-web/src/i18n/server_settings.rsmodified+1 -0
@@ -63,6 +63,7 @@ pub fn field_tr(key: &str) -> Option<(&'static str, &'static str)> {
6363 ),
6464 "ci.max_artifact_mb" => ("En büyük yapıt (MiB)", ""),
6565 "ci.max_artifacts_per_job" => ("İş başına yapıt", ""),
66+ "ci.max_job_artifacts_mb" => ("Bir işin yapıtlarının toplamı en çok (MiB)", ""),
6667 "ci.log_retention_days" => ("Günlük saklama süresi (gün)", ""),
6768 "ci.artifact_retention_days" => ("Yapıt saklama süresi (gün)", ""),
6869 "ci.artifact_keep_runs" => (
crates/forge-web/src/merge_queue.rsmodified+6 -0
@@ -347,6 +347,12 @@ async fn land(
347347 finish_removed(state, repo, entry, "permission").await?;
348348 return Ok(true);
349349 }
350+ // Reviews may have changed while the candidate was tested (a change request, a dismissed
351+ // approval): the same readiness test as before testing, now right before the target moves.
352+ if let Some(reason) = unready(state, repo, pr).await? {
353+ finish_removed(state, repo, entry, reason).await?;
354+ return Ok(true);
355+ }
350356 let refname = format!("refs/heads/{}", entry.branch);
351357 let base_path = repo_path(&state.git.data_dir, &repo.id)?;
352358 match update_ref_cas(&state.git, &base_path, &refname, &tested, &base).await {
crates/forge-web/src/pages/pulls_merge.rsmodified+8 -2
@@ -310,7 +310,8 @@ impl MergeGate {
310310 }
311311
312312 /// Evaluates the effective rule for the pull request's base branch. Approvals and change requests
313-/// count only from `counts_for_merge_rules` reviewers, using each reviewer's latest review.
313+/// count only from `counts_for_merge_rules` reviewers, using each reviewer's latest review; an
314+/// approval counts only while the head is the commit it was given on.
314315 /// Repo admins are not exempt. A base branch that does not exist counts as up to date; the merge
315316 /// itself reports that.
316317 pub async fn merge_gate(
@@ -322,7 +323,12 @@ pub async fn merge_gate(
322323 let rule = effective(&rules, &repo.default_branch, &pr.base_branch);
323324 let mut approvals = 0u32;
324325 let mut changes_requested = false;
325- for (author_id, _, review) in state.store.latest_review_states(&pr.issue.id).await? {
326+ for (author_id, _, review, commit) in state.store.latest_review_states(&pr.issue.id).await? {
327+ // An approval is of the commits the reviewer saw: a push after it leaves it uncounted
328+ // until they approve again. A change request stands until it is dismissed or replaced.
329+ if review == ReviewState::Approved && commit != pr.head_oid {
330+ continue;
331+ }
326332 let Some(reviewer) = state.store.user_by_id(&author_id).await? else {
327333 continue;
328334 };
docs/ci.mdmodified+1 -0
@@ -762,6 +762,7 @@ enabled = true
762762 max_log_mb = 16 # a log past this is cut with "[log truncated]"
763763 max_artifact_mb = 512 # per artifact
764764 max_artifacts_per_job = 50
765+max_job_artifacts_mb = 2048 # all of one job's artifacts together
765766 log_retention_days = 90
766767 artifact_retention_days = 30
767768 artifact_keep_runs = 10 # artifacts of the newest N runs per repo (that have any) are kept; 0 keeps all