Skip to content

refactor(agents-gateway): deslop agents and gateway - #165907

Merged
steipete merged 3 commits into
mainfrom
deslop/l402-types-guards-agents-gateway-20261005
Oct 6, 2026
Merged

steipete merged 3 commits into
mainfrom
deslop/l402-types-guards-agents-gateway-20261005

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Agent and Gateway code maintains duplicate declarations for contracts already owned by schemas, parsers, factories, and runtime types. Internal callers also repeat checks for states their producers exclude.

User Impact

No intended user-visible behavior change. Configuration keys, protocol and persisted-data shapes, CLI output, model-facing tool descriptions, and UI behavior are preserved. Wire, plugin, persisted-data, and live-authority validation stays in place.

Why This Change Was Made

This batch removes 1,042 net production lines (+595/−1,637) across agents and Gateway code. No code moves outside the monorepo; tests, fixtures, documentation, generated files, and ratchets are excluded from that measurement.

Simplifications and ownership
  • Session entries, extension events, tool definitions, provider settings, and user-input questions reuse agent-core, runtime, and protocol contracts, retaining their intentional overrides.
  • Sandbox and worktree types derive configuration/protocol fields while retaining required normalized settings and narrower internal states.
  • Runtime auth, catalog, media-job, native-search, and plugin-tool option bags reuse existing owner signatures instead of restating them.
  • Gateway request-client metadata derives shared WebSocket facts; node callbacks reuse registry signatures. Transport-specific and synthetic-client refinements remain explicit.
  • Gateway service, parser, projector, HTTP response, credential-plan, and usage types derive their concrete producers. Receiver-free service methods retain explicit this: void declarations.
  • Embedded stream settlement returns one captured snapshot instead of coordinating parallel mutable result variables.
  • Session resolution and store-key helpers lose single-use forwarding/option layers. Already-validated node/client facts, admitted placement states, and non-null model defaults no longer repeat impossible-state checks.
  • Narrating comments are removed from reviewed modules. Comments explaining authority, ordering, cleanup, lazy loading, and compatibility remain.

The runtime-plan leaf contract and named SDK service interfaces retain their independent declarations. Catalog-specific context-window metadata and canonical tool/audio type references remain explicit where their owners differ from the wider schema.

Evidence

Candidate: 376675539fbbc9154c18b594c94f5ede1e04a9c4, based on 381b1e05d7f0fa572fdf085e7714d4f90864d4b5.

  • On the final committed tree, isolated Linux/Node 24.19 validation passed pnpm tsgo:prod, the six-file integration/correction selection (133 tests), type-aware native core lint (103 files, zero warnings/errors), the assertion ratchet, and all production/script/full-tree unused-export scans (zero entries).
  • Both check-madge-import-cycles.ts and check-import-cycles.ts reported zero cycles on that tree.
  • Broader scoped runtime proof covered 81 selected files across the initial and correction runs. The 21-file correction/remaining selection passed 436 tests. All 27 core/UI/package test-type shards passed before the conflict-only main integration; production types and affected runtime tests were refreshed afterward.
  • SDK API comparison: no entrypoints or exports added or removed. Three public signature spellings change without changing their structural contracts: the Gateway client manifest parameter derives its owner signature, and two channel-status helpers infer their existing result fields. Reachable declaration rewrites were inspected; acknowledgement digest f4908eee.
  • Independent P0–P2 review covered the batch and corrections. All actionable issues are resolved. A reported byte-response union concern was rejected against the existing as const branch and successful typechecking.

Validation caught an incomplete catalog-type substitution and a poll-timer substitution incompatible with the existing controlled-clock test; both were removed. Named auth-limiter and service interfaces were retained for declaration-generation boundaries. No assertions, timeouts, retries, or skips were weakened. The final rebase preserves the new auth-worker code and drops three overlapping comment-only edits. Hosted CI will validate the published head.

Hosted CI attribution

Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/37402143477 (candidate 376675539fbbc9154c18b594c94f5ede1e04a9c4; tested merge a07f68217e16aeabf1f704d3e0d1b3f50b3533c0 onto 0c7a83dd65c676b1c224458d06ce4bdb69ea51ac).

  • security-fast fails production dependency auditing on source-map-js advisory GHSA-68fv-2mgg-jv7q. The same advisory fails current main run https://github.com/openclaw/openclaw/actions/runs/37402399816 at c20c6e5822d741c03831cac8ad805aace1735de3. This batch does not change package manifests, the lockfile, or the audit owner.
  • checks-node-changed-compact-large-19 fails sessions.abort-agent-scope.test.ts → “marks listed sessions active when the embedded or channel reply run registry owns the session id”: expected the sess-weixin resolver mock to be called, received zero calls. The identical assertion fails independent PR run https://github.com/openclaw/openclaw/actions/runs/37402164985/job/112072099860 at cba67cba259f4a910f5f78b871296bebbf19530f. Main commit 70cfa76a35450625b7d070b753e6778fbb78ffd8, merged after this branch's base, introduced an inventory exclusion in createVisibleActiveSessionRunProjector. The fixture supplies a row and mocks the downstream resolver without registering an embedded/reply/projected/subagent inventory owner, so that new branch returns before the mock. This PR changes neither that fixture nor its resolver, registry inventory, list handler, or presentation call path. Nearby session type/key simplifications do not supply or remove any active-run inventory; the synthetic projection fixture bypasses the changed row-scope implementation. The coordinator owns this inherited fixture failure.

Complete paginated exact-head accounting: 181 check runs, 115 successful, three failed (the two roots above plus downstream openclaw/ci-gate), 61 skipped, one neutral, and one cancelled duplicate Auto response run. No test or check job remains pending. All type, lint, dependency, baseline, architecture, and other selected test jobs passed. The aggregate gate log reports the inherited security and Node-shard failures; the cancelled Auto response is separate from CI and a succeeding Auto response is recorded on the same head. The authorized inherited-failure exception applies to exact head 376675539fbbc9154c18b594c94f5ede1e04a9c4; this does not describe CI as green.

Derive internal contracts from their schema, factory, and runtime owners; simplify proven internal states and local forwarding layers while preserving public output and lifecycle boundaries.
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 376675539fbbc9154c18b594c94f5ede1e04a9c4
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/constants.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/credential-state.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/display.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/effective-oauth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/external-cli-auth-selection.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/external-cli-discovery.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/external-cli-scope.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/identity.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-identity.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-refresh-lock-errors.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-shared.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/policy.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/portability.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/profile-list.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/state-observation.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/runtime-plan/auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/runtime-plan/credential-scoped-model.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/runtime-plan/prepare-auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/sandbox/fs-bridge.types.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/types.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/credential-planner.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/server-methods/device-management-authz.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 6, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 5, 2026, 10:06 PM ET / October 6, 2026, 02:06 UTC.

ClawSweeper review

What this changes

The branch replaces duplicate agent and Gateway type declarations with their existing owners and simplifies internal guards, forwarding helpers, and stream-result capture.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this remains useful, distinct cleanup, and the recorded member/admin authority excludes automatic closure. Source review found no concrete blocking defect.

Priority: P3
Reviewed head: 376675539fbbc9154c18b594c94f5ede1e04a9c4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Coherent ownership cleanup with no concrete defect found; reported validation supplements the source review.
Proof confidence 🌊 off-meta tidepool Not applicable: The recorded admin-author exemption applies to this internal cleanup. Settlement and transport validation is reported in the body; no real setup execution was independently verified, and no material authority or stored-format change was found.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The recorded admin-author exemption applies to this internal cleanup. Settlement and transport validation is reported in the body; no real setup execution was independently verified, and no material authority or stored-format change was found.
Evidence reviewed 10 items Pinned introduced changes: Read the introduced agent and Gateway hunks against the verified merge base, rather than attributing current-main endpoint drift to this branch. The cleanup remains absent from the inspected main implementation.
Verified merge parentage: The raw test-merge parents are the pinned main SHA followed by the exact PR head. Its inspected settlement, send, and session-row changes match the introduced cleanup and do not support a claim that newer main work is removed.
Stream settlement preserves ownership: The complete settlement module retains transcript-write admission, compaction snapshot selection, prompt-error handling, and cancellation recovery. The changed callback returns its captured result through the existing generic write owner.
Findings None None.
Security None None.

How this fits together

The Gateway validates client requests and supplies agent runs with session, credential, and execution context. Agent runtime code then calls providers and settles messages, usage, and transcript work for downstream responses.

flowchart LR
  A[Client requests] --> B[Gateway validation]
  B --> C[Agent run preparation]
  D[Schema and runtime contracts] --> C
  C --> E[Provider transport]
  E --> F[Stream settlement]
  F --> G[Session state and replies]
Loading

Before merge

  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

None.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/agents/auth-profiles/oauth-shared.ts, unknown-truncated-pull-files. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep schema and runtime producers authoritative while preserving existing wire shapes, persisted formats, and lifecycle validation.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this proposes behavior-preserving cleanup rather than a reported bug; no failing runtime path was established during this read-only review.

Is this the best way to solve the issue?

Yes: deriving duplicate contracts from existing producers follows repository ownership guidance, and the inspected runtime simplifications preserve upstream validation and settlement boundaries.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0c7a83dd65c6.

Labels

Label changes:

  • add P3: This is internal cleanup with no intended user-visible behavior change or demonstrated urgent regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The recorded admin-author exemption applies to this internal cleanup. Settlement and transport validation is reported in the body; no real setup execution was independently verified, and no material authority or stored-format change was found.

Label justifications:

  • P3: This is internal cleanup with no intended user-visible behavior change or demonstrated urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The recorded admin-author exemption applies to this internal cleanup. Settlement and transport validation is reported in the body; no real setup execution was independently verified, and no material authority or stored-format change was found.

Evidence

What I checked:

  • Pinned introduced changes: Read the introduced agent and Gateway hunks against the verified merge base, rather than attributing current-main endpoint drift to this branch. The cleanup remains absent from the inspected main implementation. (376675539fbb)
  • Verified merge parentage: The raw test-merge parents are the pinned main SHA followed by the exact PR head. Its inspected settlement, send, and session-row changes match the introduced cleanup and do not support a claim that newer main work is removed. (a07f68217e16)
  • Stream settlement preserves ownership: The complete settlement module retains transcript-write admission, compaction snapshot selection, prompt-error handling, and cancellation recovery. The changed callback returns its captured result through the existing generic write owner. (src/agents/embedded-agent-runner/run/attempt-stream-settle.ts:292, 376675539fbb)
  • Removed patch guards have a schema owner: The unchanged protocol schema permits only policy version 1 or null and arrays or null for inherited allow/deny lists. Both single and batch session-patch handlers validate before applying mutations, supporting removal of duplicate internal shape checks. (packages/gateway-protocol/src/schema/sessions-patch.ts:86, 376675539fbb)
  • Authentication boundary retained: Handshake validation rejects malformed connection parameters before client admission. Device-management authorization still distinguishes device-token callers from ordinary shared-auth device metadata; the existing focused tests cover that distinction. (src/gateway/server-methods/device-management-authz.ts:14, 376675539fbb)
  • Placement invariant remains authoritative: Active placement records require an environment and owner epoch, and assertRecordShape enforces those facts at admission. Removing their repeated checks in process observation does not change the admitted ownership contract. (src/gateway/worker-environments/placement-record.ts, 376675539fbb)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Landing the reviewed head 376675539fbbc9154c18b594c94f5ede1e04a9c4 under the maintainer-authorized inherited-failure exception. The complete paginated check census has 181 terminal check runs: 115 successful, 61 skipped, one neutral, one superseded Auto response cancellation, and exactly these three failures:

  1. security-fast (job): source-map-js GHSA-68fv-2mgg-jv7q. The same advisory fails current main CI. No dependency, lockfile, or audit input changes here.
  2. checks-node-changed-compact-large-19 (job): sessions.abort-agent-scope.test.ts expects the sess-weixin resolver mock but receives zero calls. The identical test/assertion fails in independent CI. Main commit 70cfa76a354 added the inventory exclusion before that resolver after this branch's base. The fixture does not register an inventory owner; all owners on that failing call path are unchanged by this batch. The changed row-scope implementation is bypassed by this synthetic fixture.
  3. openclaw/ci-gate (job): aggregate failure from those two roots. No additional failed or pending CI job.

All selected type, lint, dependency, baseline, architecture, and other runtime-test jobs passed. Independent review and the remote validation described in the PR remain valid. These inherited failures belong to the main CI coordinator; this is not a claim of green hosted CI.

@steipete
steipete merged commit 62b807d into main Oct 6, 2026
188 of 193 checks passed
@steipete
steipete deleted the deslop/l402-types-guards-agents-gateway-20261005 branch October 6, 2026 02:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
Derive agent and Gateway contracts from their schema, parser, factory, and runtime owners; simplify proven internal states and small forwarding layers. Retain named SDK declaration boundaries and all wire, persisted-data, plugin-input, and live-authority validation.

Removes 1,042 net production lines. Remote production/test type checks, focused runtime tests, lint, unused-export scans, assertion safety, both zero-cycle gates, SDK API comparison, and independent review support the change. Public SDK exports do not grow.

Closes openclaw#165907.

Hosted CI: all selected type/lint/dependency/baseline/architecture and other test jobs passed. Landed under the inherited-failure exception for the source-map-js advisory and the independently reproduced sessions activity fixture failure introduced by main commit 8f677ff; see PR evidence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant