File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,19 +197,26 @@ func parseCodebuffSession(
197197 // empty. Cost is tracked at the session level via credits.
198198 if rs .CreditsUsed > 0 {
199199 cost := rs .CreditsUsed * 0.01
200+ // Determine occurred_at: prefer message timestamps, then fall
201+ // back to the session directory timestamp, then source mtime.
202+ occurredAt := startedAt
203+ if ! endedAt .IsZero () {
204+ occurredAt = endedAt
205+ }
206+ if occurredAt .IsZero () && ! sessionDate .IsZero () {
207+ occurredAt = sessionDate
208+ }
209+ if occurredAt .IsZero () && fileInfo .Mtime > 0 {
210+ occurredAt = time .Unix (0 , fileInfo .Mtime )
211+ }
200212 sess .UsageEvents = []ParsedUsageEvent {{
201- SessionID : fullID ,
202- Source : "session" ,
203- OccurredAt : func () string {
204- if ! endedAt .IsZero () {
205- return endedAt .Format (time .RFC3339Nano )
206- }
207- return startedAt .Format (time .RFC3339Nano )
208- }(),
209- CostUSD : & cost ,
210- CostStatus : "reported" ,
211- CostSource : "session" ,
212- DedupKey : "session:" + fullID ,
213+ SessionID : fullID ,
214+ Source : "session" ,
215+ OccurredAt : occurredAt .Format (time .RFC3339Nano ),
216+ CostUSD : & cost ,
217+ CostStatus : "reported" ,
218+ CostSource : "session" ,
219+ DedupKey : "session:" + fullID ,
213220 }}
214221 }
215222
Original file line number Diff line number Diff line change @@ -12156,6 +12156,26 @@ func (e *Engine) SourceMtime(sessionID string) int64 {
1215612156 _ , mtime := roocodeEffectiveStat (path , info )
1215712157 return mtime
1215812158 }
12159+ if def .Type == parser .AgentCodebuff {
12160+ // Freshness spans chat-messages.json plus run-state.json and
12161+ // chat-meta.json. Compute the composite max mtime across all
12162+ // three files so companion-file-only changes are caught.
12163+ info , err := os .Stat (path )
12164+ if err != nil {
12165+ return 0
12166+ }
12167+ mtime := info .ModTime ().UnixNano ()
12168+ dir := filepath .Dir (path )
12169+ for _ , name := range []string {"run-state.json" , "chat-meta.json" } {
12170+ companion := filepath .Join (dir , name )
12171+ if ci , err := os .Stat (companion ); err == nil {
12172+ if cm := ci .ModTime ().UnixNano (); cm > mtime {
12173+ mtime = cm
12174+ }
12175+ }
12176+ }
12177+ return mtime
12178+ }
1215912179 if def .Type == parser .AgentKiloLegacy {
1216012180 // Freshness spans task_metadata.json (the stored path) plus
1216112181 // its siblings ui_messages.json and api_conversation_history.json.
You can’t perform that action at this time.
0 commit comments