Repository navigation
feat(agentsapi): preserve native output and tool history - #156182
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
83be6a4 to
df05b1a
Compare
df05b1a to
a18a434
Compare
|
Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 12:12 AM ET / 04:12 UTC (Revision 8). ClawSweeper reviewWhat this changesThe Agents API plugin projects native command activity, commentary, reasoning, saved tool history, and token usage into OpenClaw chat output and transcripts, including after a stream reconnect. Merge readiness✅ Ready for maintainer review Keep open: current main has the shared projection prerequisite but does not provide this Agents API behavior. The current-head admitted-turn disconnect evidence addresses the previous proof blocker, and this review found no concrete introduced defect. Priority: P2 Review scores
Verification
How this fits togetherThe Agents API plugin sends configured OpenAI turns to a hosted native session and receives streamed events and saved records. It turns those records into Gateway output callbacks and durable OpenClaw transcript entries. flowchart LR
A[Chat input] --> B[Gateway run]
B --> C[Agents API plugin]
C --> D[Hosted session]
D --> E[Stream and saved records]
E --> F[Projection and reconciliation]
F --> G[Chat output and transcript]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +2070, Tests +302, Docs +39. Total +2411 across 10 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Agents API turns should retain one coherent live and durable record per native item across completion, cancellation, and reconnect, while reporting usage that is available at settlement. Do we have a high-confidence way to reproduce the issue? Not applicable to this feature PR. The submitted current-head Docker and Slack runs give a concrete after-change behavior path; this read-only review did not run the plugin. Is this the best way to solve the issue? Yes. The plugin retains native protocol handling and uses the already merged shared projection contracts, avoiding a second core presentation owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 86c2919245f7. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
|
Real Slack presentation captures for public implementation c378fc9. These use different fixtures: the earlier failed readiness attempt, a fresh italic commentary marker while its command was active, and a plain final answer. They establish rendered presentation only. Steering, cancellation, reconnect, and usage acceptance are not established by these screenshots. Earlier failed readiness attempt: Commentary delivered during a live command: Plain final answer: |
69216a4 to
6568fc5
Compare
c378fc9 to
61cb8a0
Compare
6568fc5 to
1b8e97a
Compare
1b8e97a to
ca34ddd
Compare
ClawSweeper: "Retain observed usage when the final REST read fails" #156182 (comment) Merge final REST usage with observed usage by admitted turn ID. Canonical records replace matching contributions, while omitted turns keep observed usage and repeated accounting does not double count them.
8d6057c to
5f5c49f
Compare
ClawSweeper: "Retain observed usage when the final REST read fails" #156182 (comment) Merge final REST usage with observed usage by admitted turn ID. Canonical records replace matching contributions, while omitted turns keep observed usage and repeated accounting does not double count them.
bdcbcab to
69b99db
Compare
|
@clawsweeper re-review The PR body now contains real Docker/Slack evidence from the published Please assess the updated evidence and stated limits. A separate setup persisted zero usage while later native reads reported nonzero usage; the settlement snapshots were not retained, so the cause is unresolved. The disconnect checks aborted before reservation or injection, and reconnect remains unverified. The conditional null-ID historical-user finding is still unapplied while the maintainer considers it. No external-session import or attachment path exists, and no such record was observed in these plugin-created sessions. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review The PR evidence now includes a successful real admitted-turn disconnect on current head After genuine native command admission and START output, the Gateway's accepted TLS/HTTP/1 SSE socket was physically destroyed once. One replacement stream received HTTP 200 1.183 seconds after observed closure. The same VM command completed once with exit 0 after 61.873 seconds. Native saved records, normalized events, and durable history agree on one call/result pair, two commentary records, one final, and one positive usage row; repeated reads were byte-identical and Slack delivered one final. Command usage matches native accounting at 105,023 tokens, setup at 57,662, and session total at 162,685. Native is idle, both turns completed, the Gateway settled, the binding has no lease, and all persistent-work counts are zero. The test Slack connection was released after settlement while retaining the Gateway process. Direct setup snapshots show null terminal-event and normal REST usage followed by positive cleanup REST usage 1.708 seconds after the completed normal REST snapshot; that positive accounting persisted correctly. This does not establish the cause of the earlier unexplained 57,858-token setup discrepancy. Its original settlement snapshots remain unavailable. Capture limits are documented: the command's primary usage observer stopped at admission, and an auxiliary native reader captured START but ended before DONE. Completion and usage rely on canonical native REST records, normalized events, durable history, and actual Slack delivery, rather than unavailable observer snapshots. No REST accounting failure was induced; empty/partial accounting regressions protect the approved fix. Please review the updated proof and remaining accounting limit. No further source changes were made, and exact-head CI remains green. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…6182) * feat(agentsapi): project native output and reconcile saved history * fix(agentsapi): retain observed usage after accounting read failures ClawSweeper: "Retain observed usage when the final REST read fails" openclaw#156182 (comment) Merge final REST usage with observed usage by admitted turn ID. Canonical records replace matching contributions, while omitted turns keep observed usage and repeated accounting does not double count them. * test(agentsapi): cover projection usage and authoritative session receipts * refactor(agentsapi): keep projection implementation helpers module-local * test(agentsapi): use the projection factory and preserve fixture types --------- Co-authored-by: Sarah Fortune <[email protected]>



Why
OpenClaw needs to present Agents API native activity through the same output and history contracts used by its other harnesses. Sharing presentation operations lets the adapter keep native protocol handling without duplicating transcript and callback policy.
What Problem This Solves
Agents API command output, commentary, reasoning summaries, saved session state, and billed usage must reach the host consistently during streaming and recovery. This PR wires those native records into the shared projection operations merged in #156187 and sits before the tools and file-transfer layers.
Changes
Evidence
Independent source review of the lower-stack implementation and approved usage fix is clean. The shared refactor retains its relocated output-formatting tests beside their owner.
The current published head is
69b99db14f9eaa27a49efd84a5ff1d55a77bfeaa, rebased onto main after #156187 merged. All five wiring commits replay patch-identically; the Agents API and shared projection source bytes match the testedbdcbcab846d5c18e91ed1a8953ab65dcc72e19c9. Current-head CI is green, with all 42 selected checks passing. Its six Node test shards took 3 minutes 35 seconds from first start to last completion, with 18 minutes 8 seconds summed runtime and a longest shard of 3 minutes 35 seconds.Validation on the pre-rebase implementation:
pnpm test extensions/agentsapi/agentsapi-messages.test.ts --maxWorkers=1, including cold compiler preparation; test bodies total 10 milliseconds).pnpm test extensions/agentsapi/agentsapi-session.test.ts --maxWorkers=1).Pre-rebase CI is green. Its six Node test shards took 1 minute 49 seconds from first start to last completion, with 7 minutes 3 seconds summed runtime and a longest shard of 1 minute 43 seconds.
Fresh real Docker/Slack proof used a native Linux/arm64 image built from
bdcbcab846d5c18e91ed1a8953ab65dcc72e19c9, with runtime/UI compilation and actual bundled-plugin loading verified. The packaged Slack plugin required its standalone package-local dependency layout; the correction preserved source and dependency pins. No mocks, fakes, or direct native input bypasses were used./stopreached a running VM command. Actual native output contained its running marker, the command failed with exit status 130, the native session became idle, one error tool result was persisted, and Slack delivered the stopped result. The Gateway reported no active run.Additional real Docker/Slack proof ran on the current published
69b99db14f9eaa27a49efd84a5ff1d55a77bfeaahead, using a separate native Linux/arm64 Gateway and fresh state:An additional current-head recovery run used a separate native Linux/arm64 Docker Gateway, fresh state, the configured default model, and ordinary Slack input:
capture_validation_failure, and an auxiliary read-only subscriber captured START but ended before DONE. Command completion and accounting are therefore established by canonical native REST records, normalized events, durable history, and Slack delivery, rather than missing observer snapshots.Limits: an earlier command's early stdout was absent from both native saved work and its observed stream; the current-head runs above separately prove actual streamed START and DONE delivery. Two nonempty reasoning summaries from the earlier interrupted turn are persisted once, but the default Gateway history response filters them through shared heartbeat presentation logic; a separate proposed correction is awaiting approval. The fresh current-head runs returned only empty reasoning summaries. The earlier zero-usage settlement remains unexplained because its original terminal/final REST snapshots were not retained. Live tests did not induce a final REST accounting failure; the focused regressions cover empty and partial reads. ClawSweeper's latest review identified no actionable code or security findings and dropped the conditional historical null-ID concern because no reachable legacy-session path or such row was established.