Skip to content

Fix: Stop recording OpenCode's own polling after a proxy restart - #1269

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/selftraffic-child
Oct 5, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/selftraffic-child

Conversation

@huang195

@huang195 huang195 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Summary

After a proxy restart, an idle OpenCode window shows up in agentop as a pending:opencode@<pid>.<start> row. Its event count climbs by about three per second, and it has no tokens or cost. All of it is the TUI polling its own background service (/api/session, /api/plugin, /api/location, …). The self-traffic rule was written to keep exactly that traffic out of the timeline, but it stops working after a restart.

Why: selfTraffic treated a loopback listener as the agent's own only once it had named a session through its own header (IsAgentProcess). Those claims live in memory, so a restart clears them. A window nobody has typed into has a service that has named nothing, so every poll got recorded into the TUI's pending bucket. On the next prompt that bucket was merged into the real session, polling included.

Seen on a laptop: proxy.log shows the rule skipping exe=…/opencode service=127.0.0.1:49374 service_pid=45463 on Oct 2 and Oct 3. After the Oct 4 restart it never fired, and the bucket grew to 400+ rows in two minutes. 45463 is opencode serve --service, a direct child of the opencode TUI (45462).

Change

agentsOwnService accepts the listener, with no session history needed, when all of the following hold:

  • it runs the client's executable (unchanged; still checked in selfTraffic)
  • it is the client's direct child (PPID == client.PID; peerproc.Proc already carries it)
  • it did not start before the client, since a child cannot predate its parent, so an earlier start means a reused pid
  • the client identifies as a coding agent by User-Agent (affinityClient). Without this, a test suite starting a server of its own interpreter and calling it would also go dark, and that traffic is the agent's work.

Otherwise it falls back to the existing IsAgentProcess check, so the existing behavior is unchanged.

Out of scope: OpenCode's local-model probes (Ollama :11434, LM Studio :1234, :8000/health) are not self-traffic and stay recorded, so a smaller pending bucket can still appear. A follow-up agentop PR changes how such rows are displayed.

Tests

New cases in core/listener/forwardproxy/process_test.go:

  • an agent's direct-child service, same executable, never claimed: forwarded, not recorded
  • an agent's child running another executable (e.g. a node MCP server): recorded
  • a program that is not an agent (python-requests) calling its own python child: recorded
  • a listener older than the client, with its parent pid matching: recorded

Each condition was checked by removing it from the code and confirming that at least one test then fails. GOWORK=off go test ./... in core passes; gofmt -l and go vet are clean.

docs/laptop-service.md is updated: the "until then it is recorded" caveat no longer applies to a child service.

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • Bug Fixes
    • Agent-owned local services that run the agent’s executable are now excluded from the activity timeline from their first request when they are direct child processes, rather than only after naming a session. This also applies after a proxy restart.
    • Requests from unrelated processes and services that do not meet these conditions continue to appear in the timeline.
  • Documentation
    • Updated the laptop service guide to explain which local services are excluded and when Cortex logs them.

The self-traffic rule trusted a loopback listener only once it had named a
session through its own header. Those claims live in memory, so after a proxy
restart an idle OpenCode window's service had named nothing, and the TUI's
polling — about three requests a second — was recorded into its pending bucket
until the next prompt, then adopted into the session with it.

OpenCode starts its service as the TUI's child. Accept a listener that runs the
client's executable and is the client's direct child as the agent's own, which
needs no history. The client must also identify as a coding agent, since a test
suite starting a server of its own interpreter has the same shape and is the
agent's work; and the child must not predate its parent, which would mean a
reused pid.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63f10308-9c08-4d4c-bea9-18dea53f9ade
📥 Commits

Reviewing files that changed from the base of the PR and between e18722f and d1e6422.

📒 Files selected for processing (3)
  • core/listener/forwardproxy/process.go
  • core/listener/forwardproxy/process_test.go
  • docs/laptop-service.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The listener now excludes qualifying agent child-service traffic from recording before the service names a session. Tests cover related process cases, and the laptop-service documentation describes the updated behavior.

Changes

Agent child-service attribution

Layer / File(s) Summary
Detect agent child services
core/listener/forwardproxy/process.go, core/listener/forwardproxy/process_test.go, docs/laptop-service.md
The self-traffic check recognizes a direct child with a qualifying start time and nonempty affinity, or a process identified as an agent. Tests cover forwarding and recording cases. The documentation describes when the service is skipped and logged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: abigailgold

Merge Risk: ⚪ Minimal · up to d1e64

The change stops an agent's own child-service polling from being recorded after a proxy restart. Requests are still forwarded, and no merge-blocking risk was found.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to d1e64

The new exclusion can mistake a tool-started local server for internal polling and skip configured security checks, not just timeline recording. Exposure requires matching local process relationships; no remote or cross-user compromise was demonstrated.

Retained concerns

  • Medium · security · inferred: Direct-child ownership plus executable equality does not distinguish internal polling from actual agent work. For example, a Node-based agent calling a directly spawned Node MCP server with its recognized User-Agent satisfies the new predicate without the server ever naming a session. Such requests now bypass both recording and configured outbound security policies. The existing interpreter-agent test covers a sibling server, while the added different-executable test does not protect this same-interpreter child case.
Security review details

Security Blast Radius

  • observed — The new exemption requires enabled process attribution, an identified caller with a known executable, and a loopback destination whose listener qualifies. It applies without an endpoint or HTTP-method restriction. Bridged requests are excluded from this self-traffic branch.

Security Findings and Attack Paths

  • inferred — A local caller able to create a same-executable child listener can assert recognized affinity and obtain the new exemption without a listener session claim. A legitimate interpreter-based agent can also meet these conditions unintentionally when calling its own tool server. Configured pipeline rejection controls would not inspect those requests; no deployed policy bypass or downstream privilege gain was demonstrated.

Trust Boundaries and Controls

  • observed — Network headers alone cannot manufacture the required local process relationship: ownership comes from process lookups, executable paths must match, and an older listener fails the new child predicate. However, the previous fallback also relies on client-asserted session claims. Existing source explicitly treats session headers as attribution rather than authentication and directs deployments using session-state authorization to disable header grouping, which also disables this process-attribution path.

Resilience and Maintainability Implications

  • observed — The exclusion occurs before session claims, request events, pipeline reservations or finisher registration. Success and upstream failure therefore suppress both sides of recording rather than leaving an unmatched event or started plugin operation. Listener ownership remains cached per connection for 30 seconds; this pre-existing cache is not revalidated on each request, although qualification is reevaluated.

Hardening Proposals

  • proposed — Separate timeline suppression from security-policy execution, or constrain the exemption using service-specific identity beyond a shared interpreter executable and caller-declared affinity. Include a same-interpreter direct-child tool-server case when validating the boundary.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: stop recording OpenCode’s own polling after a proxy restart.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Reviewed the agentsOwnService predicate against upstream and it holds up well:

  • Both the client (ConnOwner/Ancestry) and listener lookups go through the same s.Processes resolver, so the l.Start.UnixNano() >= client.Start comparison is valid within the documented peerproc.Proc.Start comparability contract.
  • The four-condition gate (same exe, direct child, not older than parent, agent User-Agent) each has a dedicated test that fails when its condition is removed — good coverage discipline.
  • The fallback to IsAgentProcess keeps existing behavior unchanged for non-child listeners.
  • The User-Agent gate via affinityClient correctly avoids hiding a test suite's calls to its own interpreter-spawned server.

No blocking issues.

Comment thread docs/laptop-service.md
executable and is either the agent's direct child or has named a session. OpenCode
starts its service as the TUI's child, so its polling stays out of the timeline from
the first request, including after a proxy restart. The first time it is skipped
Cortex logs which program and service. It is `session.process_attribution`: `auto` (the default) means on for this

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.

nit: this sentence ("It is session.process_attribution: auto (the default) means on for this loopback-only install…") now runs well past the file's usual wrap width — worth rewrapping the paragraph for consistency with the rest of the doc.

@huang195
huang195 merged commit 3404451 into rossoctl:main Oct 5, 2026
29 checks passed
@huang195
huang195 deleted the fix/selftraffic-child branch October 5, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants