Repository navigation
Conversation
|
cc @dscho |
dscho
left a comment
There was a problem hiding this comment.
Thank you for tackling this. It's obviously a better idea to support explicit /reply commands than what I dreamed up in #154.
I have a couple of suggestions below and I do have to say even if I try to I really cannot love your commit message. Would you mind following the guidance in https://github.blog/2022-06-30-write-better-commits-build-better-projects/ to improve it, in particular with a strong focus on this part:
| What you’re doing | Why you’re doing it | |
|---|---|---|
| High-level (strategic) | Intent (what does this accomplish?) | Context (why does the code do what it does now?) |
| Low-level (tactical) | Implementation (what did you do to accomplish your goal?) | Justification (why is this change being made?) |
| // Reserve quota before the side effect. A failed SMTP attempt still consumes the slot, | ||
| // which prevents retries from bypassing the limit. |
There was a problem hiding this comment.
Interesting idea to have a daily quota and a daily quota per user.
But maybe a better idea would be to limit this /reply command to the PR owner. Only the PR owner can reply to a mail, and only if the mail actually is recorded as being part of the thread associated with the PR (We track the involved Message-IDs in the notes ref, see e.g. gitgitgadget/git@6ad9656).
There was a problem hiding this comment.
This idea to limit /reply to the PR author has prior art in /submit only allowing the PR author to submit the patch series.
| } | ||
|
|
||
| /** Send an explicitly approved reply to a mail already associated with this PR. */ | ||
| public async replyToMail( |
There was a problem hiding this comment.
Wouldn't this function live much, much more happily next to its sibling sendMail() in send-email.ts?
| const replyMatch = argument.match(/^<?([^>\s]+@[^>\s]+)>?\s*\n([\s\S]*)$/); | ||
| if (!replyMatch) { | ||
| throw new Error("Usage: /reply <message-id> followed by the reply text on the next line"); | ||
| } |
There was a problem hiding this comment.
I do think that this needs to be validated against the stored message IDs. And since I already proposed that we allow the /reply command only for emails that are associated with the current PR, that would be easy to verify: If the gitgitgadget notes ref has a mapping to this PR, then it's good to go. And if there is no such mapping (or to another PR), then nope, no /reply for you.
| await addComment(`Preview email sent as ${metadata?.coverLetterMessageId}`); | ||
| } | ||
| } else if (command === "/reply") { | ||
| const replyMatch = argument.match(/^<?([^>\s]+@[^>\s]+)>?\s*\n([\s\S]*)$/); |
There was a problem hiding this comment.
I am immediately reminded of the old programmer joke. When you think you have a problem that you can solve by regular expressions, you end up with two problems. In other words, can we do this more robustly, first splitting at the first run of whitespace characters?
| ? cleanSubject | ||
| : `Re: ${cleanSubject}` | ||
| : "Re: [PATCH]"; | ||
| const id = `reply.${Date.now()}.${Math.random().toString(16).slice(2)}@gitgitgadget.github.io`; |
There was a problem hiding this comment.
That's by far not random enough. These Message-IDs can be used by anybody, and the only way to avoid somebody already having used your Message-ID is to make it random enough.
Speaking of message ID, the message ID of the reply should of course be associated with the current PR, stored in the gitgitgadget notes ref.
There was a problem hiding this comment.
Oh, and we also need to Cc all the involved parties in that reply, i.e. coalescing a Cc: list from the To: and Cc: headers of the email we're replying to.
There was a problem hiding this comment.
Oh, and we also need to Cc all the involved parties in that reply, i.e. coalescing a
Cc:list from theTo:andCc:headers of the email we're replying to.
By which I mean: We need to parse and store that information, too. And backfill that, in addition to the subject.
It might be honestly easier to use the fact that we have a mailing list mirror from which we could obtain the entire original email. We only need a mapping from Message-ID to blob OID, which would be easy to maintain (and to back-fill).
There was a problem hiding this comment.
Should we use corresponding PR as Message-ID?
There was a problem hiding this comment.
Should we use corresponding PR as Message-ID?
@kairosci I do think that we need to imitate the existing Message-IDs a little bit more. Notice how every patch gets a message ID that's based on its commit for ID and a timestamp to provide some randomness just to make it unique (and unlikely to clash with maliciously-crafted mails other people might send to the Git mailing list)? Likewise, the cover letters get the actual PR and then also timestamp and random characters to make it unique.
See e.g. https://lore.kernel.org/git/pull.2425.v11.git.git.1795611175.gitgitgadget@gmail.com/, which has Message-ID pull.2425.v11.git.git.1795611175.gitgitgadget@gmail.com and its first patch has Message-ID ea62fc8787a2e5c407b1558d293e914688ff3a68.1795611175.git.gitgitgadget@gmail.com.
Since ultimately every email that we are replying to is based on one of those generated ones, we should probably use those and transform them into the reply's Message-ID. Maybe prefix with reply. (as you already did) and then another timestamp to provide randomness?
| await this.gggNotes.set(parsed.messageID, { | ||
| issueCommentId, | ||
| messageID: parsed.messageID, | ||
| subject: parsedMbox.subject, |
There was a problem hiding this comment.
I fear there is a problem here: Only after this has been merged, newly arriving emails will be stored with their subject. All pre-existing emails will not have a subject at all. How to deal with that? Should we backfill that? Then we need a one off script that derives the subjects, which could be done using a bare clone of gitgitgadget/git-mailing-list-mirror. But it won't be a cheap run.
There was a problem hiding this comment.
This is still true.
I highly recommend going the other route I recommended: To create and maintain a Message-ID -> blob OID map, which would e.g. map pRWo4Tw9YFIfXYAp-9Mj2dktr8BL5TIZT3pKYwIljnb4WujAajPZVrpdTLivqm0YZ-ydfpq1WY5gqara_1l9T7h1Ml5BR7E0SJQs6Rn9-jo=@protonmail.com to the blob OID of https://github.com/gitgitgadget/git-mailing-list-mirror/blob/d71faef4116f23ca3ee09e3533499ee4c7d7ccac/m.
That way, we can always retrieve easily, and fast, the full mbox file for any email, keyed on its Message-ID.
I really don't think that it'd be a good idea to store all this information in GitGitGadget's notes that you need to reply to an email properly, it's much better to get that information from the original.
|
Oh, and of course we also need a corresponding PR in the GitHub App, adjusting [this line[(https://github.com/gitgitgadget/gitgitgadget-github-app/blob/7263390faa6c63558291b6e211d83bd94ad9ec51/GitGitGadget/index.js#L106): if (!comment.body || !comment.body.match(/^\/(submit|preview|allow|disallow|test|cc)\b/)) { |
There was a problem hiding this comment.
@kairosci commit cc90afe rubs me in all the wrong ways. It's probably authored by AI, right?
It solves a problem that has already been solved. It makes sweeping, vast, verbose, and totally unreviewable changes for no good reason. I think we have to stick with more elegant code here. And if we can't make the code more elegant, we have to reconsider the strategy and settle for an easier one. And I think we already have an easier one. We don't have to add epicycles on top of epicycles just to make the quota work. I don't think the quota idea is going to fly, ever.
And please do re-review the commit message. The commit message is not in a good shape. It's totally different from the rest of 'em. It's a one-liner with way too little information. It doesn't integrate well with the other commit messages that we enjoy in this here project.
| function asTextCodeBlock(text: string): string { | ||
| const backtickRuns = text.match(/`+/g) || []; | ||
| const fence = "`".repeat(Math.max(3, ...backtickRuns.map((run) => run.length + 1))); | ||
| return `${fence}text\n${text}\n${fence}`; | ||
| } | ||
|
|
There was a problem hiding this comment.
What does this function have to do with making reply approvals and quotas concurrecy-safe?
| await addComment( | ||
| [ | ||
| `Draft ${commentID} captured. Review this exact snapshot, then approve it by posting ` + | ||
| `\`/send-reply ${commentID}\`. No email has been sent yet.`, | ||
| `Send limits: ${perUserLimit} per user and ${dailyLimit} total per UTC day; ` + | ||
| `SMTP attempts are capped at twice those limits.`, | ||
| "", | ||
| asTextCodeBlock(replyBody), | ||
| ].join("\n"), |
There was a problem hiding this comment.
Hrm. I fail to appreciate that two-step /reply -> /send-reply strategy. It strikes me as unnecessarily over-complicated. I understand that you want to rescue the daily quota idea, but I don't think it's worth saving that idea.
| /** Refresh this notes ref from its remote tip. */ | ||
| public async fetchRemote(url: string, token?: string): Promise<string> { | ||
| await git([...this.authArgs(token), "fetch", "--no-tags", url, `+${this.notesRef}:${this.notesRef}`], { | ||
| workDir: this.workDir, | ||
| }); | ||
| const head = await revParse(this.notesRef, this.workDir); | ||
| if (!head) throw new Error(`Remote notes ref ${this.notesRef} is missing`); | ||
| return head; | ||
| } | ||
|
|
||
| /** Compare-and-set the remote notes tip, allowing only an update based on expectedHead. */ | ||
| public async pushIfCurrent(url: string, expectedHead: string, token?: string): Promise<void> { | ||
| await git( | ||
| [ | ||
| ...this.authArgs(token), | ||
| "push", | ||
| `--force-with-lease=${this.notesRef}:${expectedHead}`, | ||
| url, | ||
| `${this.notesRef}:${this.notesRef}`, | ||
| ], | ||
| { workDir: this.workDir }, | ||
| ); | ||
| } |
There was a problem hiding this comment.
As part of the migration from an Azure Pipeline (that had a guaranteed single runner) to GitHub workflows (which don't have guaranteed single runners) I already implemented logic which gracefully handles pushes that fail because they don't fast-forward: If it didn't work, it would replay the notes edits automatically. So I don't think we need any of this.
cc90afe to
0d2876a
Compare
0d2876a to
0033df8
Compare
|
@dscho I believe I updated /reply based on the review feedback. The command is limited to the PR owner and accepts only emails associated with the PR. Replies preserve the original headers and recipients, use a unique Message-ID, and store the required metadata, with a backfill for archived emails. I removed the quota and the extra approval step. Hope this works better now! |
dscho
left a comment
There was a problem hiding this comment.
Sorry, I already spent way more time on this review than I actually had today. And the current single commit that does many, many things at the same time prevents me from looking at this further today.
I can already say this, it needs to be split. Into more than one commit.
When you refactor, you need to refactor in an individual commit, otherwise, it's not reviewable.
When you extend the functionality of a refactored function, you have to do that in an individual commit, with a commit message explaining what it's good for.
When you adjust a workflow to make use of functionality that you have just introduced, that workflow change needs to be an individual commit.
Likewise the adjustment to the welcome message. And the backfill script. And all the things that live very unhappily together in a single commit because they are different concerns and they all want to have their own commit to themselves with a really good commit message that first and foremost compels the reader to read on, that motivates why the changes are good and should be accepted.
I know that it is easy for AI to write many, many, many changes in one go and make only one commit. But just because it's easier doesn't make it right. It is your responsibility as the human operator to rein in those really bad tendencies of AI. You have to insert some sanity there.
I'm excited about the goal and that you are working toward it. I'm not yet excited about the shape of the changes. And I hope that you will work on it so that the shape is good, that it's fun to read, that it's easy to review, that the PR makes for a delightful story arc.
0033df8 to
e5f766c
Compare
|
I believe I have resolved everything; I hope everything works properly now. |
| const metadata = await gitGitGadget.preview(pr, userInfo); | ||
| await addComment(`Preview email sent as ${metadata?.coverLetterMessageId}`); | ||
| } | ||
| } else if (command === "/reply") { |
There was a problem hiding this comment.
Then that matcher should probably be changed from .* to [^]*, which does match line-breaks, if I remember correctly.
CI needs the mailing-list mirror both when it processes incoming mail and when a PR owner replies to an archived message. Move mirror setup into a helper so both paths use the same configuration. Keep the existing full-history behavior by default, while allowing a lookup-only caller to avoid an unnecessary unshallow fetch.
Sending a reply uses the same configured SMTP account and transport options as sending a patch series. Extract transport construction so both mail paths can share it, and validate the static configuration before recording a reply attempt. Preserve the existing sendMail path.
586a692 to
66acdd0
Compare
|
@dscho I reworked the branch into nine commits, with each message explaining why the change is needed and how it addresses the problem. /reply is limited to the PR owner and messages associated with that PR. It fetches the original email from the mailing-list mirror by Message-ID, preserving the thread and participants, and records a Message-ID-to-blob-OID mapping for quick lookup. I also fixed multiline command parsing and removed the obsolete metadata backfill. |
Replying to a mailing-list message needs its original headers and body, but GitGitGadget notes should not duplicate those mail fields. Store only the mirror's mbox blob OID beside each existing Message-ID association, then read the source email from the mirror when replying. Record the mapping as new messages are archived and fill it when an already-known message is encountered again.
Existing PR mail notes have a Message-ID association but predate the archive blob OID mapping. Scan the mailing-list mirror's history, match each archived mbox by Message-ID, and store only its blob OID in the corresponding note. This one-off scan lets reply commands retrieve historical messages from the mirror without copying their headers or bodies into GitGitGadget notes.
PR owners need to answer review mail without leaving the pull request. Build replies from the archived message so the subject, references and participants stay with the original thread, and use a unique Message-ID for every reply. Record the reply Message-ID against the PR before sending so a retried command does not send the same reply twice. Cover reply-all recipients and multiline text in the mail tests.
PR owners need a direct way to continue a mailing-list thread from the PR. Add the /reply <message-id> command with the reply text on following lines, allow it only for the PR owner, and require the source Message-ID to be associated with that PR. Load the original mbox from the mirror using its recorded blob OID, then pass it to the shared reply sender. Keep command parsing multiline-aware and split the target ID from the reply at the first whitespace.
PR owners need to know how to start a reply and which messages they can answer. Document the /reply syntax, ownership and association checks, and the one-time migration needed for messages archived before the blob mapping existed. The migration records only Message-ID to archive blob OID mappings. Reply headers and recipients continue to come from the original mbox.
New contributors may not know that they can answer a mirrored mailing- list email from the PR. Add the `/reply` syntax and its ownership and message-association requirements to the welcome instructions.
66acdd0 to
21b985c
Compare
No description provided.