Skip to content

feat: add byte tracking to ssh and pty connections - #30389

Merged
code-asher merged 5 commits into
mainfrom
asher/connection-log-bytes
Oct 16, 2026
Merged

code-asher merged 5 commits into
mainfrom
asher/connection-log-bytes

Conversation

@code-asher

@code-asher code-asher commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Part of https://linear.app/codercom/issue/CLIENT-671/agent-additional-connection-log-debug-logging

For now, the bytes are recorded but not currently exposed on the API.

@linear-code

linear-code Bot commented Oct 6, 2026

Copy link
Copy Markdown

CLIENT-671

@code-asher
code-asher force-pushed the asher/connection-log-bytes branch 14 times, most recently from bb60325 to 1773a6b Compare October 6, 2026 10:08
@code-asher
code-asher marked this pull request as ready for review October 6, 2026 10:21
@code-asher
code-asher force-pushed the asher/connection-log-bytes branch 4 times, most recently from 8dd0b88 to 83fbb53 Compare October 13, 2026 02:29
@code-asher
code-asher requested review from EhabY and a balanced review from Copilot and removed request for Copilot October 13, 2026 02:40

@EhabY EhabY left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments on byte-count reporting and two small copy/paste mistakes. The shared-tracker suggestion and older-agent compatibility question are non-blocking!

Also pls rebase 🙏

Reason: "server shut down",
RxBytes: conn.RxBytes(),
TxBytes: conn.TxBytes(),
})

@EhabY EhabY Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we wait for the connection's I/O to finish before reporting the final counts? This shutdown path reads the counters before closing the connection, so a read or write that's still running can add bytes afterward. The handler sends another disconnect report, but if the first one has already been flushed, the SQL upsert keeps its earlier counts. Reporting once after I/O finishes would avoid that timing-dependent undercount.

@code-asher code-asher Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, this disconnect report here actually needs some fixing I think because once we hit the hard context, I think the agent is not going to be able to send a report anyway (trying to make rpc calls at this point fails with "context canceled" from what I saw when trying to test this a while back).

Even if that was not the case, since this is a hard cancellation I think it is no longer correct to wait for anything, we have to wrap up immediately what we can and exit.

In practice, the conn should have already been closed with the graceful shutdown and hit the other disconnection report, which I think should always have the correct counts since it runs after the connection closes.

Comment thread agent/agent_test.go Resolved
Comment thread coderd/database/dbgen/dbgen.go Resolved
Comment thread agent/agentssh/agentssh.go Resolved
Comment thread coderd/agentapi/connectionlog.go Resolved
@code-asher
code-asher force-pushed the asher/connection-log-bytes branch 4 times, most recently from ff2fa44 to 7a4d168 Compare October 15, 2026 04:55
@code-asher
code-asher requested a review from EhabY October 15, 2026 05:14

@EhabY EhabY left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Also combine zero and null tests.  They do pretty much the exact same
thing, just set a value then check that `Valid` is still the same thing.
@code-asher
code-asher force-pushed the asher/connection-log-bytes branch from 7a4d168 to 24ae697 Compare October 16, 2026 07:27
@code-asher
code-asher requested a review from mafredri as a code owner October 16, 2026 07:27
@code-asher
code-asher merged commit 899d25a into main Oct 16, 2026
28 of 29 checks passed
@code-asher
code-asher deleted the asher/connection-log-bytes branch October 16, 2026 08:21
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants