Skip to content

refactor(acp): dedup tool-call progress at the source (O(n²)→O(1)) - #3465

Merged
enyst merged 2 commits into
mainfrom
acp-progress-dedup-at-source
Jun 2, 2026
Merged

enyst merged 2 commits into
mainfrom
acp-progress-dedup-at-source

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Problem

ACP persisted every ToolCallProgress emission, each carrying the full cumulative output (acp_agent.py session_update; _default_callback persists each one). For a chatty tool call that is O(n²) storage + WebSocket relay — and on cloud the proxy relays and persists every cumulative frame across the network, the single biggest relay/storage cost. The regular agent persists exactly one Action + one Observation per tool call, with no per-progress fan-out.

Part of OpenHands/agent-canvas#2110 (epic OpenHands/OpenHands#15746). Implements pre-cloud refactor P1-1.

Change

Collapse ACP onto the regular agent's action→observation model. The bridge now persists exactly two events per tool_call_id:

  • one early started event (the action) on ToolCallStart, and
  • one terminal completed/failed event (the observation) on the first transition into a terminal status.

Intermediate ToolCallProgress frames are accumulated silently (so the terminal event still carries the final, complete output) but not emitted — this is the O(n²)→O(1) collapse. _finalize_successful_turn flushes any tool call the server opened but never closed to completed, so every started has a matching terminal observation (no orphaned "running" cards).

Downstream merges: kept, not deleted

The original issue suggested deleting the three downstream tool_call_id dedups. Those dedups serve a second purpose beyond papering over O(n²): they merge a tool call's lifecycle events into one card — exactly the analog of an ObservationEvent superseding its ActionEvent. With the source now emitting a started + terminal pair (not N cumulative frames), deleting them would render two cards per call. So they are retained but become trivial O(1) two-event merges; their comments are updated to describe the new semantics:

  • RemoteConversation._add_event_unsafe
  • resume_transcript._terminal_tool_indices

(The canvas handle-event-for-ui merge + the should-render gate are handled in the paired agent-canvas PR.)

Tests

  • New TestACPToolCallProgressCollapse: started emits once; intermediate progress frames do not emit; full lifecycle emits exactly two events; the terminal event carries the final cumulative output; single-shot terminal ToolCallStart emits once; redundant terminal frames don't double-emit; the finalize flush completes orphaned calls.
  • New resume_transcript test asserting a started→terminal pair renders only the terminal frame (terminal-event semantics).
  • Full affected suites green: tests/sdk/agent/test_acp_agent.py, tests/sdk/agent/test_acp_dedup_and_truncation.py, tests/sdk/event/test_resume_transcript.py (342 passed); ruff check + ruff format clean.

Pairs with

agent-canvas PR (relaxes the should-render gate to render the running started card): link added in a comment below.

🤖 Generated with Claude Code


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:04c6dc0-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-04c6dc0-python \
  ghcr.io/openhands/agent-server:04c6dc0-python

All tags pushed for this build

ghcr.io/openhands/agent-server:04c6dc0-golang-amd64
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-golang-amd64
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-golang-amd64
ghcr.io/openhands/agent-server:04c6dc0-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:04c6dc0-golang-arm64
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-golang-arm64
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-golang-arm64
ghcr.io/openhands/agent-server:04c6dc0-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:04c6dc0-java-amd64
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-java-amd64
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-java-amd64
ghcr.io/openhands/agent-server:04c6dc0-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:04c6dc0-java-arm64
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-java-arm64
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-java-arm64
ghcr.io/openhands/agent-server:04c6dc0-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:04c6dc0-python-amd64
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-python-amd64
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-python-amd64
ghcr.io/openhands/agent-server:04c6dc0-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:04c6dc0-python-arm64
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-python-arm64
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-python-arm64
ghcr.io/openhands/agent-server:04c6dc0-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:04c6dc0-golang
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-golang
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-golang
ghcr.io/openhands/agent-server:04c6dc0-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:04c6dc0-java
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-java
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-java
ghcr.io/openhands/agent-server:04c6dc0-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:04c6dc0-python
ghcr.io/openhands/agent-server:04c6dc083193adcaf2744ff52db92bd6dbb008e6-python
ghcr.io/openhands/agent-server:acp-progress-dedup-at-source-python
ghcr.io/openhands/agent-server:04c6dc0-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 04c6dc0-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 04c6dc0-python-amd64) are also available if needed

ACP persisted one ACPToolCallEvent per ToolCallProgress notification, each
carrying the full cumulative output, so a chatty tool call cost O(n^2) storage
plus WebSocket relay (and on cloud, O(n^2) proxy relay/persist of every
cumulative frame). The regular agent persists exactly one Action + one
Observation per tool call.

Collapse ACP onto that model. The bridge now persists exactly two events per
tool_call_id: one early `started` event (the action) on ToolCallStart and one
terminal completed/failed event (the observation) on the first transition into
a terminal status. Intermediate ToolCallProgress frames are accumulated
silently so the terminal event still carries the final output.
_finalize_successful_turn flushes any tool call the server opened but never
closed to `completed`, guaranteeing every `started` has a matching terminal
observation (no orphaned "running" cards).

The downstream tool_call_id merges (RemoteConversation._add_event_unsafe and
resume_transcript._terminal_tool_indices) are kept: they now merge the 2-event
started->terminal pair into one card -- an O(1) merge, the analog of an
Observation superseding its Action -- rather than the old O(n^2) per-frame
dedup. Their comments are updated to match.

Part of OpenHands/agent-canvas#1025 (epic #988). Pairs with the agent-canvas PR
that relaxes the should-render gate to render the running `started` card.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@simonrosenberg

Copy link
Copy Markdown
Member Author

Paired canvas PR (renders the running started card): OpenHands/agent-canvas#1027

@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@simonrosenberg simonrosenberg self-assigned this Jun 2, 2026

all-hands-bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/agent
   acp_agent.py94810289%485–487, 617–618, 660, 662, 666, 670, 690, 753–754, 759, 826, 1040, 1043–1044, 1061–1062, 1091, 1096, 1172, 1182, 1218–1221, 1479–1482, 1486–1488, 1491–1495, 1497, 1707, 1721–1722, 1725–1727, 1735, 1739, 1743–1744, 1750–1751, 1763–1764, 1767, 1801, 1805–1807, 1811–1812, 1844, 2066–2068, 2071–2072, 2112, 2252, 2256, 2264–2266, 2304–2305, 2308, 2316–2318, 2320, 2322, 2326, 2329, 2338–2340, 2342, 2378–2379, 2397–2400, 2403, 2407–2409, 2411, 2415–2416, 2621–2622
openhands-sdk/openhands/sdk/conversation/impl
   remote_conversation.py6898188%143, 170, 183, 185–188, 198, 207, 220–221, 226–229, 313, 323–325, 331, 409, 556–559, 561, 587–591, 596–599, 602, 618, 773–774, 778–779, 793, 839, 852–853, 877–878, 901–904, 906–907, 933, 943, 947, 956–957, 996, 1146–1147, 1241–1242, 1246, 1251–1255, 1261–1267, 1280, 1285, 1327, 1540–1541
openhands-sdk/openhands/sdk/event
   resume_transcript.py1631292%81, 83, 85, 135, 139, 152, 155–156, 159–161, 320
TOTAL28688826771% 

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

Solid, well-reasoned refactor. The root cause is correctly identified — emitting one ACPToolCallEvent per cumulative ToolCallProgress frame is O(n²) storage and WebSocket relay — and the fix is clean: collapse to an action→observation pair (one started event on ToolCallStart, one terminal event on the first transition into completed/failed). The backward-compat note in _terminal_tool_indices for pre-refactor persisted logs is good defensive thinking, and the flush of unclosed cards in _finalize_successful_turn closes the invariant neatly.

Two items worth addressing:

_emit_tool_call_event docstring is now stale

Lines 695–699 still say "Called from session_update on each ToolCallStart / ToolCallProgress". After this PR it is called on ToolCallStart and on the first terminal ToolCallProgress only, plus the new _flush_inflight_tool_calls_as_completed path. A one-line update avoids future confusion.

_flush_inflight_tool_calls_as_completed reaches into a private method of _OpenHandsACPBridge

ACPAgent._flush_inflight_tool_calls_as_completed calls self._client._emit_tool_call_event(tc) directly. Both types are module-private (underscore-prefixed) so this works, and _cancel_inflight_tool_calls already follows the same pattern — it's consistent. Flagging purely as a future-cleanup note: moving flush_inflight_as_completed onto _OpenHandsACPBridge itself would co-locate the full single-event lifecycle with the bridge and let ACPAgent call a slightly higher-level method. Not a blocker.

See inline comment for the one concrete suggestion.

This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

Comment on lines +681 to 687
became_terminal = (
target is not None
and target.get("status") in _TERMINAL_TOOL_CALL_STATUSES
and prev_status not in _TERMINAL_TOOL_CALL_STATUSES
)
if target is not None and became_terminal:
self._emit_tool_call_event(target)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: became_terminal already includes target is not None as its first conjunct, so the outer guard on line 686 is always true when became_terminal is true and always false when it's false — the two conditions are redundant. Simplifying to if became_terminal: makes the intent clearer and removes the implicit claim that the two checks are independent.

Suggested change
became_terminal = (
target is not None
and target.get("status") in _TERMINAL_TOOL_CALL_STATUSES
and prev_status not in _TERMINAL_TOOL_CALL_STATUSES
)
if target is not None and became_terminal:
self._emit_tool_call_event(target)
became_terminal = (
target is not None
and target.get("status") in _TERMINAL_TOOL_CALL_STATUSES
and prev_status not in _TERMINAL_TOOL_CALL_STATUSES
)
if became_terminal:
self._emit_tool_call_event(target)

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ QA Report: PASS WITH ISSUES

Functional QA confirms ACP tool-call progress is collapsed from cumulative progress fan-out to a two-event lifecycle, but the PR currently has one failing CI check.

Does this PR achieve its stated goal?

Yes. The stated goal was to collapse ACP ToolCallProgress persistence from O(n²) cumulative-frame fan-out to O(1) lifecycle events while preserving final output and avoiding orphaned running cards. Using real agent-client-protocol schema notifications against the SDK runtime path, origin/main emitted 5 ACPToolCallEvents for one chatty tool call, while this PR emitted exactly 2 (pending + completed) and the completed event carried the final output. The PR-only orphan flush also converted an in-progress accumulated call to a completed ACPToolCallEvent.

Phase Result
Environment Setup ✅ make build completed successfully; no tests/linters were run.
CI Status ⚠️ At check time: 19 success, 8 in progress, 1 failure (Python API breakage check), 1 skipped.
Functional Verification ✅ ACP progress collapse, transcript single-card rendering, and orphan flush behavior were exercised.
Functional Verification

Test 1: Chatty ACP tool call emits lifecycle events instead of every cumulative progress frame

Step 1 — Reproduce / establish baseline (without the fix):
Ran git checkout origin/main && uv run python /tmp/qa_acp_progress.py:

{
  "event_count": 5,
  "events": [
    {"status": "pending", "raw_output": null},
    {"status": "in_progress", "raw_output": "chunk-1"},
    {"status": "in_progress", "raw_output": "chunk-1
chunk-2"},
    {"status": "completed", "raw_output": "chunk-1
chunk-2
final"},
    {"status": "completed", "raw_output": "chunk-1
chunk-2
final
redundant-terminal"}
  ],
  "transcript_tool_use_count": 1,
  "transcript_contains_redundant_terminal": true
}

This confirms the baseline problem: every progress notification, including intermediate cumulative output and redundant terminal output, was emitted as an ACPToolCallEvent.

Step 2 — Apply the PR's changes:
Checked out decc2240ef4c345e91bce5bc3d364c7c6265848e.

Step 3 — Re-run with the fix in place:
Ran git checkout decc2240ef4c345e91bce5bc3d364c7c6265848e && uv run python /tmp/qa_acp_progress.py:

{
  "event_count": 2,
  "events": [
    {"status": "pending", "raw_output": null},
    {"status": "completed", "raw_output": "chunk-1
chunk-2
final"}
  ],
  "transcript_tool_use_count": 1,
  "transcript_contains_redundant_terminal": false
}

This shows the changed behavior works: intermediate in_progress frames and a duplicate terminal frame are no longer emitted, while the terminal event still has the final cumulative output. A follow-up transcript render showed one [TOOL USE: chatty shell command] (completed) card with output lines chunk-1, chunk-2, and final.

Test 2: In-flight ACP tool call can be flushed to a terminal completed event

Step 1 — Reproduce / establish baseline (without the fix):
Ran git checkout origin/main && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_orphan.py:

{
  "flush_available": false,
  "accumulated_status": "in_progress",
  "emitted_events": []
}

This establishes the prior state: there was no flush helper, and an accumulated tool call with no closing progress frame remained in_progress.

Step 2 — Apply the PR's changes:
Checked out decc2240ef4c345e91bce5bc3d364c7c6265848e.

Step 3 — Re-run with the fix in place:
Ran git checkout decc2240ef4c345e91bce5bc3d364c7c6265848e && OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_acp_orphan.py:

{
  "flush_available": true,
  "accumulated_status": "completed",
  "emitted_events": [
    {
      "class": "ACPToolCallEvent",
      "tool_call_id": "orphan-1",
      "status": "completed",
      "raw_output": "partial output before prompt returned",
      "is_error": false
    }
  ]
}

This confirms the PR's orphan-card safeguard works at the SDK runtime level: a non-terminal accumulated tool call is converted to a terminal completed observation with its partial output preserved.

Issues Found

  • 🟠 Issue: CI is not currently green: Python API in Python API breakage checks is failing (job link). I did not rerun or diagnose CI as part of QA.

This QA review was created by an AI agent (OpenHands) on behalf of the requester.

Final verdict: PASS WITH ISSUES

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

LGTM

enyst
enyst previously requested changes Jun 2, 2026

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

Thank you for this! I actually think complexity stuff is fairly important, as we’ve stepped into the era of long running histories.

Just would like to take a moment, please, for us to understand the Python API breakage: why is it failing?

@enyst

enyst commented Jun 2, 2026

Copy link
Copy Markdown
Member

@OpenHands Understand this PR and check the Griffe API breakage workflow which fails in CI right now. Why is it failing, and WDYT, is the workflow too strict and maybe we could relax it or is it a real breakage downstream, or? Post your response directly as a comment.

@openhands-ai

openhands-ai Bot commented Jun 2, 2026

Copy link
Copy Markdown

I'm on it! enyst can track my progress at all-hands.dev

enyst commented Jun 2, 2026

Copy link
Copy Markdown
Member

I checked the PR diff, the linked ACP issue context, and the failing Python API/Griffe job.

Short version: this failure is not caused by the ACP progress-dedup change in this PR. The only reported breakages are:

  • ToolDefinition.acall
  • MCPToolDefinition.acall (reported separately because it inherited the public member)

Those come from the already-merged chore(sdk): remove dead Tool.acall method (Q1 of OpenHands/OpenHands#3341) change in OpenHands/OpenHands#3456 / commit 88b43b44, which is already on main and is an ancestor of this PR branch. This PR's diff does not touch openhands-sdk/openhands/sdk/tool/* or openhands-sdk/openhands/sdk/mcp/*; it only changes the ACP bridge/event merge behavior and tests.

My take:

  1. As an attribution issue, the workflow is too noisy for this PR. It compares the full PR branch against the latest published PyPI baseline (openhands-sdk 1.24.0 vs 1.24.0), so once an unreleased breaking change lands on main, every later PR based on main can re-fail even if unrelated. That's what happened here. For PR ergonomics, it would be reasonable to also compare against the PR base ref and only fail PRs for newly introduced API breakage, while keeping the PyPI comparison as a report/release gate.

  2. As a compatibility finding, Griffe is not wrong. ToolDefinition and MCPToolDefinition are exported public SDK symbols (openhands.sdk.__all__, plus package __all__), so removing a public method that existed in the released SDK is a source-level API break. Even if the framework never dispatched through acall internally, downstream code could still have called await tool.acall(...) or overridden it. So I would not broadly relax the “removed public class member” rule.

  3. Best fix IMO: restore ToolDefinition.acall as a deprecated compatibility shim rather than deleting it immediately. It can keep the old behavior (run_in_executor(None, self, action, conversation)) and emit the standard deprecation warning/metadata with a removal target at least 5 minor releases out (e.g. if deprecated in 1.24.0, removal no earlier than 1.29.0). Since MCPToolDefinition inherits it, that should address both reported removals. The docstring can explicitly say the SDK execution path does not call this hook, so custom async overrides are not honored by the framework.

So: this PR's ACP change looks unrelated to the CI failure. I would not change this PR for it unless we want to opportunistically include the compatibility shim here; otherwise the right follow-up is either revert/deprecate the OpenHands/OpenHands#3456 removal on main, or adjust the PR workflow to fail only on breakage introduced relative to the PR base while preserving the stricter PyPI check for release readiness.

This comment was created by an AI agent (OpenHands) on behalf of the requester.

@openhands-ai

openhands-ai Bot commented Jun 2, 2026

Copy link
Copy Markdown

OpenHands encountered an error: Request timeout after 30 seconds to https://drnpzzvchqbqlytn.prod-runtime.all-hands.dev/api/conversations/75ee4c28-d469-4b0c-b82f-810a2425df63/ask_agent

See the conversation for more information.

enyst commented Jun 2, 2026

Copy link
Copy Markdown
Member

Follow-up: I opened a separate non-draft revert PR from main to fix the Griffe API breakage here: OpenHands/OpenHands#3466

That PR reverts OpenHands/OpenHands#3456 / 88b43b44 and restores ToolDefinition.acall, which is what the Python API workflow is currently failing on. I’ll babysit OpenHands/OpenHands#3466 until checks are green and it gets approved.

This comment was created by an AI agent (OpenHands) on behalf of the requester.

@enyst
enyst dismissed their stale review June 2, 2026 15:59

Sorry, my agent dug in and found out that the API breakage wasn’t caused by this PR!

@enyst
enyst enabled auto-merge (squash) June 2, 2026 17:01
@enyst
enyst merged commit 2e946e9 into main Jun 2, 2026
27 of 28 checks passed
@enyst
enyst deleted the acp-progress-dedup-at-source branch June 2, 2026 17:04
simonrosenberg pushed a commit that referenced this pull request Jun 2, 2026
The regular terminal masks every observation via
secret_registry.mask_secrets_in_output(); ACP masked nothing, so a
subprocess that echoed an injected credential (env, a failing curl
printing an Authorization header) landed in the persisted event stream
and WebSocket relay in cleartext — the largest credential-leak surface,
widened on cloud where subscription tokens are injected.

Route ACP output through the registry mask before emitting:
- streamed AgentMessageChunk text (on_token + accumulated_text) and
  AgentThoughtChunk text
- tool-call title/raw_input/raw_output/content, masked at ingestion so
  the started event, the single terminal event (#3465 dedup), and the
  flush/supersede path all carry masked values and the accumulator never
  holds plaintext
- the joined response_text/thought_text in _finalize_successful_turn
  (persistence boundary), which also catches secrets split across
  stream chunks

Complete the mask set for the channels that bypass get_secret_value:
seed _exported_values for the agent_context.secrets drain and the
(deprecated, #3464) acp_env via a new SecretRegistry.track_exported_value
with a minimum-length guard so trivially short non-secret config
(e.g. VERBOSITY=1) is not masked. The state.secret_registry channel
auto-seeds via get_secret_value.

A failing masker falls back to the original value (crash-safe), matching
the terminal tool contract. The live on_token relay still forwards a
secret split mid-value across chunks as fragments; the persisted stream
is fully masked.

Implements pre-cloud refactor P0-2 (OpenHands/agent-canvas#1023).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
simonrosenberg pushed a commit that referenced this pull request Jun 3, 2026
The regular terminal masks every observation via
secret_registry.mask_secrets_in_output(); ACP masked nothing, so a
subprocess that echoed an injected credential (env, a failing curl
printing an Authorization header) landed in the persisted event stream
and WebSocket relay in cleartext — the largest credential-leak surface,
widened on cloud where subscription tokens are injected.

Route ACP output through the registry mask before emitting:
- streamed AgentMessageChunk text (on_token + accumulated_text) and
  AgentThoughtChunk text
- tool-call title/raw_input/raw_output/content, masked at ingestion so
  the started event, the single terminal event (#3465 dedup), and the
  flush/supersede path all carry masked values and the accumulator never
  holds plaintext
- the joined response_text/thought_text in _finalize_successful_turn
  (persistence boundary), which also catches secrets split across
  stream chunks

The mask set is the registry's _exported_values, seeded by
get_secret_value when _start_acp_server reads state.secret_registry —
the canonical channel that #3464 routes provider creds and (on the
caller/cloud path) agent_context.secrets through. No new SecretRegistry
API; the deprecated acp_env / canvas-local drain are out of scope.

A failing masker falls back to the original value (crash-safe), matching
the terminal tool contract. The live on_token relay still forwards a
secret split mid-value across chunks as fragments; the persisted stream
is fully masked (follow-up: OpenHands/agent-canvas#1049).

Implements pre-cloud refactor P0-2 (OpenHands/agent-canvas#1023).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
simonrosenberg pushed a commit that referenced this pull request Jun 3, 2026
The regular terminal masks every observation via
secret_registry.mask_secrets_in_output(); ACP masked nothing, so a
subprocess that echoed an injected credential (env, a failing curl
printing an Authorization header) landed in the persisted event stream
and WebSocket relay in cleartext — the largest credential-leak surface,
widened on cloud where subscription tokens are injected.

Bind the registry masker onto the bridge once in _start_acp_server
(conversation-stable; a pure read of _exported_values with none of the
cross-thread/state-lock hazards that make on_event/on_token per-turn)
and route ACP output through it before emitting:
- streamed AgentMessageChunk text (on_token + accumulated_text) and
  AgentThoughtChunk text
- tool-call title/raw_input/raw_output/content, masked at ingestion so
  the started event, the single terminal event (#3465 dedup), and the
  flush/supersede path all carry masked values and the accumulator never
  holds plaintext
- the ask_agent() fork accumulator + its joined return value, which is
  relayed to the caller/UI (binding the masker once is what makes this
  reachable even when ask_agent runs while no turn is active)
- the joined response_text/thought_text in _finalize_successful_turn
  (persistence boundary), which also catches secrets split across chunks

The mask set is the registry's _exported_values, seeded by
get_secret_value when _start_acp_server reads state.secret_registry —
the canonical channel that #3464 routes provider creds and (on the
caller/cloud path) agent_context.secrets through. No new SecretRegistry
API; the deprecated acp_env / canvas-local drain are out of scope.

A failing masker falls back to the original value (crash-safe), matching
the terminal tool contract. The live on_token relay still forwards a
secret split mid-value across chunks as fragments; the persisted stream
is fully masked (follow-up: OpenHands/agent-canvas#1049).

Implements pre-cloud refactor P0-2 (OpenHands/agent-canvas#1023).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
…penHands#3465)

Co-authored-by: Debug Agent <debug@example.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Engel Nyst <engel.nyst@gmail.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.

4 participants