txmap 3.1.5

A concurrent transactional hash map for Rust with fine-grained locking, internal mutability and composable transactions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
name: Agent

# Restrict the default GITHUB_TOKEN permissions
permissions:
  contents: read

on:
  issues:
    types: [edited, opened, reopened]
  issue_comment:
    types: [created, edited]

# Prevent multiple agents editing the branch at the same time
concurrency:
  group: agent-${{ github.event.issue.number }}
  cancel-in-progress: false

jobs:
  triage:
    if: |
      (github.event_name == 'issues' && (contains(github.event.issue.title, '@agent') || contains(github.event.issue.body, '@agent'))) ||
      (github.event_name == 'issue_comment' && (contains(github.event.comment.body, '@agent')))
    runs-on: ubuntu-latest
    timeout-minutes: 10
    permissions:
      contents: write
      id-token: write
      issues: write
    outputs:
      issue-branch-base: ${{ steps.gather-branches.outputs.issue-branch-base }}
      issue-branch: ${{ steps.gather-branches.outputs.issue-branch }}
      address-issue-base64: ${{ steps.prompts.outputs.address-issue-base64 }}
      classify-request-base64: ${{ steps.prompts.outputs.classify-request-base64 }}
      classify-response-base64: ${{ steps.prompts.outputs.classify-response-base64 }}
      extra-information-required-base64: ${{ steps.prompts.outputs.extra-information-required-base64 }}
      information-list-base64: ${{ steps.schemas.outputs.information-list-base64 }}
      request-classification-base64: ${{ steps.schemas.outputs.request-classification-base64 }}
      response-classification-base64: ${{ steps.schemas.outputs.response-classification-base64 }}
      issue-context-base64: ${{ steps.gather-context.outputs.context-base64 }}
      request-type: ${{ steps.save-request-type.outputs.request-type }}
    steps:
      - name: Infisical
        uses: Infisical/secrets-action@v1.0.16
        with:
          method: "oidc"
          identity-id: "c603d49b-292c-42ae-b838-52e03e3c3a84"
          project-slug: "agents"
          env-slug: "dev"

      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v3
        env:
          GITHUB_APP_AGENT_HELPER_CLIENT_ID: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          GITHUB_APP_AGENT_HELPER_PRIVATE_KEY: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}
        with:
          client-id: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          private-key: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}

      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          token: ${{ steps.app-token.outputs.token }}

      - name: Remove all previous reactions from issue and comment
        uses: ./.github/actions/remove-emoji-reactions
        with:
          comment-id: ${{ github.event.comment.id }}
          issue-number: ${{ github.event.issue.number }}
          token: ${{ steps.app-token.outputs.token }}

      - name: Acknowledge
        uses: ./.github/actions/emoji-react
        with:
          comment-id: ${{ github.event.comment.id }}
          issue-number: ${{ github.event.issue.number }}
          reaction: 'eyes'
          token: ${{ steps.app-token.outputs.token }}

      - name: Gather issue branches
        id: gather-branches
        uses: ./.github/actions/gather-issue-branches
        with:
          issue-number: ${{ github.event.issue.number }}
          issue-branch-base: ${{ github.event.repository.default_branch }}

      - name: Save base64 prompts
        id: prompts
        run: |
          {
            echo "address-issue-base64=$(base64 -w 0 < .github/prompts/address-issue.txt)"
            echo "classify-request-base64=$(base64 -w 0 < .github/prompts/classify-request.txt)"
            echo "classify-response-base64=$(base64 -w 0 < .github/prompts/classify-response.txt)"
            echo "extra-information-required-base64=$(base64 -w 0 < .github/prompts/extra-information-required.txt)"
          } >> "$GITHUB_OUTPUT"

      - name: Save base64 schemas
        id: schemas
        run: |
          {
            echo "information-list-base64=$(base64 -w 0 < .github/schemas/information-list.json)"
            echo "request-classification-base64=$(base64 -w 0 < .github/schemas/request-classification.json)"
            echo "response-classification-base64=$(base64 -w 0 < .github/schemas/response-classification.json)"
          } >> "$GITHUB_OUTPUT"

      - name: Get last 50 comments
        id: gather-context
        uses: actions/github-script@v9
        with:
          script: |
            const { data: issue } = await github.rest.issues.get({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number
            });
            const comments = [];
            for await (const response of github.paginate.iterator(
              github.rest.issues.listComments,
              {
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.issue.number,
                per_page: 100
              }
            )) {
              comments.push(...response.data);
            }
            // Only send the most recent comments to the model: the full history
            // of a long-lived issue can be huge (cost, tokens and job output
            // size), and older comments are rarely relevant.
            const history = comments.slice(-50).map(comment => ({
              author: comment.user.login,
              date: comment.created_at,
              body: comment.body,
            }));
            const issueContext = {
              title: issue.title,
              body: issue.body,
              history
            };
            const stringified = JSON.stringify(issueContext);
            const context_base64 = Buffer.from(stringified).toString('base64');
            core.setOutput('context-base64', context_base64);

      - name: Set up DeepSeek via pi
        uses: ./.github/actions/set-up-deepseek-via-pi
        env:
          DEEPSEEK_API_KEY: ${{ env.DEEPSEEK_API_KEY }}

      - name: Classify request
        id: classify-request
        uses: ./.github/actions/question-pi
        with:
          context-base64: ${{ steps.gather-context.outputs.context-base64 }}
          prompt-base64: ${{ steps.prompts.outputs.classify-request-base64 }}
          schema-base64: ${{ steps.schemas.outputs.request-classification-base64 }}

      - name: Save request type
        id: save-request-type
        run: |
          REQUEST_TYPE=$(echo "${{ steps.classify-request.outputs.response-base64 }}" | base64 -d | jq -r .request_type)
          # Guard against unexpected model output: default to OTHER so the user
          # always gets a visible response instead of a silent no-op.
          case "${REQUEST_TYPE}" in
            BUG_FIX|CHANGE_REQUEST|FEATURE_REQUEST|INVESTIGATION|QUESTION|SPAM|CAN_IGNORE|OTHER) ;;
            *) REQUEST_TYPE=OTHER ;;
          esac
          echo "request-type: ${REQUEST_TYPE}"
          echo "request-type=${REQUEST_TYPE}" >> "$GITHUB_OUTPUT"

  thumbs-down-spam:
    needs: [triage]
    if: needs.triage.outputs.request-type == 'SPAM'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    permissions:
      contents: write
      id-token: write
    steps:
      - name: Infisical
        uses: Infisical/secrets-action@v1.0.16
        with:
          method: "oidc"
          identity-id: "c603d49b-292c-42ae-b838-52e03e3c3a84"
          project-slug: "agents"
          env-slug: "dev"

      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v3
        env:
          GITHUB_APP_AGENT_HELPER_CLIENT_ID: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          GITHUB_APP_AGENT_HELPER_PRIVATE_KEY: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}
        with:
          client-id: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          private-key: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}

      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          token: ${{ steps.app-token.outputs.token }}

      - name: Thumbs down
        uses: ./.github/actions/emoji-react
        with:
          comment-id: ${{ github.event.comment.id }}
          issue-number: ${{ github.event.issue.number }}
          reaction: '-1'
          token: ${{ steps.app-token.outputs.token }}

  other-request:
    needs: [triage]
    if: needs.triage.outputs.request-type == 'OTHER'
    runs-on: ubuntu-latest
    timeout-minutes: 10
    permissions:
      contents: write
      id-token: write
      issues: write
    steps:
      - name: Infisical
        uses: Infisical/secrets-action@v1.0.16
        with:
          method: "oidc"
          identity-id: "c603d49b-292c-42ae-b838-52e03e3c3a84"
          project-slug: "agents"
          env-slug: "dev"

      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v3
        env:
          GITHUB_APP_AGENT_HELPER_CLIENT_ID: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          GITHUB_APP_AGENT_HELPER_PRIVATE_KEY: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}
        with:
          client-id: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          private-key: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}

      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          token: ${{ steps.app-token.outputs.token }}

      - name: React confused
        uses: ./.github/actions/emoji-react
        with:
          comment-id: ${{ github.event.comment.id }}
          issue-number: ${{ github.event.issue.number }}
          reaction: 'confused'
          token: ${{ steps.app-token.outputs.token }}
      - name: Add comment
        uses: actions/github-script@v9
        with:
          script: |
            const body = "I'm sorry I wasn't able to understand the issue type. If it's a bug fix, change request, feature request, investigation or question please mention it specifically.";
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body
            });

  respond:
    needs: [triage]
    if: (needs.triage.outputs.request-type == 'BUG_FIX') || (needs.triage.outputs.request-type == 'CHANGE_REQUEST') || (needs.triage.outputs.request-type == 'FEATURE_REQUEST') || (needs.triage.outputs.request-type == 'INVESTIGATION') || (needs.triage.outputs.request-type == 'QUESTION')
    runs-on: ubuntu-latest
    timeout-minutes: 60
    permissions:
      contents: write
      id-token: write
      issues: write
      pull-requests: write
    steps:
      - name: Infisical
        uses: Infisical/secrets-action@v1.0.16
        with:
          method: "oidc"
          identity-id: "c603d49b-292c-42ae-b838-52e03e3c3a84"
          project-slug: "agents"
          env-slug: "dev"

      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v3
        env:
          GITHUB_APP_AGENT_HELPER_CLIENT_ID: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          GITHUB_APP_AGENT_HELPER_PRIVATE_KEY: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}
        with:
          client-id: ${{ env.GITHUB_APP_AGENT_HELPER_CLIENT_ID }}
          private-key: ${{ env.GITHUB_APP_AGENT_HELPER_PRIVATE_KEY }}

      - name: Checkout repository
        uses: actions/checkout@v5
        with:
          token: ${{ steps.app-token.outputs.token }}

      - name: Checkout issue branch if it exists
        id: checkout-issue-branch
        uses: ./.github/actions/checkout-branch
        with:
          branch: ${{ needs.triage.outputs.issue-branch }}
          base: ${{ needs.triage.outputs.issue-branch-base }}
          create-if-not-exists: false

      - name: Set up DeepSeek via pi
        uses: ./.github/actions/set-up-deepseek-via-pi
        env:
          DEEPSEEK_API_KEY: ${{ env.DEEPSEEK_API_KEY }}

      - name: Classify response
        id: classify-response
        uses: ./.github/actions/question-pi
        with:
          context-base64: ${{ needs.triage.outputs.issue-context-base64 }}
          prompt-base64: ${{ needs.triage.outputs.classify-response-base64 }}
          schema-base64: ${{ needs.triage.outputs.response-classification-base64 }}
      - name: Save response type
        id: save-response-type
        run: |
          RESPONSE_TYPE=$(echo "${{ steps.classify-response.outputs.response-base64 }}" | base64 -d | jq -r .response_type)
          # Guard against unexpected model output: default to
          # REQUIRES_MORE_INFORMATION so the user always gets a visible response
          # instead of a silent no-op.
          case "${RESPONSE_TYPE}" in
            ALREADY_ADDRESSED|REQUIRES_HUMAN|REQUIRES_MORE_INFORMATION|CAN_ADDRESS_FULLY) ;;
            *) RESPONSE_TYPE=REQUIRES_MORE_INFORMATION ;;
          esac
          echo "RESPONSE_TYPE: ${RESPONSE_TYPE}"
          echo "response-type=${RESPONSE_TYPE}" >> "$GITHUB_OUTPUT"

      - name: Classify extra information required
        id: classify-extra-information-required
        if: steps.save-response-type.outputs.response-type == 'REQUIRES_MORE_INFORMATION'
        uses: ./.github/actions/question-pi
        with:
          context-base64: ${{ needs.triage.outputs.issue-context-base64 }}
          prompt-base64: ${{ needs.triage.outputs.extra-information-required-base64 }}
          schema-base64: ${{ needs.triage.outputs.information-list-base64 }}
      - name: Save extra information required
        id: save-extra-information-required
        if: steps.save-response-type.outputs.response-type == 'REQUIRES_MORE_INFORMATION'
        run: |
          EXTRA_INFORMATION_REQUIRED=$(echo "${{ steps.classify-extra-information-required.outputs.response-base64 }}" | base64 -d | jq -c .information)
          echo "EXTRA_INFORMATION_REQUIRED: ${EXTRA_INFORMATION_REQUIRED}"
          # Use a random delimiter so a model response containing a line that
          # reads "EOF" cannot truncate the multi-line output value.
          DELIM="GHA_EOF_$RANDOM"
          {
            echo "extra-information-required<<${DELIM}"
            echo "${EXTRA_INFORMATION_REQUIRED}"
            echo "${DELIM}"
          } >> "$GITHUB_OUTPUT"

# Already addressed
      - name: Reply as already addressed
        if: steps.save-response-type.outputs.response-type == 'ALREADY_ADDRESSED'
        uses: actions/github-script@v9
        with:
          script: |
            let body = "I think this has already been addressed.\nIf it hasn't please add another comment.";
            if (${{ steps.checkout-issue-branch.outputs.issue-branch-exists }} == true) {
              body += "\n[The changes I have made can be found here.](https://github.com/" + `${context.repo.owner}/${context.repo.repo}` + "/compare/${{ needs.triage.outputs.issue-branch-base }}...${{ needs.triage.outputs.issue-branch }})";
            }
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body
            });

# Require human
      - name: Require human
        if: steps.save-response-type.outputs.response-type == 'REQUIRES_HUMAN'
        uses: actions/github-script@v9
        with:
          script: |
            const body = "I'm sorry I cannot address this issue as it requires a human.";
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body
            });

# Ask for more information
      - name: Add confused reaction
        if: steps.save-response-type.outputs.response-type == 'REQUIRES_MORE_INFORMATION'
        uses: ./.github/actions/emoji-react
        with:
          comment-id: ${{ github.event.comment.id }}
          issue-number: ${{ github.event.issue.number }}
          reaction: 'confused'
          token: ${{ steps.app-token.outputs.token }}
      - name: Ask for required information
        if: steps.save-response-type.outputs.response-type == 'REQUIRES_MORE_INFORMATION'
        uses: actions/github-script@v9
        with:
          script: |
            let extraInfo = ${{ toJson(steps.save-extra-information-required.outputs.extra-information-required) }};
            // The response is schema-validated JSON (an array of strings); parse
            // it, falling back to the raw text for robustness.
            if (typeof extraInfo === 'string') {
              try {
                extraInfo = JSON.parse(extraInfo);
              } catch (e) {
                // Not JSON; use the raw text.
              }
            }
            let body = "The following additional information is required:\n";
            if (Array.isArray(extraInfo)) {
              extraInfo.forEach(item => {
                body += `- ${item}\n`;
              });
            } else {
              body += `${extraInfo}`;
            }
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body
            });

# Respond
      - name: Add thumbs up reaction
        if: steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY'
        uses: ./.github/actions/emoji-react
        with:
          comment-id: ${{ github.event.comment.id }}
          issue-number: ${{ github.event.issue.number }}
          reaction: '+1'
          token: ${{ steps.app-token.outputs.token }}
      - name: Ensure issue branch
        if: (steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY')
        uses: ./.github/actions/checkout-branch
        with:
          branch: ${{ needs.triage.outputs.issue-branch }}
          base: ${{ needs.triage.outputs.issue-branch-base }}
          create-if-not-exists: true
      - name: Set up shipyard ssh auth
        if: steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY'
        env:
          SHIPYARD_KNOWN_HOST: ${{ env.SHIPYARD_KNOWN_HOST }}
          SHIPYARD_SSH_PRIVATE_KEY_CLIENT: ${{ env.SHIPYARD_SSH_PRIVATE_KEY_CLIENT }}
        run: |
          mkdir -p ~/.ssh
          chmod 700 ~/.ssh
          printf '%s\n' "${{ env.SHIPYARD_SSH_PRIVATE_KEY_CLIENT }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          echo "${{ env.SHIPYARD_KNOWN_HOST }}" >> ~/.ssh/known_hosts
          ssh -T git@ssh.shipyard.rs
      - name: Address issue
        id: address-issue
        if: steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY'
        uses: ./.github/actions/invoke-pi
        with:
          context-base64: ${{ needs.triage.outputs.issue-context-base64 }}
          prompt-base64: ${{ needs.triage.outputs.address-issue-base64 }}
      - name: Save address response
        id: save-address-issue-summary
        if: steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY'
        run: |
          SUMMARY=$(echo "${{ steps.address-issue.outputs.response-base64 }}" | base64 -d)
          # Use a random delimiter so a summary containing a line that reads
          # "EOF" cannot truncate the multi-line output value.
          DELIM="GHA_EOF_$RANDOM"
          {
            echo "summary<<${DELIM}"
            echo "${SUMMARY}"
            echo "${DELIM}"
          } >> "$GITHUB_OUTPUT"
      - name: Check for code changes
        id: check-for-code-changes
        if: steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY'
        run: |
          # quick local check
          if ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
            echo "has-changes=true" >> "$GITHUB_OUTPUT"
            exit 0
          fi
          # slow network check
          ISSUE_BRANCH="${{ needs.triage.outputs.issue-branch }}"
          ISSUE_BRANCH_BASE="${{ needs.triage.outputs.issue-branch-base }}"
          git fetch origin "$ISSUE_BRANCH" 2>/dev/null || true
          git fetch origin "$ISSUE_BRANCH_BASE" 2>/dev/null || true
          if git rev-parse --verify "origin/$ISSUE_BRANCH" >/dev/null 2>&1; then
            REFERENCE="origin/$ISSUE_BRANCH"
          elif git rev-parse --verify "origin/$ISSUE_BRANCH_BASE" >/dev/null 2>&1; then
            REFERENCE="origin/$ISSUE_BRANCH_BASE"
          else
            REFERENCE="HEAD"
          fi
          if ! git diff --quiet HEAD "$REFERENCE"; then
            HAS_CHANGES=true
          else
            HAS_CHANGES=false
          fi
          echo "has-changes=${HAS_CHANGES}" >> "$GITHUB_OUTPUT"
      - name: Commit and push code changes
        if: (steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY') && (steps.check-for-code-changes.outputs.has-changes == 'true')
        run: |
          git config --global user.email "agent@stock-trek.com"
          git config --global user.name "Stock-Trek Agent"
          git add .
          git commit --allow-empty -m "Commit changes made by pi"
          git push
      - name: Reply if no code changes made
        if: (steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY') && (steps.check-for-code-changes.outputs.has-changes == 'false')
        uses: actions/github-script@v9
        with:
          script: |
            const body = ${{ toJson(steps.save-address-issue-summary.outputs.summary) }};
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body
            });
      - name: Raise PR if code changes made
        id: raise-pr
        if: (steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY') && (steps.check-for-code-changes.outputs.has-changes == 'true')
        env:
          GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          ISSUE_TITLE: ${{ github.event.issue.title }}
          ISSUE_IS_PR: ${{ github.event.issue.pull_request != null }}
        run: |
          # Write title and body to temporary files to handle quotes and backticks
          # Use a random, quoted delimiter so a summary containing "EOF" or shell metacharacters cannot break the heredoc
          # Event data is passed via environment variables so an issue title containing shell metacharacters cannot be injected into the script
          # When the request came from a comment on a pull request, reference rather than "close" it: the number refers to a PR, not an issue
          if [ "${ISSUE_IS_PR}" == "true" ]; then
            REFERENCE="Addresses"
          else
            REFERENCE="Closes"
          fi
          printf '%s #%s %s\n' "${REFERENCE}" "${ISSUE_NUMBER}" "${ISSUE_TITLE}" > /tmp/pr_title.txt
          # shellcheck disable=SC2034 # PR_BODY_DELIM is used as the heredoc delimiter below
          PR_BODY_DELIM="PR_BODY_EOF_$RANDOM"
          cat > /tmp/pr_body.txt << "$PR_BODY_DELIM"
          ${{ steps.save-address-issue-summary.outputs.summary }}
          $PR_BODY_DELIM
          # Reuse an existing open PR for this branch if one was already created
          # by a previous run, otherwise create a new one.
          PR_URL=$(gh pr list \
            --head "${{ needs.triage.outputs.issue-branch }}" \
            --state open \
            --json url \
            --jq '.[0].url // empty' 2>/dev/null || true)
          if [ -z "$PR_URL" ]; then
            PR_URL=$(gh pr create \
              --base "${{ needs.triage.outputs.issue-branch-base }}" \
              --head "${{ needs.triage.outputs.issue-branch }}" \
              --title "$(cat /tmp/pr_title.txt)" \
              --body-file /tmp/pr_body.txt)
          fi
          echo "pull-request-url=$PR_URL" >> "$GITHUB_OUTPUT"
      - name: Reply with diff and PR link
        if: (steps.save-response-type.outputs.response-type == 'CAN_ADDRESS_FULLY') && (steps.check-for-code-changes.outputs.has-changes == 'true')
        uses: actions/github-script@v9
        with:
          script: |
            const body = "I have now addressed this.\n" +
                          "[The changes I have made can be found here.](https://github.com/" + `${context.repo.owner}/${context.repo.repo}` + "/compare/${{ needs.triage.outputs.issue-branch-base }}...${{ needs.triage.outputs.issue-branch }})\n" +
                          "[The PR is available here.](${{ steps.raise-pr.outputs.pull-request-url }})";
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body
            });

  notify-failure:
    needs: [triage, thumbs-down-spam, other-request, respond]
    if: failure() || cancelled()
    runs-on: ubuntu-latest
    timeout-minutes: 10
    permissions:
      actions: read
      issues: write
    steps:
      - name: Comment failure details on the issue
        uses: actions/github-script@v9
        with:
          script: |
            const owner = context.repo.owner;
            const repo = context.repo.repo;
            const issueNumber = context.issue.number;
            const runId = context.runId;

            const { data: run } = await github.rest.actions.getWorkflowRun({
              owner,
              repo,
              run_id: runId
            });
            const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
              owner,
              repo,
              run_id: runId,
              per_page: 100
            });

            const PROBLEM_CONCLUSIONS = new Set(['failure', 'cancelled', 'timed_out', 'startup_failure']);
            const failedJobs = jobs.jobs.filter(job => PROBLEM_CONCLUSIONS.has(job.conclusion));

            let body = "⚠️ I'm sorry, something went wrong while I was trying to address this issue.\n\n";
            if (failedJobs.length === 0) {
              body += "The workflow did not report a specific failed job.\n";
            } else {
              body += "The following failed:\n";
              for (const job of failedJobs) {
                body += `\n**${job.name}**\n`;
                const failedSteps = (job.steps || []).filter(step => PROBLEM_CONCLUSIONS.has(step.conclusion));
                if (failedSteps.length === 0) {
                  body += "- The job failed without reporting a specific step.\n";
                } else {
                  for (const step of failedSteps) {
                    body += `- ${step.name}\n`;
                  }
                }
              }
            }
            body += `\nYou can find the full logs [here](${run.html_url}).\n`;
            body += "\nIf you'd like me to try again, please add a comment mentioning @agent.";

            await github.rest.issues.createComment({
              owner,
              repo,
              issue_number: issueNumber,
              body
            });