docs(#251): add shell return-vs-exit correctness rule - #282
docs(#251): add shell return-vs-exit correctness rule#282fullsend-ai-coder[bot] wants to merge 1 commit into
Conversation
Add a Shell scripting section to AGENTS.md with guidance on the return-vs-exit distinction in executed vs sourced scripts. The review agent previously dismissed a top-level return in an executed script as harmless dead code (PR fullsend-ai#3182). In bash, return at script top level is invalid and causes a hard abort under set -euo pipefail, regardless of reachability. Closes #251
|
🤖 Finished Review · ✅ Success · Started 4:41 PM UTC · Completed 4:45 PM UTC |
Review — commentPR: Authorization & scope ✅Change traces to issue #251 (created by repo owner). The diff is a verbatim implementation of the issue's "Proposed change" section. No scope creep. CODEOWNERS wildcard rule ensures human approval. Security ✅No secrets, injection patterns, permission changes, or steganographic content. The review-guidance directive follows established AGENTS.md patterns. Style & conventions ✅Heading levels ( Correctness — findingsThe guidance is directionally correct and addresses a real, documented bug (PR fullsend-ai#3182). However, the technical explanation has a precision gap: [medium · technical-accuracy · AGENTS.md:~51] The claim that top-level
Both outcomes are bugs, but for different reasons. The current wording could lead a reviewer to skip flagging the pattern in scripts without Note: the [low · edge-case · AGENTS.md:~53] The example VerdictThe new rule is well-scoped, properly authorized, and adds genuine value — the review agent missed exactly this class of bug on PR fullsend-ai#3182. The medium finding is about precision of the technical explanation, not correctness of the review guidance itself ("flag top-level
Previous runReview — approvePR: #282 · SummarySingle-file documentation change adding a "Shell scripting" section to AnalysisCorrectness — The technical content is accurate. Intent & coherence — The committed text matches the proposed change in issue #251 verbatim. The commit message uses the correct Style & placement — The new Security — Documentation-only change; no security implications. Documentation currency — N/A (this is the documentation change). Cross-repo contracts — No external interfaces affected. No findings above the severity threshold.
Labels: PR adds documentation to AGENTS.md |
|
/fs-fix |
|
🤖 Finished Fix · ✅ Success · Started 5:38 PM UTC · Completed 5:44 PM UTC |
🔧 Fix agent — iteration 1 (human-triggered)No actionable review feedback was found. The review body was empty and the human instruction was 'none'. The PR modifies only AGENTS.md (a protected path). No code changes were made. Disagreed (1):
Tests: passed Updated by fullsend fix agent |
|
/fs-review |
|
🤖 Finished Review · ✅ Success · Started 4:50 AM UTC · Completed 4:57 AM UTC |
|
|
||
| ## Shell scripting | ||
|
|
||
| ### `return` vs `exit` in executed scripts |
There was a problem hiding this comment.
[medium] technical-accuracy
The claim that top-level return in an executed script 'causes a hard error' is imprecise. Without set -e, return at top level prints a diagnostic to stderr and exits with code 2, but the script continues execution — the guard silently fails. Only with set -e does the non-zero exit code cause an abort. Both outcomes are bugs but for different reasons, and the current wording could lead reviewers to skip flagging this pattern in scripts without set -e.
Suggested fix: Reword to describe both failure modes: 'At the top level of an executed script, return fails with exit code 2 and prints a diagnostic. Without set -e, the script continues past the failed return (the guard silently fails to skip execution). With set -e (commonly set -euo pipefail), the non-zero exit code aborts the script.'
|
|
||
| ### `return` vs `exit` in executed scripts | ||
|
|
||
| `return` is valid only inside functions or in scripts that are `source`d. At the top level of an executed script (one with a shebang or run via `bash script.sh`), `return` causes a hard error — and under `set -euo pipefail`, this aborts the script. |
There was a problem hiding this comment.
[low] edge-case
The example pattern [[ -n "${LOADED:-}" ]] && return 0 only triggers the return error when the guard variable is set. When unset (common case), && short-circuits and return is never reached, making this a latent bug that passes basic testing but fails when the variable leaks from the environment.
Suggested fix: Consider adding: 'The error only triggers when the guard condition is true (variable is set); when false, && short-circuits and return is never reached, making this a latent bug that may not manifest in simple testing.'
Add a Shell scripting section to AGENTS.md with guidance on the return-vs-exit distinction in executed vs sourced scripts. The review agent previously dismissed a top-level return in an executed script as harmless dead code (PR fullsend-ai#3182). In bash, return at script top level is invalid and causes a hard abort under set -euo pipefail, regardless of reachability.
Closes #251
Post-script verification
agent/251-shell-return-rule)d8e3df7c018996e396c79b8ecd59e4145a628a6f..HEAD)