Skip to content

📡 live session presence: providers push status + context tokens to /sessions - #192

Open
sdougbrown wants to merge 2 commits into
mainfrom
session-presence
Open

📡 live session presence: providers push status + context tokens to /sessions#192
sdougbrown wants to merge 2 commits into
mainfrom
session-presence

Conversation

@sdougbrown

Copy link
Copy Markdown
Owner

Adds live session presence so avenor_peers and /sessions show status, context usage, and token counts per run.

Why: peer discovery today shows only static metadata (backend/model/dir). A coordinator deciding whether to ask a peer — or a reviewer gauging a sibling's capacity — has no signal about liveness, current status, or how full the context window is.

What changed:

  • SessionInfo gains context_pct / context_tokens / context_window (broker.go); /sessions copies them through, UpdateSessionInfo overwrites cleanly.
  • ACP provider pushes initial starting presence on Start, flips thinking/idle across each Prompt boundary, reads total_tokens from the prompt response usage block, and keeps a 5s ticker (sharing the poll context) that refreshes LastSeen/status between turns.
  • Pi provider wires the broker ref via merged StartOptions (fully localized), pushes status/last-seen plus a 5s ticker; Pi exposes no token data, so context fields are omitted.
  • avenor_peers renders N% context (M tokens) per session where reported.

Tests: TestBrokerSessionInfoContextFields, TestPresencePushContextTokens, TestProviderPresencePush. Full go build ./... and go test ./... pass.

No change to ask/reply transport or control RPCs — presence only.

@umpire-bot umpire-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR is marked... FOUL BALL. 👉

// presencePush writes the current presence state to the broker under the
// provider's run ID. It sends a complete SessionInfo so the broker's overwrite
// semantics cleanly reflect the latest values.
func (p *Provider) presencePush() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

presencePush omits ContextTokens, ContextPct, and ContextWindow, which the PR title ("push status + context tokens to /sessions") and the acp provider both include (acp/provider.go:504). If the pi backend exposes usage data, these should be pushed for parity. Note the pi translator (translateAgentEnd, events.go:52) does not extract usage from the backend payload — unlike the acp translator — which suggests the pi backend may not provide it. If so, this is an intentional difference worth a brief comment; if not, add the fields.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

👾 AI Agent

👾 AI Agent

Good catch — this was an intentional difference but undocumented. The pi backend exposes no model-context usage data (translateAgentEnd in internal/runtime/pi/events.go extracts nothing from the backend payload), so there is nothing to push for context_pct/context_tokens/context_window. Added a comment on presencePush explaining that, and noting ACP pushes them because its response payloads carry token counts. Commit a4ed11d. Resolved.

The pi backend exposes no model-context usage data, so presencePush
intentionally omits context_pct/context_tokens/context_window. The ACP
provider pushes them because its response payloads carry token counts.
@sdougbrown

Copy link
Copy Markdown
Owner Author

👾 AI Agent

Addressed 1 comment across 1 file:

  • Fixed (1): internal/runtime/pi/provider.go:449 — documented why the pi presencePush intentionally omits context fields (the pi backend exposes no usage data; ACP pushes them because its payloads carry token counts). Commit a4ed11d.

Review loop: 1 iteration — comment-only fix, no code change, so no regression surface (full go build + pi provider tests green).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant