Skip to content

fix(preview): only update preview comments written by the token's own identity - #1361

Merged
BryanFRD merged 1 commit into
mainfrom
fix/preview-comment-own-identity
Oct 31, 2026
Merged

BryanFRD merged 1 commit into
mainfrom
fix/preview-comment-own-identity

Conversation

@BryanFRD

Copy link
Copy Markdown
Contributor

Closes #1345

find_comment matched the first comment carrying the invisible marker, whoever wrote it, so a human comment containing it got overwritten and the real preview went stale.

It now resolves the token's identity with GET /user (only when a marked comment exists) and returns the most recent marked comment written by that identity. A 5xx on that lookup fails the step with a warning rather than guessing.

GitLab had the same bug, so it gets the same fix even though the issue only names GitHub and Gitea.

When /user returns 401/403, the identity is unknown:

  • GitHub (GITHUB_TOKEN, app installation tokens): matches any author of type Bot. This differs from the github-actions[bot] / ferrflow[bot] list suggested in the issue, which would post a new comment on every push for a custom GitHub App. Humans are protected, but another bot's comment carrying the marker can still be matched.
  • Gitea and GitLab: matches nothing, warns and posts a new comment, so a token without user read access now gets one new comment per push.

The GraphQL viewer query was not used: its behaviour with integration tokens could not be confirmed, and {api_base}/graphql is wrong on GHES.

Tested against the fake forge server only. The 403 for GITHUB_TOKEN on /user was not exercised on a real runner.

… identity

Signed-off-by: BryanFRD <bryanferrando59@gmail.com>
@BryanFRD
BryanFRD enabled auto-merge (squash) October 31, 2026 10:08

@ferrfleet-interne ferrfleet-interne Bot 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.

Approve: the ownership filter is correct on all three forges. I left two nits.

Comment thread src/forge/rest.rs
fn wrote(&self, comment: &serde_json::Value) -> bool {
let author = &comment["user"];
match self {
Self::Login(login) => author["login"].as_str() == Some(login),

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.

Nit: with an integration token, AnyBot still matches a marked comment from a different app (e.g. another bot quoting the marker). It now wins as the most recent one, and the PATCH then fails with 403, which is the same failure this PR fixes, only narrower. Not blocking since /user can't identify an installation token. If you want to close it, have the update path fall back to create_comment on a 403.

Comment thread src/forge/gitlab.rs
Comment on lines +261 to +263
tracing::warn!(
"Warning: the token cannot read its own user, posting a new note instead of updating one"
);

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.

Nit: the other Warning: in this file is rendered with .yellow(). Matching that style:

Suggested change
tracing::warn!(
"Warning: the token cannot read its own user, posting a new note instead of updating one"
);
tracing::warn!(
"{}",
"Warning: the token cannot read its own user, posting a new note instead of updating one"
.yellow()
);

@ferrfleet-interne

Copy link
Copy Markdown
Contributor

Ready to merge. The review approved this PR with two non-blocking suggestions. Formal verification did not run: that step failed and returned no result, so nothing is verified formally.

The change makes preview comment lookup match only comments written by the token's own identity on GitHub, Gitea and GitLab. If /user is unreadable (401/403), the lookup falls back: GitHub integration tokens match bot comments only, while Gitea and GitLab match nothing and post a new comment. Other errors from the identity lookup are propagated. Tests cover foreign comments, the most recent own comment, the unreadable-user case and the server-error case.

Suggestions

  • src/forge/rest.rs:24: with a GitHub integration token, the AnyBot fallback can select a newer marked comment from a different bot. The following PATCH then fails with 403. Suggested fix: on a 403 from update_comment, fall back to create_comment.
  • src/forge/gitlab.rs:261: the new warning is not styled like the other Warning: messages in this file, which use .yellow(). Suggested fix: tracing::warn!("{}", "...".yellow()).

Formal verification

Property Result
All Step failed, no result

@BryanFRD
BryanFRD merged commit b512611 into main Oct 31, 2026
34 checks passed
@BryanFRD
BryanFRD deleted the fix/preview-comment-own-identity branch October 31, 2026 10:10
ferrflow Bot added a commit that referenced this pull request Oct 31, 2026
## [7.35.2] - 2026-10-31

### Bug Fixes

- fix(preview): only update preview comments written by the token's own identity (#1361)
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.

fix(preview): only update preview comments written by the token's own identity

1 participant