Repository navigation
Fix: Stop recording OpenCode's own polling after a proxy restart - #1269
Conversation
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]>
|
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
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe 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. ChangesAgent child-service attribution
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to 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 ReviewSecurity architecture risk: 🟡 Moderate · up to 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
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
pdettori
left a comment
There was a problem hiding this comment.
Reviewed the agentsOwnService predicate against upstream and it holds up well:
- Both the client (
ConnOwner/Ancestry) and listener lookups go through the sames.Processesresolver, so thel.Start.UnixNano() >= client.Startcomparison is valid within the documentedpeerproc.Proc.Startcomparability 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
IsAgentProcesskeeps existing behavior unchanged for non-child listeners. - The User-Agent gate via
affinityClientcorrectly avoids hiding a test suite's calls to its own interpreter-spawned server.
No blocking issues.
| 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 |
There was a problem hiding this comment.
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.
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:
selfTraffictreated 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.logshows the rule skippingexe=…/opencode service=127.0.0.1:49374 service_pid=45463on Oct 2 and Oct 3. After the Oct 4 restart it never fired, and the bucket grew to 400+ rows in two minutes.45463isopencode serve --service, a direct child of theopencodeTUI (45462).Change
agentsOwnServiceaccepts the listener, with no session history needed, when all of the following hold:selfTraffic)PPID == client.PID;peerproc.Procalready carries it)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
IsAgentProcesscheck, 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:python-requests) calling its ownpythonchild: recordedEach condition was checked by removing it from the code and confirming that at least one test then fails.
GOWORK=off go test ./...incorepasses;gofmt -landgo vetare clean.docs/laptop-service.mdis 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