`project: unknown` heartbeats split real editor events, so durations collapse to zero

Open Beginner friendly
#57 5 comments 0 reactions 0 assignees View on GitHub

@BeatLink is already working on this.

Since Oct 21, 2026.

  • #56 by @BeatLink — open
  • #58 by @TimeToBuildBob — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
69/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript, vscode

Research direction

Read src/extension.ts around _onEvent and _createHeartbeat, then check the event tests or smoke test steps referenced by #55. Confirm that a missing active text editor does not send an unknown heartbeat and that normal editor heartbeats still work; the packaged build smoke test is still needed for completion.

Written by the indexing model from the issue text.

Description

project: unknown heartbeats split real editor events, so durations collapse to zero

On a machine where most editing happens with an agent panel open in the editor
area, this watcher records 0.16 h against the window watcher's 44.78 h of
focused VS Code time over 30 days — 0.4%
. 187 of its 218 stored events have
duration: 0.0.

I think this is the root cause of #10, and it is distinct from the feature
request in #43. #43 asks for terminal and sidebar time to be tracked. This is
narrower and worse: focus leaving the text editor destroys the measurement of
the editor time the watcher is already observing.

Mechanism

_onEvent fires on onDidChangeTextEditorSelection and
onDidChangeActiveTextEditor. When the focused tab is not a document — a
webview tab, the Settings UI, an agent chat panel — window.activeTextEditor
is undefined, onDidChangeActiveTextEditor still fires, and
_createHeartbeat sends {file: 'unknown', project: 'unknown', language: 'unknown'} (plus branch: 'unknown', since the git-branch support added for #41).

aw-server extends the open event only while the incoming heartbeat's data
is identical. So a single unknown between two heartbeats for the same file
ends that event and opens a new one — both at duration 0.

Probed directly against aw-server-rust v0.14.0, pulsetime=20, heartbeats 5 s
apart:

# three identical heartbeats
00:00:00 a.ts | 00:00:05 a.ts | 00:00:10 a.ts
  -> 1 stored event,  duration 10.0

# identical, with one `unknown` interleaved
00:00:00 b.ts | 00:00:05 unknown | 00:00:10 b.ts
  -> 3 stored events, duration 0.0, 0.0, 0.0

In the real bucket the pair arrives 21 ms apart, because switching tabs emits
undefined before the new editor:

16:40:18.837  dur 0.0  unknown
16:40:18.850  dur 0.0  /temp/readonly/Bash tool output (6jjs8r)
16:40:32.404  dur 0.0  unknown
16:40:32.425  dur 0.0  .../docs/hour-app-plan.md

84 of 218 events are that unknown. Note this is not the sidebar case
@TimeToBuildBob tested in #43: a sidebar leaves activeTextEditor intact, so
it emits nothing. A webview tab in the editor group clears it, so it emits
unknown.

Fix

Return early instead of reporting unknown. Letting the event lapse costs
nothing — pulsetime closes it anyway — whereas unknown actively ends it.
Against master, and it does not touch anything #52 moves:

--- a/src/extension.ts
+++ b/src/extension.ts
@@ -103,6 +103,18 @@
             return;
         }
 
+        // Nothing is reportable when no document has the focus: a webview tab,
+        // the Settings UI, a diff of a deleted file or an agent chat panel all
+        // leave `activeTextEditor` undefined. Returning here rather than
+        // sending `unknown` is not cosmetic. aw-server extends the open event
+        // only while the incoming heartbeat's `data` is identical, so one
+        // `unknown` between two heartbeats for the same file ends that event
+        // and opens another — both at duration 0. Letting the event lapse on
+        // its own costs nothing by comparison: pulsetime closes it anyway.
+        if (!window.activeTextEditor) {
+            return;
+        }
+
         // Create and send heartbeat
         try {
             const heartbeat = this._createHeartbeat();

I have not run a packaged build of this, so it wants the same smoke test #55
lists as an open sub-task; the reasoning above is what I verified, by probing
the server directly.

What this does not fix

Coverage. There is still no heartbeat while reading without moving the
cursor, which is the other half of #10. A periodic heartbeat gated on
window.state.focused && window.activeTextEditor would close it, and I think
it answers @johan-bjareholt's objection in #10 about overshooting: that is the
same condition the window watcher bills on, not a guess about attention. Happy
to open that separately if there's appetite — it is a policy change, where the
above is just a bug.

Environment

VS Code 1.129.1, extension 0.5.0 (the Marketplace build; the code path is
unchanged on master), aw-server-rust v0.14.0, macOS 26.5.2.

Dominant language
TypeScript
Stars
285
Forks
50
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ActivityWatch/aw-watcher-vscode

All issues in ActivityWatch/aw-watcher-vscode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.