Skip to content

fix: save the base as soon as it is built, and explain refused pushes - #184

Merged
Svilen-Stefanov merged 3 commits into
mainfrom
fix/save-base-early-explain-sync
Dec 6, 2026
Merged

Svilen-Stefanov merged 3 commits into
mainfrom
fix/save-base-early-explain-sync

Conversation

@Svilen-Stefanov

@Svilen-Stefanov Svilen-Stefanov commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Three fixes so a run's work is not thrown away, and so a failing run says why.

  1. Review saves the base before analyzing the head. The base upload used to run after the head analysis. If the head failed or the job timed out, the finished base was lost and the next pull request built it again.
  2. Sync publishes its analysis even when the push is refused. It is uploaded under the analyzed commit as soon as the analysis succeeds, so the next sync or review can start from it.
  3. A refused push names the cause. When GitHub refuses the push because of branch protection or a ruleset (GH006/GH013), the run fails with the fix instead of "Could not push":
    • on the default branch with in_place: remove codeboarding_analysis_location: in_place so sync saves to codeboarding/baseline;
    • otherwise: add GitHub Actions (or the CodeBoarding app) as a bypass actor.

The early quota check that was here moves to Core, following review: CodeBoarding/CodeBoarding#712. Core already tells the user's CodeBoarding quota apart from the hosted provider running out, and the Action already shows Core's message, so the Action needs no quota code.

The README's example workflow now uses timeout-minutes: 180, and docs/COMMIT_STRATEGY.md says when each analysis is published.

Why

A customer's reviews kept rebuilding the base from scratch, about 50 minutes each on a 1.3M-line C# repository:

  • Sync never saved an analysis. It was killed by the 60-minute job limit, or it failed on a quota that was already used up when the run started (the Core PR above handles that case).
  • Two bases were lost. Twice the base finished and the head was then killed, so the base was never uploaded.
  • A refused push threw the analysis away. On another repository, sync appears to commit to a protected main; the push is refused and the analysis is discarded with it.

Tests

  • python3 -m unittest discover -s tests: 379 pass, 9 skipped. Refused pushes are simulated with pre-receive hooks.
  • actionlint, shellcheck -x scripts/action/*.sh, black: clean.

Not yet seen on a real runner: GitHub's exact refusal text.

🤖 Generated with Claude Code

…d stop early on a spent quota

- Review uploads the base right after generating it, before the head analysis, so a head that fails or times out no longer discards it.
- Sync publishes the analyzed commit's base whatever the delivery did; the baseline-commit copy still needs a delivered commit.
- A push refused by branch protection or a ruleset (GH006/GH013) fails with the branch and the fix.
- A spent hosted quota or OpenRouter key limit stops the run before checkout and install, with the reason in the review comment or sync summary.
- README workflow examples use timeout-minutes: 180.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T23:10:00.705323Z 07c63d2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codeboarding-review

codeboarding-review Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

CodeBoarding review

Status: 0 changed components (no analysed file changed)

See the full change in CodeBoarding.

graph LR
    n_Action_Execution_And_Relay["Action Execution And Relay"]
    n_Remote_Analysis_Integration["Remote Analysis Integration"]
    classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
    classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
    classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
Loading

download artifacts · run 47580511332

…er outputs

- The quota message matches Core's and links to pricing; it no longer tells a license user to switch to a license.
- "Remove in_place" is advised only for the default branch; any other branch gets the bypass-actor fix.
- baseline_sha is set only when in_place writes a commit, so its publish step needs one plain condition.
- refused_by_rule lives next to baseline_fail; clearer names, shorter comments, shared test helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ivanmilevtues ivanmilevtues 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.

I would like to reconsider the quota handling as we are already doing it via core and I am unsure how does this fit into that.
After prompting it said this:

The existing path is:

- Engine [`LLMQuotaError`](https://github.com/CodeBoarding/CodeBoarding/blob/main/agents/llm_errors.py#L109-L132) produces: “Your CodeBoarding quota is exhausted. Buy a CodeBoarding license at https://codeboarding.org/pricing, or wait for your weekly reset.”
- The CLI exits with code `3`.
- The Action’s [`analyze_repository.py`](https://github.com/CodeBoarding/CodeBoarding-action/blob/main/scripts/analyze_repository.py#L111-L124) preserves that message as `failure_reason`, which the workflow displays.

**What [PR #184](https://app.codeboarding.org/CodeBoarding/CodeBoarding-action/pull/184) adds is an earlier check, not a previously missing upgrade message.** It probes quota before checkout and engine installation, rather than discovering exhaustion when analysis makes an LLM request. That can save wasted setup and static-analysis time. The runtime handling still needs to exist because quota can run out during analysis.

There is nevertheless a legitimate duplication concern: **the new script reimplements the classification and upgrade copy, less precisely.** It treats any HTTP `402` from the hosted endpoint as the user’s CodeBoarding quota being exhausted. The existing engine distinguishes that from CodeBoarding’s upstream provider running out of credits, which tells the user to contact support rather than buy a license.

Comment thread scripts/action/quota_check.py Outdated

OPENROUTER_KEY_URL = "https://openrouter.ai/api/v1/key"

HOSTED_SPENT = (

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.

We already handle exhausted quota and show the upgrade/reset guidance through LLMQuotaError and analyze_repository.py. I understand the benefit here is checking before expensive setup.
This probably has to be handled within the core or feature itself rather than here, it is a bit odd to make a request we also have just openrouter_key here.

Could you revise this so it is handled a bit mroe centralized not one time in core, one in action and so on. I am not sure how we can do that, but I preferred the way with the exception from core and then we should proly also have something for the cloud part (which is the llm lambda proxy itself I think)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, took it out of this PR (07c63d2). The early check now lives in Core instead: https://app.codeboarding.org/CodeBoarding/CodeBoarding/pull/712

  • One free GET /models call in bootstrap_environment(), before tool installs and static analysis, only for the Action's hosted credentials.
  • It raises the existing LLMQuotaError only when _is_codeboarding_quota says so, so the message and the upstream-out-of-credits split are the same code as at runtime. The CLI exits 3 and the Action shows Core's message, so the Action has no quota code left.
  • No cloud change: the proxy's gate already answers before forwarding, and /models is not metered.

On the time it saves: across 11 recent jobs on our repos, the Action spends 37–59 s before Core starts (mostly the pip install), while Core's static analysis takes minutes on our repos and tens of minutes on a 1.3M-line C# repo. So checking inside Core catches nearly all the waste, without a second copy in the Action.

Comment thread README.md
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))
runs-on: ubuntu-latest
timeout-minutes: 60
timeout-minutes: 180

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.

okay that's good

Review asked for quota handling in one place: Core's LLMQuotaError already
tells the user's CodeBoarding quota apart from the hosted provider running out,
and the Action shows its message. The early check moves to Core, so the Action
gets it without its own request or copy of the message.

Authentication is configured where it was before, and credentials are cleared
in review mode only, as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Svilen-Stefanov added a commit to CodeBoarding/CodeBoarding that referenced this pull request Dec 5, 2026
…quota is spent

A large repository's Action run spent many minutes on static analysis before
its first LLM call, and only then learned the free-tier quota was spent. The
hosted proxy gates every request on the caller's weekly quota before
forwarding it and meters only completions, so a GET /models through the same
client answers 402 at no token cost. bootstrap_environment now makes that one
request on hosted credentials and raises the same LLMQuotaError the runtime
path raises, so full, incremental and partial runs exit 3 with Core's message.
Any other answer lets the run go on. Own provider keys are never checked.

Replaces the Action-side probe removed from CodeBoarding/CodeBoarding-action#184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Svilen-Stefanov Svilen-Stefanov changed the title fix: save the base as soon as it is built, explain refused pushes, and stop early on a spent quota fix: save the base as soon as it is built, and explain refused pushes Dec 6, 2026
@Svilen-Stefanov
Svilen-Stefanov merged commit 1a05a05 into main Dec 6, 2026
5 checks passed
@Svilen-Stefanov
Svilen-Stefanov deleted the fix/save-base-early-explain-sync branch December 6, 2026 16:56
Svilen-Stefanov added a commit to CodeBoarding/CodeBoarding that referenced this pull request Dec 6, 2026
…quota is spent (#712)

* feat: stop a hosted run before static analysis when the CodeBoarding quota is spent

A large repository's Action run spent many minutes on static analysis before
its first LLM call, and only then learned the free-tier quota was spent. The
hosted proxy gates every request on the caller's weekly quota before
forwarding it and meters only completions, so a GET /models through the same
client answers 402 at no token cost. bootstrap_environment now makes that one
request on hosted credentials and raises the same LLMQuotaError the runtime
path raises, so full, incremental and partial runs exit 3 with Core's message.
Any other answer lets the run go on. Own provider keys are never checked.

Replaces the Action-side probe removed from CodeBoarding/CodeBoarding-action#184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: log the quota check's trace, report its stop, and check full runs only

- A check that gets no usable answer is logged with logger.exception, so its
  traceback is kept (AGENTS.md: never lose the trace).
- A quota it finds is sent to PostHog via capture_error("quota_check"):
  mid-run quota errors reach it through track_analysis, this one stops the
  run before any tracked analysis starts.
- Only full runs are checked up front. They spend minutes on tool installs
  and static analysis before the first LLM call; an incremental run may need
  no LLM call, so a spent quota stops it only if it reaches one.
- The client is built inside the try, so any failure lets the run go on, and
  uses the provider's own key instead of the placeholder constant.
- LLMQuotaError.is_codeboarding_quota is gone: only its own __init__ read it.
- Tests use the relay's real base URL (no /v1), assert tool installs never
  start and the stop is reported, and share one copy of the 402 body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: type the recorded requests in the quota CLI tests

CI runs mypy over the tests too; the two empty lists needed their type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor: check the quota in every CLI bootstrap, without a flag

Hosted credentials reach Core only through the Action, which runs the CLI, and every CLI run starts in bootstrap_environment. Checking there unconditionally covers full, incremental and partial runs, including the full run an incremental starts after an engine change, which the full_run flag missed.

The check reports its own stop to PostHog, so bootstrap calls it in one line; its docstring is down to a summary and a Why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants