Skip to content

feat(agentloop): Token-/Kosten-Budget mit Hard-Cap (issue #151) - #228

Merged
Delqhi merged 1 commit into
mainfrom
feat/issue-151-token-budget
Jun 16, 2026
Merged

feat(agentloop): Token-/Kosten-Budget mit Hard-Cap (issue #151)#228
Delqhi merged 1 commit into
mainfrom
feat/issue-151-token-budget

Conversation

@Delqhi

@Delqhi Delqhi commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Implements issue #151. MaxTokens + BudgetWarnRatio + Completion.Usage.

Closes #151

What ships:
  - cmd/sin-code/internal/agentloop/loop.go:
    - New Completion.Usage + Usage struct (PromptTokens, CompletionTokens, TotalTokens).
    - New Loop.MaxTokens field: 0 disables (backwards-compatible).
    - New Loop.BudgetWarnRatio field: fraction of MaxTokens that fires hooks.BudgetWarn.
    - Token accumulator state (totalTokens, warnedBudget).
    - Budget check after appending msgs: if total >= MaxTokens, fires
      BudgetExhausted + records TypeTokenBudgetExhausted + either
      returns an error or a checkpointed Result (AllowContinuation).
  - cmd/sin-code/internal/ledger/store.go: new EntryType TypeTokenBudgetExhausted.
  - cmd/sin-code/internal/hooks/hooks.go: new events BudgetWarn, BudgetExhausted.
  - cmd/sin-code/internal/agentloop/loop_token_test.go: 3 tests
    (disabled, exhausts, allow-continuation).

Acceptance criteria (from #151):
  - [x] MaxTokens caps cumulative tokens across the run.
  - [x] MaxTokens=0 disables the guard (legacy behavior).
  - [x] BudgetWarnRatio fires hooks.BudgetWarn once when crossed.
  - [x] AllowContinuation converts the cap into a checkpoint.
  - [x] go test ./cmd/sin-code/internal/agentloop/... all green.

Hard mandates honored:
  - M2: no new deps.
  - M3: token accounting is post-verify; never short-circuits the gate.
  - M7: 3/3 tests pass under go test -race -count=1.

Refs: #151
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sin-code Ready Ready Preview, Comment, Open in v0 Jun 16, 2026 8:33pm

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/ronaldokrause-9559s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/einskarst-2238s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-young-hobby-team-24h").

Learn More: https://vercel.com/karstenblau45-2395s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/sagamundis-1139s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/aragonheld-7756s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/mariobatrhs-9606s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/cristianoronalodbau-9053s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-young-hobby-team-24h").

Learn More: https://vercel.com/spriterfrau-5830s-projects?upgradeToPro=build-rate-limit

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-young-hobby-team-24h").

Learn More: https://vercel.com/manheiler-8784s-projects?upgradeToPro=build-rate-limit

@github-actions

Copy link
Copy Markdown

🏆 CEO Audit — A+ (100.0/100)

Metric Value
Grade A+
Score 100.0/100
Critical findings 0
High findings 0
Profile QUICK
Min grade gate B

📥 Download full report (Markdown)
📊 Download SARIF (for Code Scanning)

Run ~/.config/opencode/skills/ceo-audit/scripts/audit.sh . --profile=QUICK locally to reproduce.

@github-actions

Copy link
Copy Markdown

🏆 CEO Audit — A+ (100.0/100)

Metric Value
Grade A+
Score 100.0/100
Critical findings 0
High findings 0
Medium findings 0
Profile QUICK
Min grade gate B

📥 Download full report (Markdown)

Run ID: 27646324747 · Commit: ${github.sha}

Run ~/.config/opencode/skills/ceo-audit/scripts/audit.sh . --profile=QUICK locally to reproduce.

@Delqhi
Delqhi merged commit 5ff1979 into main Jun 16, 2026
8 of 11 checks passed
@Delqhi
Delqhi deleted the feat/issue-151-token-budget branch June 16, 2026 20:35
TypeStallDetected EntryType = "stall_detected"
// TypeTokenBudgetExhausted is recorded when cumulative token usage exceeds
// MaxTokens and the run stops spending (issue #151).
TypeTokenBudgetExhausted EntryType = "token_budget_exhausted"
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.

Loop: Token-/Kosten-Budget mit Hard-Cap

2 participants