Skip to content

Commit 87e2771

Browse files
sepo-engFelicity
andauthored
refactor(observability): baseline counters on paths the redesign replaces (#6)
Additive, no behavior change. Instruments the four paths named in TKT-309 so later adapter-removal decisions are measured: - V1 session archive route calls (the setArchivedThroughLifecycle compatibility adapter from #4) - session event subscribe: fresh vs cursor-resumed (a reconnect asking to replay after a sequence), on the v2.session.events handler - compaction runs, next to the existing Compaction.Started publish - the browser-only opencode:session-tabs-removed dispatch (the tab cleanup path the authoritative-session-entities slice replaces) All four are plain in-memory counts (packages/core/src/observability/ baseline-counters.ts) surfaced through the existing structured log stream via Effect.logInfo, or console.debug for the one browser-side path — never read back into request handling. No new endpoint: "logs" is the chosen half of the ticket's "logs or a debug endpoint". Co-authored-by: Felicity <[email protected]>
1 parent 212fdbe commit 87e2771

5 files changed

Lines changed: 65 additions & 5 deletions

File tree

‎packages/app/src/components/titlebar-session-events.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ export type SessionTabsRemovedDetail = {
88
sessionIDs: string[]
99
}
1010

11+
// TKT-309 baseline: this custom event is the browser-only half of the current archive
12+
// path (see home-session-archive.ts) that the authoritative-session-entities slice
13+
// replaces with a server-driven store. Counting its use here, before that change, is
14+
// the measurement the removal decision hangs on. Additive only — the dispatch below is
15+
// unchanged.
16+
let sessionTabsRemovedNotifications = 0
17+
1118
export function notifySessionTabsRemoved(input: SessionTabsRemovedDetail) {
19+
sessionTabsRemovedNotifications++
20+
console.debug("[baseline] session-tabs-removed dispatch", {
21+
total: sessionTabsRemovedNotifications,
22+
sessionCount: input.sessionIDs.length,
23+
})
1224
window.dispatchEvent(new CustomEvent(SESSION_TABS_REMOVED_EVENT, { detail: input }))
1325
}
1426

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* TKT-309: lightweight, additive counters on the paths the reliability redesign will
3+
* replace, so later adapter-removal decisions ("is anyone still hitting the V1 route?")
4+
* are measured against real numbers instead of guessed. No behavior change — these are
5+
* plain in-memory counts, surfaced through the existing structured log stream via
6+
* Effect.logInfo at each call site, never read back into request handling.
7+
*/
8+
9+
let v1SessionArchiveCalls = 0
10+
let sessionEventFreshSubscribes = 0
11+
let sessionEventReplays = 0
12+
let compactionRuns = 0
13+
14+
export const BaselineCounters = {
15+
v1SessionArchive: () => ++v1SessionArchiveCalls,
16+
/** hasCursor: the client passed `after`, i.e. this is a reconnect/replay, not a fresh subscribe. */
17+
sessionEventSubscribe: (hasCursor: boolean) =>
18+
hasCursor ? ++sessionEventReplays : ++sessionEventFreshSubscribes,
19+
compactionRun: () => ++compactionRuns,
20+
snapshot: () => ({
21+
v1SessionArchiveCalls,
22+
sessionEventFreshSubscribes,
23+
sessionEventReplays,
24+
compactionRuns,
25+
}),
26+
}

‎packages/core/src/session/compaction.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SessionEvent } from "./event"
88
import { SessionMessage } from "./message"
99
import { SessionSchema } from "./schema"
1010
import { Token } from "../util/token"
11+
import { BaselineCounters } from "../observability/baseline-counters"
1112

1213
const DEFAULT_BUFFER = 20_000
1314
const DEFAULT_KEEP_TOKENS = 8_000
@@ -189,6 +190,12 @@ export const make = (dependencies: Dependencies) => {
189190
timestamp: yield* DateTime.now,
190191
reason: "auto",
191192
})
193+
// TKT-309 baseline: how often compaction actually runs (past the size checks above),
194+
// ahead of the durable-goal/ledger slice that changes what survives it.
195+
yield* Effect.logInfo("baseline: compaction run", {
196+
sessionID: input.sessionID,
197+
total: BaselineCounters.compactionRun(),
198+
})
192199

193200
const chunks: string[] = []
194201
let failed = false

‎packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Agent } from "@/agent/agent"
33
import { SessionV1 } from "@opencode-ai/core/v1/session"
44
import { SessionV2 } from "@opencode-ai/core/session"
55
import { SessionLifecycle } from "@opencode-ai/core/session/lifecycle"
6+
import { BaselineCounters } from "@opencode-ai/core/observability/baseline-counters"
67
import { EventV2Bridge } from "@/event-v2-bridge"
78
import { Command } from "@/command"
89
import { Permission } from "@/permission"
@@ -104,6 +105,12 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "session",
104105
sessionID: SessionID,
105106
archived: number,
106107
) {
108+
// TKT-309 baseline: how much is still calling the V1 archive route, so removing the
109+
// adapter later is a measured decision rather than a guess.
110+
yield* Effect.logInfo("baseline: v1 session archive call", {
111+
sessionID,
112+
total: BaselineCounters.v1SessionArchive(),
113+
})
107114
const id = SessionV2.ID.make(sessionID)
108115
const current = yield* sessionV2.get(id).pipe(Effect.orDie)
109116
// Only an active session is archivable. A session already archived keeps the instant it was

‎packages/server/src/handlers/session.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "@opencode-ai/protocol/errors"
1717
import { AbsolutePath } from "@opencode-ai/core/schema"
1818
import { SessionLifecycle } from "@opencode-ai/core/session/lifecycle"
19+
import { BaselineCounters } from "@opencode-ai/core/observability/baseline-counters"
1920

2021
const DefaultSessionsLimit = 50
2122
const DefaultSessionHistoryLimit = 50
@@ -458,11 +459,18 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
458459
)
459460
.handle(
460461
"session.events",
461-
Effect.fn((ctx) =>
462-
Effect.succeed(
463-
session.events({ sessionID: ctx.params.sessionID, after: ctx.query.after }).pipe(Stream.orDie),
464-
),
465-
),
462+
// TKT-309 baseline: split fresh subscribes from cursor-resumed ones (a reconnect
463+
// asking to replay after a sequence) so client reconnect behavior is measured
464+
// before the tab-reconciliation slice changes how it's driven.
465+
Effect.fn(function* (ctx) {
466+
const hasCursor = ctx.query.after !== undefined
467+
yield* Effect.logInfo("baseline: session event subscribe", {
468+
sessionID: ctx.params.sessionID,
469+
hasCursor,
470+
total: BaselineCounters.sessionEventSubscribe(hasCursor),
471+
})
472+
return session.events({ sessionID: ctx.params.sessionID, after: ctx.query.after }).pipe(Stream.orDie)
473+
}),
466474
)
467475
.handle(
468476
"session.interrupt",

0 commit comments

Comments
 (0)