From e97d41858c67ca7b019493be2b436e32b8069118 Mon Sep 17 00:00:00 2001 From: Omni Worker Date: Sat, 22 Nov 2025 05:25:57 -0500 Subject: 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 --- Omni/Agent/Worker.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Omni') 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 () -- cgit v1.2.3