Skip to content

Show context window usage for ACP clients - #1283

Merged
SawyerHood merged 2 commits into
mainfrom
bb/acp-context-window-usage-1111-thr_k9gmb2hkkc
Aug 10, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/acp-context-window-usage-1111-thr_k9gmb2hkkc

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

  • parse stable ACP usage_update notifications
  • translate exact used and size values into BB context-window events
  • preserve usage reports during session restore and before the first turn
  • increment the host-daemon protocol version for the new event behavior

Root cause

The ACP bridge forwarded usage_update as an untyped session update. The adapter classified it as noise, so the server never received a context-window event. The bridge also discarded all session updates during session/load.

Validation

  • reproduced the issue with a failing ACP adapter test: valid usage returned no events
  • ACP, domain, and host-daemon contract tests pass: 1,032 tests
  • server tests pass: 1,391 tests
  • focused server ingest and timeline test passes
  • affected package type checks pass
  • host-daemon and server builds pass

Closes #1111

@SawyerHood
SawyerHood marked this pull request as ready for review August 10, 2026 20:20
@SawyerHood

SawyerHood commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am now reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

Comment thread packages/agent-runtime/src/acp/bridge/bridge.ts Outdated

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5

BB now shows how full an ACP agent's memory box is. It works like a fuel gauge.

One restore path can show the old box level after BB starts a new box.

Finding

P2 — A failed session restore can publish stale context usage.

The bridge now forwards usage while session/load is still pending. If the load fails, BB starts a fresh session.

The old usage event remains on the timeline. The UI can then show the old session's usage for the new session.

The bridge also parses sessionId, but it does not check that value. I left one inline comment with the recommended fix and tests.

Other review results

  • Security: I found no data leak, command injection, or permission problem.
  • Code quality: The adapter validates the new fields and rejects malformed values.
  • Architecture: The code uses the existing context-usage event path. The provider implementations have different source data, so a shared helper adds little value.
  • Performance: Each update adds one small event. I found no new unbounded loop or expensive hot-path work.
  • Protocol: The change correctly increases HOST_DAEMON_PROTOCOL_VERSION from 94 to 95.

End-to-end check

I started the source app and ran a real OpenCode ACP thread.

OpenCode reported 11,460 used tokens from a 200,000-token window. The UI showed 6% used and 94% left.

Checks

  • ACP adapter and bridge: 95 tests passed.
  • Host daemon contract: 35 tests passed.
  • Server event ownership: 8 tests passed.
  • GitHub CI: all required checks passed.
  • git diff --check: passed.

I posted this as a comment only. I did not approve the pull request or request changes.

@SawyerHood

Copy link
Copy Markdown
Collaborator Author

🚨 SLOP COP 🚨 · review

I am SlopCop. I am starting the review now. I will check security, code quality, architecture, performance, and the main user path.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5: ACP agents can now tell BB how much model memory they use. BB shows that value in the existing context meter.

I found no actionable findings.

  • Security: The code validates usage data at the ACP boundary. It also rejects updates for a different restored session.
  • Code quality: The split is clean. The wire layer validates, the adapter normalizes, and the domain defines event scope.
  • Architecture: I found no stale names, material duplicate logic, or useful refactor for this change.
  • Performance: Resume keeps one latest usage snapshot. Normal updates remain small, and existing event pruning bounds storage.
  • Compatibility: The daemon protocol increases from 94 to 95 for the new cross-process behavior.

I tested exact SHA 361acba8. The focused ACP, contract, server, and type checks passed. All GitHub checks also passed.

I also ran a live OpenCode ACP thread through the exact-sha dev server. The browser showed 6% used and 11k / 200k tokens.

One small test opportunity remains. A future test could cover session/load through runtime identity and timeline storage in one automated path.

@SawyerHood
SawyerHood merged commit 3f1a4d6 into main Aug 10, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/acp-context-window-usage-1111-thr_k9gmb2hkkc branch August 10, 2026 20:53
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
## Summary

- parse stable ACP `usage_update` notifications
- translate exact `used` and `size` values into BB context-window events
- preserve usage reports during session restore and before the first
turn
- increment the host-daemon protocol version for the new event behavior

## Root cause

The ACP bridge forwarded `usage_update` as an untyped session update.
The adapter classified it as noise, so the server never received a
context-window event. The bridge also discarded all session updates
during `session/load`.

## Validation

- reproduced the issue with a failing ACP adapter test: valid usage
returned no events
- ACP, domain, and host-daemon contract tests pass: 1,032 tests
- server tests pass: 1,391 tests
- focused server ingest and timeline test passes
- affected package type checks pass
- host-daemon and server builds pass

Closes get-bb#1111
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.

Show Context Window Usage for ACP clients

1 participant