Commit Graph
4 Commits
Author SHA1 Message Date
yetone 4c801e5756 devin 0.1.34: keepalive pings timed from when the request was sent; magpie's session header keys them (#626, #620)
#626 (zelong77): keptAfter scheduled the first ping 285 s after the
reply's stop event, and run() scheduled each next one 285 s after the
ping before had come back. Devin renews its cache when it takes a
request, so a 33-47 s Fable reply or a 10-20 s ping put the next ping
past the 5 minutes. In zelong77's usage.jsonl every ping 315.9 s or more
after its request was sent missed and wrote ~500k tokens again.

- roundtrip stamps sentAt before it sends; scheduleKeepalive waits
  max(0, interval - (now - sentAt)), and each ping is timed from when it
  was sent. A reply or ping longer than the interval is followed at once.
- The timers object carries the clock (now), so tests hold it.

#620, after 0.1.33 (zelong77, 08:18): through magpie, check A and the
grown check B still kept separate pings. magpie hands a plugin's fetch
none of the agent's own headers, so x-claude-code-session-id never
reached keepaliveKey, and magpie's translation merges Claude Code's two
user messages into one whose history grows in the middle, which firstOf
can't follow.

- keepaliveKey reads x-magpie-session first and x-magpie-subagent beside
  x-claude-code-agent-id. magpie sets both on a plugin's fetch in a
  release that follows this one; the host strips them from what a plugin
  sends on.
- README: the timing, and the headers.

Run on mote (Bun 1.4.2, HOME=$(mktemp -d)) at this tree, on main 63cd0e4:
- packages/devin `bun test`: 189 pass, 0 fail.
- The 3 new keepalive tests on main's index.mjs: 3 fail (22 pass). The
  two timing tests got 285000 where 238200 and 0 were due; the merged
  check A's timer was never cleared.
- Whole repo `bun test`: 4781 pass, 0 fail. `bun scripts/check.mjs
  devin`: ok.

Not tried: a real Devin account or a real Claude Code session; fake
timers and a fake Devin only. Without any session header (not Claude
Code's case once magpie sends x-magpie-session), a merged check whose
history grows in the middle still gets a new key: matching on a shared
leading block would merge different conversations that start with the
same reminder, which costs a full rewrite rather than an extra read.
2026-11-02 16:54:17 +08:00
yetone 581ca13db6 devin 0.1.33: a permission check whose history grew replaces its keepalive pings (#620)
zelong77 found that Claude Code Auto's permission check left several
keepalive tasks running for one check. keepaliveKey hashed the first user
message, and the check sends the whole history in that message, so every
check got a new key. stopKeepalive(newKey) never stopped the old task,
and each reply started another one.

- The key is now the session, the Claude Code agent id and a hash of the
  instructions and the tools' names. The first user message is left out
  when the agent names a session. The lead, its permission check and a
  subagent still get keys of their own, because their instructions,
  tools or agent id differ.
- When a request names no session, the first message still tells two
  conversations apart. A first message that grew from one seen before
  (blocks appended, or text added to the last block) maps to the earlier
  key (firstOf). firstOf keeps only hashes, of 256 conversations at most.
- README: what a conversation is.

Run on mote (Bun 1.4.2, HOME=$(mktemp -d)) at this tree, on main 2595d48:
- packages/devin `bun test`: 186 pass, 0 fail.
- The new keepalive tests on main's index.mjs: 4 fail (18 pass, 4 fail).
  These are zelong77's repro, with and without session headers, plus a
  grown last text and the stay-apart case.
- Whole repo `bun test`: 4741 pass, 12 skip, 0 fail.
  `bun scripts/check.mjs`: exit 0.

Not tried: a real Devin account, or a real Claude Code Auto session. The
tests use zelong77's offline requests with fake timers and no network.
A request with no session whose first message starts with another
conversation's whole first message is taken as that conversation.
2026-11-02 14:44:55 +08:00
yetone 1a3a138491 devin 0.1.31: each cache keep-alive ping is told to magpie; the interval and count get magpie's Options editor (#592)
zelong77 asked for two things once 0.1.30's keep-alive worked: the pings
were invisible in magpie, and the interval and ping count could only be
edited in plugins.json.

- Each ping that wasn't cut short is reported through magpie.usage (new
  in magpie, plugins#592) with kind cache_keepalive, the conversation's
  model (chat.model) and account (magpie.account at request time), its
  input, output, cache read and write tokens, status, time, and why it
  failed. The ping still goes straight to Devin, never back through the
  gateway: the gateway re-shapes a request, and the cache would no
  longer match. An older magpie or OpenCode has no magpie.usage and is
  told nothing; the pings go on the same.
- pingOnce now also reads output tokens (usage field 3) and keeps the
  failure's message.
- package.json magpie.options gives the two settings' defaults
  (285 s, 6), which magpie's Plugins › Options editor now starts from
  for a provider plugin. The switch's description says where they are
  and that pings show in Usage, in all five languages, each under the
  host's 300-character cap.

Run (on mote, sandbox HOME): bun test in packages/devin, 174 pass;
bun scripts/check.mjs devin ok.
Broken by hand: reporting aborted pings too fails "a ping cut short by
the conversation's next request isn't told"; dropping the report call
fails "each ping is told to magpie".
Not tried: a real Devin account's ping reported into a real magpie.
2026-11-01 17:59:33 +08:00
yetone b797476f6b devin 0.1.30: an opt-in cache keepalive, as the devin CLI's (#592)
Devin's prompt cache lasts 5 minutes and has no longer TTL to ask for.
A switch, "Keep the cache warm" (cache_keepalive, off by default, with
zh, zh-TW, ja and de labels), keeps it as the CLI's cache_keepalive.rs
does: after a reply that read or wrote the cache, whatever it stopped
for, the same GetChatMessage goes again every 285 s with one more user
prompt, "continue", and max_tokens 1. The request's bytes are encoded
once, and the ping is them with that prompt and field 8's max_tokens.

- A conversation is session + Claude Code agent id (when the headers
  reach the plugin) + a hash of the instructions, tool names and first
  user message; its next real request stops its pings, so a subagent
  never stops its lead's.
- Stops on 401, 402, 429, two pings in a row reading under half their
  prompt from the cache, the most pings (6), the switch going off, and
  process exit. Timers are unref'd. At most 32 conversations are kept.
- Options cacheKeepaliveInterval (30-299 s) and cacheKeepaliveMaxPings
  (1-50); OpenCode, which has no switch, takes cacheKeepalive: true.
- README says the cost (each ping is a cache read of the whole context,
  spent whether the user comes back or not) and why it is off.

Run (mote, HOME=$(mktemp -d)):
- bun test packages/devin: 170 pass, 0 fail (14 new in keepalive.test.mjs).
- Whole repo bun test: 4520 pass, 9 skip, 1 fail: gcp-ai's "a lock held
  by another process is waited for, then taken" (ENOENT in abandoned()'s
  stat, a race in lib/lock.mjs; passes 3 of 3 alone), filed as #594.
- bun scripts/check.mjs: ok.
- The new tests against the old index.mjs: 14 of 14 fail.

Broken by hand, each red in the test named for it: no cancel on the next
request, no agent id in the key, no prefix hash, no stop on 401/402/429,
no miss count, no cap, no unref, max_tokens kept, pings after a reply
that touched no cache.

Real account (the owner's Devin sign-in read, nothing written, sandbox
HOME, this Mac): claude-sonnet-5-5-low, an 11k-token prompt wrote 10,984
to the cache; one ping 287 s later read 10,984 from it (cacheWrite 3,
output 1) and, at max 1, stopped.

Not tried: more than one ping or a long Claude Code session; the OpenCode
2 (v2) path, which has no keepalive. magpie doesn't pass
x-claude-code-session-id / x-claude-code-agent-id to a plugin's fetch, so
under magpie the key rests on the prefix hash (a lead and a subagent
differ there; two sessions with the same prefix share one keepalive).
2026-11-01 14:12:06 +08:00