Skip to content

Usage is very high (#18) - #19

Merged
ableinc merged 2 commits into
mainfrom
agent/issue-18-usage-is-very-high
Aug 30, 2026
Merged

Usage is very high (#18)#19
ableinc merged 2 commits into
mainfrom
agent/issue-18-usage-is-very-high

Conversation

@ableinc

@ableinc ableinc commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Closes #18

What the agent did

This matches the plan's file list exactly. I'll leave version control to the harness as instructed (not committing).

Summary

Implemented the approved plan for issue #18 (cut per-run token usage) across three parts:

Part A — cache reads reported separately from fresh input

  • internal/claude/runner.go: added FreshTokensIn(), CacheWriteTokens(), CacheReadTokens() accessors.
  • internal/store/store.go: new migration (entry 3) adding tokens_cache_read/tokens_cache_write columns; Run, runColumns, scanRun updated; RecordUsage now takes a RunUsage struct instead of 7 positional args.
  • Four call sites updated (loop.go, prcomments.go, both RecordUsage calls plus claude_done event details) and two in store_test.go, plus a new migration test TestMigrationAddsCacheTokenColumns.
  • internal/web/assets/app.js: new fmtTokensBreakdown helper, used in the runs table and run detail view.
  • internal/discord/notifier.go: Tokens embed field now shows the fresh/written/cached split.

Part B — trim the harness prompt (internal/orchestrator/prompt.go)

  • Tightened constants (maxBodyChars 12000→6000, maxCommentChars 2000→1200, maxCommentsInclu 12→6), added maxPlanChars, maxPRCommentsInclu, maxDiffHunkChars, maxReviewsInclu.
  • issueContext now filters out harness-authored comments (isAgentComment) and bare approvals (isApproval) before applying the comment window, and omits the ### Discussion header when nothing survives the filter.
  • implementTaskPrompt/planTaskPrompt cap the plan with truncate; prCommentTaskPrompt caps comment count, diff-hunk size, and review count.
  • Added tests: filtering, empty-discussion edge case, PR-comment cap, and a bounded-size regression test.

Part C — stop the CLI loading ambient operator context (internal/claude/runner.go)

  • Added --strict-mcp-config, --disable-slash-commands, --exclude-dynamic-system-prompt-sections, --autocompact 200000 as hardcoded args, before ExtraArgs. Added TestRunPassesTokenReductionFlags.

Also updated README.md's Prompts section and the verbatim claude … invocation block to document all of this.

Verification: go build ./... succeeds; go test ./... passes for every package except internal/git, which fails on main too (pre-existing environmental identity-config mismatch, unrelated to any file this change touches — verified no diff exists in internal/git).

Note for reviewer: early in the session I accidentally ran a bare git stash push that briefly stashed this in-progress work; I recovered it immediately via git stash apply <sha> (not pop) and dropped the entry — final git status confirms only the intended 11 files are modified, matching the plan's file list exactly.

Verification

Tests failed (make test). This PR is a draft — the failure is reported rather than hidden, so you can judge whether the change is salvageable.

Test output (tail)
go test -race ./...
go: golang.org/toolchain@v0.0.1-go1.26.5.linux-arm64: verifying module: golang.org/toolchain@v0.0.1-go1.26.5.linux-arm64: open /home/node1/go/pkg/sumdb/sum.golang.org/latest: read-only file system
make: *** [Makefile:122: test] Error 1

Changes

README.md                            | 22 +++++++++-
 internal/claude/runner.go            | 34 +++++++++++++++
 internal/claude/runner_test.go       | 36 ++++++++++++++++
 internal/discord/notifier.go         |  3 +-
 internal/orchestrator/loop.go        | 17 ++++++--
 internal/orchestrator/prcomments.go  | 17 ++++++--
 internal/orchestrator/prompt.go      | 51 ++++++++++++++++++----
 internal/orchestrator/prompt_test.go | 82 ++++++++++++++++++++++++++++++++++++
 internal/store/store.go              | 38 ++++++++++++++---
 internal/store/store_test.go         | 43 +++++++++++++++++--
 internal/web/assets/app.js           | 15 ++++++-
 11 files changed, 328 insertions(+), 30 deletions(-)

Opened automatically by coding-agent-loop (run b328b7bb-cc7a-451c-b698-00fbcad54205, attempt 3, model claude-sonnet-5, cost $2.2602, session d328a89e-cafd-4133-a8b1-2435aa7f4c48). Nothing here has been reviewed by a human yet.

Closes #18

Generated by coding-agent-loop run b328b7bb-cc7a-451c-b698-00fbcad54205.
@ableinc ableinc mentioned this pull request Aug 30, 2026
@ableinc
ableinc marked this pull request as ready for review August 30, 2026 03:59
@ableinc
ableinc merged commit 7b1eb23 into main Aug 30, 2026
8 checks passed
@ableinc
ableinc deleted the agent/issue-18-usage-is-very-high branch August 30, 2026 04:01
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.

Usage is very high

1 participant