Skip to content

feat: upstream_fix marker convention, --audit-fixes command, and CI Bun crash resilience#555

Merged
anandgupta42 merged 3 commits intomainfrom
feat/upstream-fix-markers
Mar 29, 2026
Merged

feat: upstream_fix marker convention, --audit-fixes command, and CI Bun crash resilience#555
anandgupta42 merged 3 commits intomainfrom
feat/upstream-fix-markers

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Mar 29, 2026

What does this PR do?

Introduces a strategy for handling bug fixes to upstream code, plus code review fixes from #546.

upstream_fix: convention:

  • Tag in marker description (// altimate_change start — upstream_fix: description) distinguishes temporary bug fixes from permanent feature additions
  • Reviewers know to check "did upstream fix this?" during merge conflict resolution

--audit-fixes command:

  • bun run script/upstream/analyze.ts --audit-fixes lists all upstream bug fixes we're carrying
  • Prints file locations, descriptions, and merge review checklist

Retagged 3 existing upstream bug fixes:

  • locale.ts:57 — days/hours duration calculation swap
  • command/index.ts:57 — placeholder lexicographic sort ($10 before $2)
  • home.tsx:41 — beginner UI race condition flash

Code review fixes from #546:

  • Guard --downstream without --model in dbt build (returns error instead of silently running full project build)
  • Remove unused condition field from Suggestion interface

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #554

How did you verify your code works?

  • 22 marker analyzer tests pass (1 new for upstream_fix: recognition)
  • --audit-fixes correctly lists all 3 upstream bug fixes
  • 5 dbt build tests pass (1 new for --downstream guard)
  • Marker guard passes in strict mode against origin/main
  • Prettier passes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed duration display for 24+ hour periods; --downstream now errors if --model is missing.
  • New Features

    • Added --audit-fixes CLI flag to report upstream bug fixes being carried.
  • Documentation

    • Added upstream_fix tag docs and pre-merge audit guidance.
  • Refactor

    • Removed optional suggestion condition field from followups interface.
  • Tests

    • Added tests for build-arg validation and upstream-fix marker parsing.
  • Style / Chores

    • Minor comment and formatting tweaks; CI test-run step updated.

Introduces a strategy for handling bug fixes to upstream code:

**`upstream_fix:` convention:**
- Tag in marker description distinguishes temporary bug fixes from
  permanent feature additions
- Before each upstream merge, run `--audit-fixes` to review which
  fixes we're carrying and whether upstream has shipped their own

**`--audit-fixes` flag on analyze.ts:**
- Lists all `upstream_fix:` markers with file locations and descriptions
- Prints merge review checklist

**Retagged 3 existing upstream bug fixes:**
- `locale.ts` — days/hours duration swap
- `command/index.ts` — placeholder lexicographic sort
- `home.tsx` — beginner UI race condition

**Code review fixes from #546:**
- Guard `--downstream` without `--model` (returns error instead of
  silently running full project build)
- Remove unused `condition` field from `Suggestion` interface
- Add test for `--downstream` error case

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

Adds an upstream_fix: marker convention, a new --audit-fixes CLI flag and audit flow to script/upstream/analyze.ts, documentation and tests for the convention, fixes duration calculation in locale.ts, removes a suggestion condition field, and tightens build flag validation with a new test.

Changes

Cohort / File(s) Summary
Upstream Fix Audit Infrastructure
script/upstream/analyze.ts, script/upstream/analyze.test.ts, script/upstream/README.md
Add --audit-fixes CLI flag and auditUpstreamFixes() flow to detect/report marker blocks whose start comment contains upstream_fix:; tests and README updated to document and validate behavior.
Build Command Validation
packages/dbt-tools/src/commands/build.ts, packages/dbt-tools/test/build.test.ts
Change build() arg validation to return { error: "--downstream requires --model" } when --downstream is provided without --model; add test asserting no adapter methods are called.
Locale Duration Calculation
packages/opencode/src/util/locale.ts
Fix calculation for durations ≥ 24 hours to compute whole days and remainder hours (days = floor(ms/86400000), hours = floor((ms % 86400000)/3600000)).
Interface Cleanup & Text Formatting
packages/opencode/src/skill/followups.ts
Remove optional condition?: string from exported SkillFollowups.Suggestion interface; reformat multi-line WAREHOUSE_NUDGE string.
Comments / Minor Formatting
packages/opencode/src/cli/cmd/tui/routes/home.tsx, packages/opencode/src/command/index.ts
Inline comment updates referencing upstream_fix: and minor loop/body formatting changes in Command.hints (no logic change).
CI Workflow
.github/workflows/ci.yml
Change Bun test step to run via a Bash wrapper that captures/parses test output and fails only on detected test failures (prints captured output).

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer (CLI)
    participant Analyze as analyze.ts
    participant Repo as Repository files
    participant Parser as Marker Parser
    participant Console as Console/Report

    Dev->>Analyze: run `analyze.ts --audit-fixes`
    Analyze->>Repo: scan files for marker blocks
    Repo-->>Analyze: return file hunks
    Analyze->>Parser: parse hunks for `upstream_fix:` in start comment
    Parser-->>Analyze: list of matching markers (file, range, description)
    Analyze->>Console: print "Upstream Bug Fixes We’re Carrying" report
    Console-->>Dev: human-readable checklist + exit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I nibbled at markers in the night,
Found upstream fixes tagged just right,
I hopped and counted every line,
So merges go tidy, neat, and fine,
A tiny rabbit audit, done in light.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the three main contributions: the upstream_fix marker convention, the --audit-fixes command, and CI Bun crash resilience improvements.
Description check ✅ Passed The PR description provides a comprehensive summary of changes with clear sections on what changed, testing verification, and completed checklist items, closely following the template structure.
Linked Issues check ✅ Passed All coding objectives from issue #554 are met: upstream_fix convention is implemented with marker tagging, --audit-fixes command lists fixes with locations and checklists, three existing fixes are retagged, and code review fixes from #546 are included.
Out of Scope Changes check ✅ Passed All changes directly align with objectives: upstream_fix infrastructure updates, audit command, existing fix retagging, #546 code review fixes, and CI resilience improvements for Bun crashes are all within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/upstream-fix-markers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
script/upstream/analyze.ts (1)

514-517: Minor: JSX comment trailing characters may leak into description.

For JSX markers like {/* altimate_change start — upstream_fix: desc */}, the description extraction may leave a trailing }:

desc }

This is cosmetic and doesn't affect functionality, but for cleaner output:

Optional fix for cleaner JSX description extraction
-    const desc = fix.startComment.replace(/.*upstream_fix:\s*/, "").replace(/\s*\*\/\s*$/, "")
+    const desc = fix.startComment
+      .replace(/.*upstream_fix:\s*/, "")
+      .replace(/\s*\*\/\s*\}?\s*$/, "")
+      .trim()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@script/upstream/analyze.ts` around lines 514 - 517, The description
extraction for each fix (inside the for loop over fixes) can leave a trailing
JSX brace like "}" in desc; update the desc assignment that uses
fix.startComment to additionally strip trailing braces and stray comment chars
by chaining a final replace such as .replace(/[\s\}]*$/, "") (i.e., modify the
desc computation that currently uses
fix.startComment.replace(/.*upstream_fix:\s*/, "").replace(/\s*\*\/\s*$/, "") to
also remove trailing "}"/whitespace so JSX markers like {/* ... */} don't leak a
trailing brace).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@script/upstream/analyze.ts`:
- Around line 514-517: The description extraction for each fix (inside the for
loop over fixes) can leave a trailing JSX brace like "}" in desc; update the
desc assignment that uses fix.startComment to additionally strip trailing braces
and stray comment chars by chaining a final replace such as .replace(/[\s\}]*$/,
"") (i.e., modify the desc computation that currently uses
fix.startComment.replace(/.*upstream_fix:\s*/, "").replace(/\s*\*\/\s*$/, "") to
also remove trailing "}"/whitespace so JSX markers like {/* ... */} don't leak a
trailing brace).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c8cba34f-f6ea-4145-ab15-a11e13864ddc

📥 Commits

Reviewing files that changed from the base of the PR and between 384335d and 6195e24.

📒 Files selected for processing (9)
  • packages/dbt-tools/src/commands/build.ts
  • packages/dbt-tools/test/build.test.ts
  • packages/opencode/src/cli/cmd/tui/routes/home.tsx
  • packages/opencode/src/command/index.ts
  • packages/opencode/src/skill/followups.ts
  • packages/opencode/src/util/locale.ts
  • script/upstream/README.md
  • script/upstream/analyze.test.ts
  • script/upstream/analyze.ts

Bun 1.3.x has a known crash (segfault/SIGTERM) during process cleanup
after all tests pass successfully. This caused flaky CI failures where
5362 tests pass but the job reports failure due to exit code 143.

The fix captures test output and checks the actual pass/fail summary
instead of relying on Bun's exit code:
- Real test failures (N fail > 0): exit 1
- No test summary at all (Bun crashed before running): exit 1
- All tests pass but Bun crashes during cleanup: emit warning, exit 0

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@anandgupta42 anandgupta42 changed the title feat: upstream_fix marker convention and --audit-fixes command feat: upstream_fix marker convention, --audit-fixes command, and CI Bun crash resilience Mar 29, 2026
The previous approach using `tee` failed because when Bun segfaults,
the pipe breaks and tee doesn't flush output to the file. The grep
then finds no summary and reports "crashed before producing results"
even though all tests passed.

Fix: redirect bun output to file directly (`> file 2>&1 || true`),
then `cat` it for CI log visibility. Use portable `awk` instead of
`grep -oP` for summary extraction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)

101-121: Capture and reuse the test command exit code for better CI diagnostics.

Line 101 currently swallows the test process status via || true, so the step can’t tell a clean pass from a crash-after-pass case. Capture the exit code and emit a warning when tests pass but the command returned non-zero.

Suggested patch
-          bun test --timeout 30000 > /tmp/test-output.txt 2>&1 || true
+          BUN_EXIT=0
+          bun test --timeout 30000 > /tmp/test-output.txt 2>&1 || BUN_EXIT=$?
           cat /tmp/test-output.txt
@@
-          if [ -n "$PASS_COUNT" ] && [ "$PASS_COUNT" -gt 0 ] 2>/dev/null; then
+          if [ -n "$PASS_COUNT" ] && [ "$PASS_COUNT" -gt 0 ] 2>/dev/null; then
+            if [ "$BUN_EXIT" -ne 0 ]; then
+              echo "::warning::Tests passed, but bun exited with status $BUN_EXIT (likely cleanup crash)"
+            fi
             exit 0
           fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yml around lines 101 - 121, The CI step currently
swallows the bun test exit code by using "|| true"; run bun test redirecting
output to /tmp/test-output.txt without "|| true", immediately capture its exit
status into a variable (e.g., TEST_EXIT_CODE=$?), and then use PASS_COUNT and
FAIL_COUNT as already extracted to decide final outcome: if FAIL_COUNT non-zero
exit 1 as now; if PASS_COUNT > 0 but TEST_EXIT_CODE != 0 emit a warning message
including TEST_EXIT_CODE and then exit non-zero (or at least surface the
non-zero status), otherwise exit 0 on clean success. Ensure references to the
bun test invocation, /tmp/test-output.txt, TEST_EXIT_CODE, PASS_COUNT, and
FAIL_COUNT are updated accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 101-121: The CI step currently swallows the bun test exit code by
using "|| true"; run bun test redirecting output to /tmp/test-output.txt without
"|| true", immediately capture its exit status into a variable (e.g.,
TEST_EXIT_CODE=$?), and then use PASS_COUNT and FAIL_COUNT as already extracted
to decide final outcome: if FAIL_COUNT non-zero exit 1 as now; if PASS_COUNT > 0
but TEST_EXIT_CODE != 0 emit a warning message including TEST_EXIT_CODE and then
exit non-zero (or at least surface the non-zero status), otherwise exit 0 on
clean success. Ensure references to the bun test invocation,
/tmp/test-output.txt, TEST_EXIT_CODE, PASS_COUNT, and FAIL_COUNT are updated
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 45c5557a-e74a-467d-bfc1-4a17303e433c

📥 Commits

Reviewing files that changed from the base of the PR and between 6195e24 and db4405a.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml

@anandgupta42 anandgupta42 merged commit dbff413 into main Mar 29, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: upstream_fix marker convention for upstream bug fixes

1 participant