summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
authorOmni Worker <bot@omni.agent>2025-11-22 05:25:57 -0500
committerOmni Worker <bot@omni.agent>2025-11-22 05:25:57 -0500
commite97d41858c67ca7b019493be2b436e32b8069118 (patch)
tree4f021c4faa0f60428bfa3ad563c28ab64a491cec /Omni
parentcf32eb4ea6e2f8594fea7895fee38c9c2a838042 (diff)
fix: read amp log from start and use totalCredits for accuracy
Amp-Thread-ID: https://ampcode.com/threads/T-5a2ca80d-5cba-409f-a262-6b5c652c257d Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni')
-rw-r--r--Omni/Agent/Worker.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 4ff9042..7afc849 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -227,8 +227,7 @@ monitorLog :: FilePath -> IO ()
monitorLog logPath = do
waitForFile logPath
IO.withFile logPath IO.ReadMode <| \h -> do
- -- Tail the file
- IO.hSeek h IO.SeekFromEnd 0
+ -- Start from beginning of file (don't seek to end)
forever <| do
eof <- IO.hIsEOF h
if eof
@@ -263,11 +262,12 @@ parseAndUpdate line = do
_ -> pure ()
-- Extract cost from usage-ledger:event
- -- Pattern: {"addedCredits": 0.123, "message": "usage-ledger:event", ...}
- case KM.lookup "addedCredits" obj of
+ -- Pattern: {"totalCredits": 1.54, "message": "usage-ledger:event", ...}
+ -- We use totalCredits to be robust against missed lines and restarts.
+ case KM.lookup "totalCredits" obj of
Just (Aeson.Number n) ->
- let cost = Scientific.toRealFloat n
- in AgentLog.update (\s -> s {AgentLog.statusCredits = AgentLog.statusCredits s + cost})
+ let total = Scientific.toRealFloat n
+ in AgentLog.update (\s -> s {AgentLog.statusCredits = total})
_ -> pure ()
timeTicker :: IO ()