mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
test(recovery): pin the daily-limit fallback test to the current UTC day (#21236)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The fresh-continuation fallback continues interrupted tasks. Its
tests run on every pull request.
> - One test checks that the agent's daily run limit keeps a
continuation pending.
> - The test failed on unrelated pull requests just after 00:00 UTC. It
passed the rest of the day.
> - The daily run limit counts runs started in the current UTC day. The
test's source run started 11 minutes before now, so just after midnight
it counted as yesterday's run.
> - This pull request pins the test's runs to the current UTC day.
> - The benefit is that the test gives the same result at every hour,
and CI and the release source check do not fail after midnight UTC.
## Linked Issues or Issue Description
**What happened?**
`server/src/services/fresh-continuation-fallback.test.ts > keeps the
continuation pending while the agent's daily run limit declines it, then
delivers it` failed in "General tests (server (11/12))" on two unrelated
pull requests at about 00:10 UTC, with `expected [ { …(81) } ] to have a
length of +0 but got 1`.
**Expected behavior**
The test passes at every hour of the day.
**Steps to reproduce**
1. Run the test between 00:00 and 00:11 UTC (or move the source run's
`startedAt` to before today's UTC midnight, which is the same state).
2. See that the daily limit does not decline the continuation, and a
successor run is created.
The product code is correct: `dailyRunConditions` in
`server/src/services/heartbeat/timer-policy.ts` counts runs whose
`startedAt` is in the current UTC day. Only the test depended on the
clock.
## What Changed
- The test now sets the source run's `startedAt` to one minute before
today's UTC midnight, and adds a succeeded run started now on another
task. That run uses the agent's single daily run.
- Test file only. No product change.
## Verification
- RED: with only the source run moved before today's UTC midnight (the
state from 00:00 to 00:11 UTC), the test fails with the same message as
CI: `expected [ { …(81) } ] to have a length of +0 but got 1`.
- GREEN: with the run started today added, the test passes.
- `cd server && npx vitest run
src/services/fresh-continuation-fallback.test.ts`: 53 passed (on current
master).
## Risks
- Low risk. Test file only.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Claude Code agent with tool use
(shell, file edit, test runs).
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes (no
behavior change)
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1cf43e666
commit
ddc0aacad8
1 file changed
+17
-3
@@ -318,10 +318,23 @@ suite("fresh-continuation fallback", () => {
|
||||
// A gate after the hook must never consume the recovery: it stays pending
|
||||
// and is delivered once the gate clears.
|
||||
it("keeps the continuation pending while the agent's daily run limit declines it, then delivers it", async () => {
|
||||
const f = await unfinishedRun({ runtime: "native", errorCode: "native_session_interrupted", hold: "settled_blocked" });
|
||||
await db.update(agents).set({ runtimeConfig: { heartbeat: { maxConcurrentRuns: 1, maxDailyRuns: 1 } } }).where(eq(agents.id, agentId));
|
||||
// The daily limit counts runs started in the current UTC day, and it reads
|
||||
// the clock on every check. Freeze Date (timers stay real) so every check in
|
||||
// this test sees the same day, even when UTC midnight passes mid-test.
|
||||
const now = new Date();
|
||||
vi.useFakeTimers({ toFake: ["Date"], now });
|
||||
try {
|
||||
// The source run already used today's single run.
|
||||
const f = await unfinishedRun({ runtime: "native", errorCode: "native_session_interrupted", hold: "settled_blocked" });
|
||||
await db.update(agents).set({ runtimeConfig: { heartbeat: { maxConcurrentRuns: 1, maxDailyRuns: 1 } } }).where(eq(agents.id, agentId));
|
||||
// Pin the runs to that day so the result does not depend on the hour:
|
||||
// the source run started yesterday (as it does just after 00:00 UTC), and
|
||||
// another run started today used the single run.
|
||||
const todayStart = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
||||
await db.update(heartbeatRuns).set({ startedAt: new Date(todayStart - 60_000), createdAt: new Date(todayStart - 120_000) })
|
||||
.where(eq(heartbeatRuns.id, f.runId));
|
||||
const [other] = await db.insert(issues).values({ companyId, title: "Used today's run", status: "done", assigneeAgentId: agentId }).returning();
|
||||
await db.insert(heartbeatRuns).values({ companyId, agentId, issueId: other!.id, status: "succeeded",
|
||||
startedAt: now, finishedAt: now, contextSnapshot: { issueId: other!.id } });
|
||||
expect(await sweepWake(f.issueId)).toBeNull();
|
||||
await deliver();
|
||||
expect(await successors(f.runId)).toHaveLength(0);
|
||||
@@ -332,6 +345,7 @@ suite("fresh-continuation fallback", () => {
|
||||
await deliver();
|
||||
expect(await successors(f.runId)).toHaveLength(1);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
await db.update(agents).set({ runtimeConfig: { heartbeat: { maxConcurrentRuns: 1 } } }).where(eq(agents.id, agentId));
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
Reference in new issue
Block a user