Skip to content

fix(prioritize): inline CSMA library into post-script#3182

Merged
ralphbean merged 1 commit into
mainfrom
fix/inline-csma-into-prioritize
Jul 7, 2026
Merged

fix(prioritize): inline CSMA library into post-script#3182
ralphbean merged 1 commit into
mainfrom
fix/inline-csma-into-prioritize

Conversation

@ralphbean

@ralphbean ralphbean commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Inlines scripts/lib/github-api-csma.sh directly into post-prioritize.sh and post-prioritize-test.sh
  • Deletes the now-unused scripts/lib/ directory
  • Removes the scaffold test reference to the deleted file

Problem

Base composition (base: in harness YAML) fetches each script as an individual content-addressed blob. The post-prioritize script does source "${SCRIPT_DIR}/lib/github-api-csma.sh", but lib/ doesn't exist next to the cached blob. This has broken every prioritize run since the July 1 migration to base composition (8382e8ba).

Fix

Inline the CSMA functions, matching the pattern used by other post-scripts (e.g., post-retro.sh handles retries inline rather than sourcing a library).

Companion PR: fullsend-ai/agents#35

Test plan

  • bash internal/scaffold/fullsend-repo/scripts/post-prioritize-test.sh — all 7 tests pass
  • go test ./internal/scaffold/... — passes
  • shellcheck — clean

The post-prioritize script sources lib/github-api-csma.sh via SCRIPT_DIR,
but base composition fetches scripts as individual content-addressed blobs
without their sibling directories. This breaks every prioritize run under
base composition (since 8382e8ba).

Inline the CSMA functions directly into post-prioritize.sh and
post-prioritize-test.sh, matching the approach other post-scripts use
(e.g., post-retro.sh handles retries inline). Delete the now-unused
scripts/lib/ directory.

Assisted-by: Claude claude-opus-4-6 <noreply@anthropic.com>
Signed-off-by: Ralph Bean <rbean@redhat.com>
@ralphbean ralphbean requested a review from a team as a code owner July 6, 2026 21:34
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 6, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 9:35 PM UTC · Completed 9:40 PM UTC
Commit: e397f79 · View workflow run →

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix prioritize by inlining GitHub CSMA helpers into post scripts

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Inline GitHub API CSMA retry/sense helpers into prioritize post scripts for base composition
 compatibility.
• Remove the now-unused scripts/lib CSMA library file and update scaffolding tests accordingly.
• Keep CSMA behavior identical while making prioritize runs self-contained and reliable.
Diagram

graph TD
Base["Base composition"] --> Post["post-prioritize.sh"] --> CSMA["CSMA helpers"] --> GH["gh + jq"] --> API{{"GitHub API"}}
Tests["post-prioritize-test.sh"] --> CSMA
Scaffold["scaffold_test.go"] --> Post
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Bundle scripts as a directory artifact in base composition
  • ➕ Keeps shared Bash libraries centralized (no duplication across post-scripts)
  • ➕ Avoids copy/paste drift when multiple scripts need the same helpers
  • ➖ Requires changes to the base composition/caching mechanism and rollout coordination
  • ➖ Higher operational surface area vs a self-contained script fix
2. Install shared CSMA library into the runner image and source from a stable path
  • ➕ Single source of truth for CSMA behavior across scripts
  • ➕ No dependence on adjacent repo paths/blobs
  • ➖ Couples behavior updates to image rebuild/release cadence
  • ➖ Harder to iterate on script logic within the repo without image changes
3. Generate a single combined post-script artifact during scaffolding
  • ➕ Avoids runtime directory assumptions while still authoring code modularly
  • ➕ Keeps duplication out of committed scripts
  • ➖ Adds a build/generation step and associated tooling complexity
  • ➖ Can make debugging harder if generated output diverges from source modules

Recommendation: Inlining is the most pragmatic short-term fix because it directly addresses the blob-only fetch behavior without requiring composition or image changes, and it matches existing patterns used by other post-scripts. If CSMA logic needs to be shared across more scripts over time, consider moving to an image-installed library or composition directory bundling to avoid long-term duplication.

Files changed (3) +636 / -6

Bug fix (1) +318 / -3
post-prioritize.shMake post-prioritize self-contained by inlining CSMA GitHub API retry logic +318/-3

Make post-prioritize self-contained by inlining CSMA GitHub API retry logic

• Removes dependency on scripts/lib/github-api-csma.sh (which is not co-located when scripts are fetched as blobs) and embeds the CSMA helpers directly in the script. This restores prioritize runs under base composition while keeping rate-limit sensing, jitter, and retry/backoff behavior in place.

internal/scaffold/fullsend-repo/scripts/post-prioritize.sh

Tests (2) +318 / -3
post-prioritize-test.shInline CSMA helper library into prioritize post-script tests +318/-2

Inline CSMA helper library into prioritize post-script tests

• Replaces sourcing of scripts/lib/github-api-csma.sh with an inlined copy of the CSMA helper functions. This keeps the test harness self-contained under base composition and preserves the existing CSMA unit tests.

internal/scaffold/fullsend-repo/scripts/post-prioritize-test.sh

scaffold_test.goUpdate scaffold file-existence test to stop expecting deleted CSMA lib +0/-1

Update scaffold file-existence test to stop expecting deleted CSMA lib

• Removes scripts/lib/github-api-csma.sh from the list of required scaffolded files to match the new inlined approach. Keeps scaffold validation aligned with the repository layout after deleting scripts/lib/.

internal/scaffold/scaffold_test.go

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Site preview

Preview: https://381e8e32-site.fullsend-ai.workers.dev

Commit: e397f79e4a870eb3cc6407ca4cad6660a05dc131

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 61 rules

Grey Divider


Remediation recommended

1. Invalid top-level return 🐞 Bug ≡ Correctness
Description
post-prioritize.sh (and post-prioritize-test.sh) now contains a top-level return 0 in the CSMA
“already loaded” guard, which is invalid when the script is executed (not sourced). If
GITHUB_API_CSMA_SH_LOADED is set in the environment, Bash will emit a hard error (`return: can
only 'return'...) and may abort under set -euo pipefail`.
Code

internal/scaffold/fullsend-repo/scripts/post-prioritize.sh[R30-33]

+# shellcheck shell=bash
+
+[[ -n "${GITHUB_API_CSMA_SH_LOADED:-}" ]] && return 0
+GITHUB_API_CSMA_SH_LOADED=1
Relevance

⭐⭐⭐ High

Team often fixes bash runtime-fatal errors under set -euo; similar safety fixes merged in multiple
script PRs.

PR-#2456
PR-#1620
PR-#1711

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
post-prioritize.sh is an executable host-run script and contains a top-level return in the
inlined CSMA block; the test harness also executes it via bash, confirming it is not sourced in
normal flows. The same invalid guard exists in post-prioritize-test.sh’s inlined CSMA block.

internal/scaffold/fullsend-repo/scripts/post-prioritize.sh[1-6]
internal/scaffold/fullsend-repo/scripts/post-prioritize.sh[30-34]
internal/scaffold/fullsend-repo/scripts/post-prioritize-test.sh[249-251]
internal/scaffold/fullsend-repo/scripts/post-prioritize-test.sh[284-288]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The inlined CSMA code kept the library-style load guard:

```bash
[[ -n "${GITHUB_API_CSMA_SH_LOADED:-}" ]] && return 0
GITHUB_API_CSMA_SH_LOADED=1
```

This is valid only when the code is **sourced**. After inlining, it lives in executable scripts and `return` becomes invalid if the variable is pre-set.

### Issue Context
These scripts are executed directly (not sourced), so a pre-set `GITHUB_API_CSMA_SH_LOADED` will trigger an invalid `return` and can break runs.

### Fix Focus Areas
- internal/scaffold/fullsend-repo/scripts/post-prioritize.sh[30-33]
- internal/scaffold/fullsend-repo/scripts/post-prioritize-test.sh[284-287]

### Suggested fix
Remove the guard entirely (recommended for inlined code), or replace the `return` with a no-op so it’s always legal in an executable script (e.g., `[[ -n ... ]] && :`) and keep/adjust the sentinel assignment as needed.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +30 to +33
# shellcheck shell=bash

[[ -n "${GITHUB_API_CSMA_SH_LOADED:-}" ]] && return 0
GITHUB_API_CSMA_SH_LOADED=1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Invalid top-level return 🐞 Bug ≡ Correctness

post-prioritize.sh (and post-prioritize-test.sh) now contains a top-level return 0 in the CSMA
“already loaded” guard, which is invalid when the script is executed (not sourced). If
GITHUB_API_CSMA_SH_LOADED is set in the environment, Bash will emit a hard error (`return: can
only 'return'...) and may abort under set -euo pipefail`.
Agent Prompt
### Issue description
The inlined CSMA code kept the library-style load guard:

```bash
[[ -n "${GITHUB_API_CSMA_SH_LOADED:-}" ]] && return 0
GITHUB_API_CSMA_SH_LOADED=1
```

This is valid only when the code is **sourced**. After inlining, it lives in executable scripts and `return` becomes invalid if the variable is pre-set.

### Issue Context
These scripts are executed directly (not sourced), so a pre-set `GITHUB_API_CSMA_SH_LOADED` will trigger an invalid `return` and can break runs.

### Fix Focus Areas
- internal/scaffold/fullsend-repo/scripts/post-prioritize.sh[30-33]
- internal/scaffold/fullsend-repo/scripts/post-prioritize-test.sh[284-287]

### Suggested fix
Remove the guard entirely (recommended for inlined code), or replace the `return` with a no-op so it’s always legal in an executable script (e.g., `[[ -n ... ]] && :`) and keep/adjust the sentinel assignment as needed.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@fullsend-ai-review

Copy link
Copy Markdown

Review — approve

PR: fix(prioritize): inline CSMA library into post-script
Severity threshold: low

Summary

This PR fixes a production regression where every prioritize agent run has been failing since the July 1 migration to base composition (8382e8ba). The root cause is clear: base composition fetches each script as an individual content-addressed blob, so source "${SCRIPT_DIR}/lib/github-api-csma.sh" fails because the lib/ directory doesn't exist next to the cached blob.

The fix inlines the CSMA library directly into post-prioritize.sh and post-prioritize-test.sh, matching the pattern already used by other post-scripts (e.g., post-retro.sh handles retries inline). The deleted library file has no other consumers.

Verified

  • Inlined code fidelity: The inlined CSMA code in both post-prioritize.sh and post-prioritize-test.sh is a faithful copy of the deleted lib/github-api-csma.sh, with only expected differences (shebang line removed, header comment adjusted, boundary markers added).
  • No orphaned references: Searched the entire repo for references to scripts/lib/github-api-csma.sh and scripts/lib/ in YAML, Go, and shell files. All references are in files modified by this PR. The post-retro.sh comment mentioning the library is a design note explaining why it doesn't use CSMA — not a code dependency.
  • SCRIPT_DIR removal: The SCRIPT_DIR variable removed from post-prioritize.sh was only used for the source command; no other code references it. In post-prioritize-test.sh, SCRIPT_DIR is retained (line 8) as it's still used for POST_SCRIPT.
  • Scaffold test updated: The TestFullsendRepoFilesExist assertion for scripts/lib/github-api-csma.sh is correctly removed.
  • PR title: Follows COMMITS.md — fix type is appropriate for a user-visible bug, prioritize scope is correct, no breaking change (no ! needed).
  • Guard code: The GITHUB_API_CSMA_SH_LOADED guard with return 0 is dead code in the inlined context (the variable is always unset at script start). It's harmless — the false branch of the [[ -n ... ]] test means return 0 never executes.

Notes

The ~315 lines of CSMA logic are now duplicated across two files. This is an acknowledged trade-off: the base composition model doesn't support shared libraries, and other post-scripts already follow the inline pattern. Future CSMA changes need to be applied in both places.

No medium or higher findings. The change is a clean, mechanical fix for a real production issue.


Labels: PR fixes the prioritize agent post-script and resolves a bug

@fullsend-ai-review fullsend-ai-review Bot added ready-for-merge All reviewers approved — ready to merge agent/prioritize Prioritize agent bug labels Jul 6, 2026

@ifireball ifireball left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting.

Longer term we need to consider how to share code between agent scripts - I would assume we may want the same CSMA-style logic in other scripts, but duplicating it everywhere would be cumbersome.

Do you think we should have an issue for that @ralphbean , @ggallen ?

@ralphbean

Copy link
Copy Markdown
Member Author

Yes please! Retro agent, you got that, right?

@ralphbean ralphbean added this pull request to the merge queue Jul 7, 2026
Merged via the queue into main with commit 3c6b1c7 Jul 7, 2026
28 of 30 checks passed
@ralphbean ralphbean deleted the fix/inline-csma-into-prioritize branch July 7, 2026 22:37
@fullsend-ai-retro

fullsend-ai-retro Bot commented Jul 7, 2026

Copy link
Copy Markdown

🤖 Finished Retro · ✅ Success · Started 10:39 PM UTC · Completed 10:47 PM UTC
Commit: e397f79 · View workflow run →

@fullsend-ai-retro

Copy link
Copy Markdown

Retro analysis of PR #3182: fix(prioritize): inline CSMA library into post-script.

This PR fixed a 5-day production regression where every prioritize agent run failed after the July 1 base composition migration. The fix inlined the CSMA library into post-prioritize scripts. The review agent approved but incorrectly dismissed a latent shell bug (top-level return 0 in an executed script) that the Qodo code review bot correctly flagged. The bug is still present in main.

Three proposals filed:

  1. Add shell correctness guidance to AGENTS.md for return outside functions in executed scripts
  2. Fix the latent return 0 guard bug in inlined CSMA code
  3. Enhance the correctness sub-agent to verify construct validity during code context migration

Proposals filed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/prioritize Prioritize agent bug ready-for-merge All reviewers approved — ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants