Skip to content

refactor(infra): consolidate service paths and usage rollups - #119433

Merged
steipete merged 1 commit into
mainfrom
codex/loc-0804-infra-luem8u
Aug 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/loc-0804-infra-luem8u

Conversation

@steipete

@steipete steipete commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Daemon startup and usage accounting independently repeated platform PATH assembly, service identity selection, and timestamped versus untimestamped rollup projection. This is part of a maintainer-requested project-wide production LOC reduction campaign.

Why This Change Was Made

Consolidate equivalent platform/service path and usage accumulation owners while preserving Nix/workspace ordering, service identity, and all model/tool/cost accounting.

User Impact

No service-startup or usage-reporting behavior changes; removes 120 production lines.

Evidence

Exact-head service setup and usage-rollup runtime proof

The actual committed daemon service environment, node service, and usage-rollup production modules were executed through a TypeScript-stripping Node VM. Their source bytes were verified against the exact Git blobs; an in-memory native service-manager fixture avoided all operator state, service mutation, and network access.

{
  "head":"9a5c08677fe38139b619f3d54ef3bffff044d866",
  "sourceBlobs":{"src/daemon/node-service.ts":"fff737bc75ae3ba97b38fe2e08a7e8a7e886805a","src/daemon/service-env.ts":"89ce13f04490fb3282461234715d9ca4257da713","src/infra/session-cost-usage-rollup.ts":"1914833be0904d54d7e9f2ad91b4e4f74e2b7019","src/infra/session-cost-usage.types.ts":"ec67a3015419324d358fa3714c71c71b395c4e16"},
  "serviceSetup":{"linuxPathPrefix":["/usr/local/bin","/usr/bin","/bin"],"pnpmRoots":["/fixtures/home/.local/share/pnpm","/fixtures/home/.local/share/pnpm/bin"],"workspacePathRejected":true,"nixProfilePrecedence":["/fixtures/home/.nix-profile/bin","/nix/default/bin"],"macosLaunchAgentPath":"/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin","windowsPersistsInstallTimePath":false,"nodeInstall":{"programArguments":["/fixtures/runtime/bin/node","node-host"],"launchdLabel":"ai.openclaw.node","systemdUnit":"openclaw-node","windowsTaskName":"OpenClaw Node","windowsTaskScript":"node.cmd","serviceKind":"node","serviceMarker":"openclaw","pathFirst":"/fixtures/runtime/bin","credentials":"[REDACTED]"},"statusProbeTimeoutMs":1234},
  "usageRollup":{"timestamps":[1785931200000,1785931202000],"lastUserTimestamp":1785931200000,"bounded":{"totalTokens":55,"totalCost":0.125,"messageCounts":{"total":2,"user":1,"assistant":1,"toolCalls":2,"toolResults":1,"errors":2},"toolUsage":{"totalCalls":2,"uniqueTools":1,"tools":[{"name":"weather","count":2}]},"models":[{"provider":"fixture-provider","model":"fixture-model","count":1}],"latency":{"count":1,"avgMs":2000,"p95Ms":2000,"minMs":2000,"maxMs":2000},"missingCostByModel":{"fixture-provider/fixture-model":1}},"includingUntimestamped":{"totalTokens":62,"totalCost":0.132,"messageCounts":{"total":3,"user":1,"assistant":2,"toolCalls":3,"toolResults":2,"errors":2},"untimestampedTokens":7,"latencySamples":1}},
  "assertions":"PASS"
}

This observed runtime artifact fulfills the requested service-setup and usage-rollup evidence. The reviewed Git head remains unchanged; root policy explicitly does not require another bot review after a body-only evidence update.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 5, 2026
@steipete
steipete marked this pull request as ready for review August 5, 2026 02:49
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 11:22 PM ET / August 5, 2026, 03:22 UTC.

ClawSweeper review

What this changes

This PR consolidates daemon service-path and node-service setup plus session usage-rollup accumulation while preserving platform service identities and cost-reporting behavior.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. This remains a distinct, behavior-preserving refactor with no actionable correctness finding; its protected maintainer label requires a maintainer-owned merge decision.

Priority: P3
Reviewed head: 9a5c08677fe38139b619f3d54ef3bffff044d866
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused refactor has consistent owner-boundary behavior, existing coverage, successful supplied checks, and exact-head runtime output.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body includes exact-head terminal output that verifies all changed source blobs and reports PASS for service setup plus bounded and untimestamped usage-rollup behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes exact-head terminal output that verifies all changed source blobs and reports PASS for service setup plus bounded and untimestamped usage-rollup behavior.
Evidence reviewed 6 items Exact-head service behavior: The node adapter still overlays the same node-specific service identity fields for install and lifecycle calls; the install environment remains optional and is safely normalized before overlay.
Service-path owner and consumers: The unified path builder retains the platform-specific Darwin/Linux manager roots, Nix ordering, workspace rejection, and Windows early return; guarded generic service operations consume the supplied environment.
Usage-rollup invariant: Timestamped and untimestamped entries still receive identical totals/count/model updates, while only timestamped buckets proceed to latency and last-user timestamp updates.
Findings None None.
Security None None.

How this fits together

Managed daemon setup converts CLI install and control requests into platform service definitions with a minimal PATH and node-specific identity. Session transcript parsing feeds incremental usage rollups, which produce bounded and all-time cost reports.

flowchart LR
  A[Daemon CLI request] --> B[Node service adapter]
  B --> C[Platform service definition]
  D[Session transcript] --> E[Usage rollup]
  E --> F[Cost and usage report]
Loading

Decision needed

Question Recommendation
Should this protected maintainer cleanup be adopted after a current-base merge review? Adopt the refactor: Merge after confirming the current-base result retains the inspected service-path and usage-rollup behavior.

Why: The patch is behavior-preserving and clean, but the protected maintainer label reserves final merge scope for a human owner.

Before merge

  • Resolve merge risk (P1) - GitHub reports the branch behind current main; review the actual current-base merge result before landing, although no touched path changed after this PR’s parent.
Agent review details

Security

None.

PR surface

Source -120. Total -120 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 4 66 186 -120
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 66 186 -120

Review metrics

Metric Value Why it matters
Production versus test LOC production -120, tests 0 The stated LOC-reduction goal is achieved entirely in production code, so preservation evidence from existing tests and exact-head runtime output matters before merge.

Stored data model

Persistent data-model change detected: serialized state: src/infra/session-cost-usage-rollup.ts, serialized state: src/infra/session-cost-usage.types.ts, unknown-data-model-change: src/infra/session-cost-usage-rollup.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the single canonical service-path and rollup flows, then land only if a current-base review preserves the inspected platform and reporting invariants.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the single canonical service-path and rollup flows, then land only if a current-base review preserves the inspected platform and reporting invariants.

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

Not applicable: this PR claims behavior preservation rather than a bug fix; its exact-head runtime artifact exercises the changed service and rollup paths.

Is this the best way to solve the issue?

Yes. Consolidating the duplicated logic at the existing service-environment and rollup owners is the narrowest maintainable approach, and the sibling platform/reporting paths were checked.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a8caab5c3d3c.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes exact-head terminal output that verifies all changed source blobs and reports PASS for service setup plus bounded and untimestamped usage-rollup behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes exact-head terminal output that verifies all changed source blobs and reports PASS for service setup plus bounded and untimestamped usage-rollup behavior.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is a low-risk internal cleanup with no reported user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes exact-head terminal output that verifies all changed source blobs and reports PASS for service setup plus bounded and untimestamped usage-rollup behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes exact-head terminal output that verifies all changed source blobs and reports PASS for service setup plus bounded and untimestamped usage-rollup behavior.

Evidence

What I checked:

  • Exact-head service behavior: The node adapter still overlays the same node-specific service identity fields for install and lifecycle calls; the install environment remains optional and is safely normalized before overlay. (src/daemon/node-service.ts:32, 9a5c08677fe3)
  • Service-path owner and consumers: The unified path builder retains the platform-specific Darwin/Linux manager roots, Nix ordering, workspace rejection, and Windows early return; guarded generic service operations consume the supplied environment. (src/daemon/service-env.ts:238, 9a5c08677fe3)
  • Usage-rollup invariant: Timestamped and untimestamped entries still receive identical totals/count/model updates, while only timestamped buckets proceed to latency and last-user timestamp updates. (src/infra/session-cost-usage-rollup.ts:228, 9a5c08677fe3)
  • Existing boundary coverage and proof: Existing service-path and session-cost tests cover Nix/workspace/platform paths and bounded-versus-untimestamped reporting; the PR body supplies a PASS terminal artifact whose four reported blob IDs match the exact head. (src/daemon/service-env.test.ts:302, 9a5c08677fe3)
  • Current-main distinction: No commit after the PR parent changed any of the four touched paths on current main, and the PR head is not an ancestor of main; the work is neither implemented nor superseded. (src/daemon/service-env.ts:238, a8caab5c3d3c)
  • Feature provenance: The persisted session-rollup feature dates to the identified incremental-rollup commit; current surrounding source attributes to a recent area contributor. (src/infra/session-cost-usage-rollup.ts:228, b8b064a9483e)

Likely related people:

  • steipete: Authored the original persisted session-rollup feature and this focused consolidation. (role: original rollup feature author and current refactor author; confidence: high; commits: b8b064a9483e, 9a5c08677fe3; files: src/infra/session-cost-usage-rollup.ts, src/infra/session-cost-usage.types.ts)
  • vincentkoc: Current-main provenance for the daemon and usage-rollup surroundings is attributed to this recent area commit. (role: recent area contributor; confidence: medium; commits: 6293b54250fc; files: src/daemon/service-env.ts, src/daemon/node-service.ts, src/infra/session-cost-usage-rollup.ts)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-05T03:04:47.234Z sha 9a5c086 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 5, 2026
@steipete
steipete merged commit 2692954 into main Aug 5, 2026
197 of 213 checks passed
@steipete
steipete deleted the codex/loc-0804-infra-luem8u branch August 5, 2026 03:39
@steipete

steipete commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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