sessionapi: guard Session messages against concurrent reads, drop GIT_CONFIG block from generate-proto #23
This PR carries the four commits of #19 plus four fix commits, so I am treating it as the replacement for #19. CI is green on this head. Checked each fix against its diff:
dbdc264: the GIT_CONFIG_* block is gone from dev/tasks/generate-proto. Good.956922c: Session.messages is guarded by an RWMutex in Messages() and AddMessages, the two direct reads in LoadSession now go through Messages(), and the field carries the "diverges from upstream, see #14" marker. Good.7366927: TestConcurrentReadDuringTurn runs ListMessages, ListSessions, and GetSession in loops while a turn is blocked in the sandbox and while it finishes. Good. Note that ap test does not run with -race (.ap/go.yaml has only gofmt and govet), so this test proves the behaviour, not the absence of the race; if ap has no knob for -race, a one-line note on #14 or gke-labs-infra is enough.309744a: AO_LISTEN, --json on ao session get, docs for both and for the system prompt event, and an e2e check for --json. Good.One requested change remains, from the maintainer's comment on #19: the three _ = closeErr sites in cmd/ao/client.go (lines 54, 102, 162 here) are unchanged. Assigning an error and discarding it with _ is ignoring it with extra lines. Please log it at a verbose level, ideally through one small helper:
defer func() {
if err := conn.Close(); err != nil {
scoped.Log(cmd.Context()).V(4).Info("closing gRPC connection", "error", err)
}
}()
(scoped.Log lands with #26; if this merges first, klog.FromContext and a follow-up swap are fine.)
Also, the four fix commits say Issue #20. #20 was closed as superseded by the review on #19, so reference Part of #17 instead, and keep Fixes #17 on the final commit.
I will approve once the close-error fix is pushed.
#26 (pkg/scoped) and #27 (commit message rules) are on main now, and this branch still merges cleanly. When you push the close-error fix, use scoped.Log(ctx).V(4).Info(...) directly rather than klog.FromContext, and please rebase onto main so CI runs against the merged pkg/scoped. Per the updated AGENTS.md, either amend the touched commit or add a fixup! commit and leave it in place; do not squash.
Please rebase for easier code review
Approving. Head 7251e28 is rebased onto current main (merge-base equals main), CI is green on it, and the e2e log shows TestSessionAPI passing on kind alongside TestSession and TestSmoke.
Checked against the earlier review:
closeConnection logs at V(4) through scoped.Log, and ao serve uses scoped.Log too.Session.messages is guarded by an RWMutex with the divergence marker, and TestConcurrentReadDuringTurn is present.dev/tasks/generate-proto has no GIT_CONFIG_* block.Part of #17 with Fixes #17 on the last commit, and the last commit's body matches its diff.This PR introduces the Session gRPC API, ao serve, and the ao session list|get|send CLI from #17; #19 was closed in its favour. Remaining notes are tracked elsewhere: -race in ap test and the lint knob for printf-style klog (gke-labs-infra), and the fork divergences (#14).
justinsb
codebot-robot
This PR addresses the follow-up items from issue #20 on the Session API and tooling:
1. Guard
Session.messagesagainst concurrent reads:- Added
messagesMu sync.RWMutextopkg/session.Session, protectingmessagesinAddMessagesandMessages().- Used
session.Messages()inEnsureSystemPromptandRunTurn.- Added divergence tracking comment referencing issue #14, and updated issue #14 with item 8.
- Added
TestConcurrentReadDuringTurntopkg/sessionapi/server_test.gousingblockingSandboxto verify concurrentListMessages,ListSessions, andGetSessionreads during an in-flight and completing turn without data races undergo test -race.- Note on
.ap/go.yaml: Checkedgke-labs-infra'sap testimplementation and.ap/go.yamlschema; there is currently no configuration knob for enabling-raceinap test(it runsgo test -json ./...). This can be filed ongke-labs-infra.2. Drop
GIT_CONFIGblock fromdev/tasks/generate-proto:- Removed the
unset GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEMblock sogrep -rn GIT_CONFIG dev/returns nothing.3. CLI and Documentation follow-ups:
- Updated
ao servedefault listen env var fromLISTENtoAO_LISTENto align withAO_SERVER.- Added
--jsonflag toao session getfor machine-readable JSON output, and verified it in e2e tests.- Documented
AO_LISTEN,ao session get --json, and noted that the firstSendMessageon a session streams the system prompt to the client indocs/sessions.md.Fixes #20