Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fileignoreconfig:
- filename: src/logs/logs.inputs.test.ts
checksum: 7b4df8790179c7dc4385acd1d380bb91397523bab111593742e2fc53c94da375
- filename: test/integration/logs-get.test.ts
checksum: 909965f29b2e6a0b6220b22c175b4a39edc05759fba1274a7a1f2f750a7e0e3b
checksum: 89ce4f3864c6316e8075e08fb86fb07d848cbe717f434c3b3e228622b263eed2
- filename: src/commands/launch/logs/get.test.ts
checksum: d94d390de150956c799f64a84adfe0e02b5b21c66ddcc5cf55a1329aa67ec1a7
- filename: src/core/failure.test.ts
Expand Down Expand Up @@ -93,7 +93,7 @@ fileignoreconfig:
- "'SECRET=hunter2'"
- "formFieldKey"
- filename: test/integration/projects-create.test.ts
checksum: 5dd8e9b7c0d595f716b8046c2561cb240ef4144d0afddd5ed42e243442961515
checksum: 7fe9bd2822624f634e3a83907c327223249cbb132d3591d7ae517b38d4fee161
- filename: test/fixtures/README.md
checksum: d801c84c8b7d7f38f967573e9a3a70da4405b7cbcbf10d2a6e5be3d65fb3daa1
allowed_patterns:
Expand Down Expand Up @@ -236,7 +236,7 @@ fileignoreconfig:
- "a project name passed on argv to the project resolver"
- "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)"
- filename: AGENTS.md
checksum: 3379e8c597c8306e7377e60667f7df6e599e45e289928bc88b217356aa43feb1
checksum: ecab79e8abbaae85038afe4f9e8e90e310eef5b0c002cee2b014926850be2c56
allowed_patterns:
- "Do not add an exemption to a guard to make a new file pass"
- "passes its own error wording to `client.request\\(req, MESSAGES\\)`"
Expand Down Expand Up @@ -337,7 +337,7 @@ fileignoreconfig:
- "-p, --password"
- "-u, --username"
- filename: test/integration/environments-create.test.ts
checksum: aaf11e8bc45b980aee892489d507e22362cf3d48d333d7c22f46b3a506944aca
checksum: 23d388585ff2f40f8a13bf068c50694fefe423ccf312922cf8887d9f2607af22
- filename: src/commands/launch/variables/list.test.ts
checksum: 87ccb762f4931326fc50bca1c01aeb4a16d552e4dfa141d00370fdfafa4363be
- filename: src/commands/launch/variables/set.test.ts
Expand Down Expand Up @@ -435,13 +435,13 @@ fileignoreconfig:
- filename: src/deployments/deployment.presenter.test.ts
checksum: e393d6bb6ce3fd92920f5003603b161186085ea8939fae704e6f71bd9e1778bc
- filename: test/integration/deployments-create.test.ts
checksum: 2d3a8ed873ca9bf6274b074393b73f94bdf958bc2f74ef31a7558ae41c475eb4
checksum: fef71ae5b4bed7bcca111e90870238a26518e7a376475aa55768f5ffbe07ba36
- filename: src/deployments/deployment.watcher.test.ts
checksum: 0a9dab3e2436531279078bb5c0b3ef8524cebf7824b0602b7685ae0b4ef47923
checksum: b04213c987716247cfb4f1ccac37ba96f0c9a73b4564bd45b4da8ee5def0b9ca
- filename: src/deployments/deployment.create.ts
checksum: ca64f3b29a68c4a2755a88a141e2cd9dbd6fa851a2776876d78c40f3168492e3
- filename: src/commands/launch/deployments/create.test.ts
checksum: 50c3f35c7246b49f6ebf5e48a9a9646ccbcb563c0c0e042fd38917e2f98cbba3
checksum: bcbb2f85e0a78d38036af4723a0ce691f2692de05f5c7c9c3f97a5cca13497a6
- filename: src/deployments/deployment.create.test.ts
checksum: 6545afa21a23b7e5de18ad8ff417f88a184577e7042713cfda90758ccbcd9869
- filename: test/integration/deployments-rollback.test.ts
Expand Down
23 changes: 17 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,19 +713,30 @@ waits `SITE_OPEN_DELAY_MS` (six seconds, V1's wait, because a site opened the mo
live can still answer "site not reachable") and opens that url in the browser, terminal or not, as V1
did. The wait goes through the injected `sleep`, so it is awaited and the browser opens before the
command returns.
The first read asks from `DEPLOYMENT_LOGS_FROM` (the epoch) and every later one from the last
parseable timestamp printed: with a `timestamp` the service returns what came strictly after it in
ascending order, and without one it returns the newest page in **descending** order, so never let the
cursor drop the query. The poll that sees the terminal status still reads the logs once more before
returning, so the last lines of a build are never lost. The logs are auxiliary: a
The first read asks from `DEPLOYMENT_LOGS_FROM` (the epoch) and every later one from
`DEPLOYMENT_LOG_LOOKBACK_MS` (10 s) before the newest parseable timestamp printed: with a `timestamp`
the service returns what came strictly after it in ascending order, and without one it returns the
newest page in **descending** order, so never let the cursor drop the query. The look-back exists
because logs become searchable **out of timestamp order** (the logs background-jobs service batches
its bulk writes every 2 s, and the `deployment-logs` index has two shards that refresh on their own),
so a cursor at the newest line skips an older line indexed after it (CL-8805). `LogTail` remembers each
line it printed by timestamp, stage and message with a repeat count, so a re-read prints nothing twice
and identical lines in one millisecond still all print. The logs are auxiliary: a
failed read prints nothing, is retried from the same cursor on the next poll, and never changes the
outcome - the status poll alone decides that.

**The terminal poll drains the logs.** A poll that sees a terminal status does not read the logs once: it keeps
reading from the advancing `tail.since()` until `tail.fresh` returns nothing new, at most `MAX_PAGES` reads, so a
build that wrote more than one page after the last in-flight poll is never cut short. An in-flight poll still makes
exactly one read. A read that fails mid-drain prints nothing, ends the drain and never changes the
outcome. `stop` (an `AbortSignal` on `DeploymentWatchDeps`, `DeploymentFollower.watch(scope, stop)`) ends the wait
outcome. After the drain the watcher **lets the logs settle**: a deployment turns LIVE before its last
lines are searchable (the agent logs `Build and hosting completed.` after it starts the job that marks
the site live), so it makes `logSettleMs / pollDelayMs` more reads (`DEPLOYMENT_LOG_SETTLE_MS` 10 s /
2 s = 5), sleeping the poll delay before each, a failed one simply followed by the next. It settles only
when the watch saw the deployment in flight or its `updatedAt` is within `logSettleMs`, so `logs:get` on a
long-finished deployment returns at once; `waitUntilLive` reads no logs and passes `logSettleMs: 0`.
`logSettleMs` is optional on `WatchTiming` and absent means no settling, so a test timing without it
keeps its old read count. `stop` (an `AbortSignal` on `DeploymentWatchDeps`, `DeploymentFollower.watch(scope, stop)`) ends the wait
with `stop.reason` wherever it is noticed: before a poll, after one, during the drain, and at the sleep - a signal
already aborted when the loop would sleep ends it at once rather than sleeping the full delay, and the default
`sleep` takes the signal as its second argument and clears its timer on abort, so no timer outlives an interrupt.
Expand Down
7 changes: 7 additions & 0 deletions src/commands/launch/deployments/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UsageError } from '../../../core/errors';
import type { UxLike } from '../../../core/prompt';
import { PICK_COMMIT } from '../../../deployments/deployment.inputs';
import { firstDeploymentFailureMessage } from '../../../deployments/deployment.presenter';
import * as watcher from '../../../deployments/deployment.watcher';
import DeploymentsCreate from './create';

const DATA_DIR = '/work/site';
Expand Down Expand Up @@ -40,7 +41,13 @@ function commandUnderTest(resolved: Record<string, unknown>, projectType = 'GITP
return { command, lines, created };
}

const realWatchTiming = watcher.defaultWatchTiming;

describe('launch:deployments:create', () => {
beforeEach(() => {
jest.spyOn(watcher, 'defaultWatchTiming').mockImplementation(() => ({ ...realWatchTiming(), sleep: async () => undefined }));
});

it('declares org, project and env as required inputs and commit and last-upload as optional ones', () => {
expect(DeploymentsCreate.inputs).toEqual({
org: { required: true },
Expand Down
9 changes: 5 additions & 4 deletions src/deployments/deployment.follower.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ function harness(options: { withoutOpenUrl?: boolean; statuses?: string[] } = {}
pollDelayMs: 1000,
maxBackoffSteps: 3,
timeoutMs: 60_000,
logSettleMs: 3000,
};

return { follower: new DeploymentFollower(services, timing), timeline, polled, logged };
}

describe('DeploymentFollower.watch', () => {
it('polls the deployment and reads its logs in the scope it was given', async () => {
const { follower, polled, logged } = harness();
it('polls the deployment and reads its logs in the scope it was given, keeping on reading them while they settle', async () => {
const { follower, polled, logged } = harness({ statuses: ['DEPLOYING', 'LIVE'] });

const outcome = await follower.watch(SCOPE);

expect(outcome).toEqual(expect.objectContaining({ kind: 'success', status: 'LIVE' }));
expect(polled).toEqual([SCOPE]);
expect(logged).toEqual([{ ...SCOPE, timestamp: '1970-01-01T00:00:00.000Z' }]);
expect(polled).toEqual([SCOPE, SCOPE]);
expect(logged).toEqual(Array(5).fill({ ...SCOPE, timestamp: '1970-01-01T00:00:00.000Z' }));
});
});

Expand Down
1 change: 1 addition & 0 deletions src/deployments/deployment.follower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class DeploymentFollower {
outputIsTTY: this.services.outputIsTTY === true,
loader: silentLoader,
stop,
logSettleMs: 0,
logs: async () => [],
poll: () => this.services.api.deployments.get(scope),
until: (deployment) => normalizeStatus(deployment.status) === LIVE_STATUS,
Expand Down
37 changes: 32 additions & 5 deletions src/deployments/deployment.log-tail.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEPLOYMENT_LOGS_FROM, LogTail } from './deployment.log-tail';
import { DEPLOYMENT_LOG_LOOKBACK_MS, DEPLOYMENT_LOGS_FROM, LogTail } from './deployment.log-tail';
import type { DeploymentLog } from './types';

describe('log tail', () => {
Expand All @@ -13,20 +13,21 @@ describe('log tail', () => {
expect(tail.fresh(logs)).toEqual(logs);
});

it('asks from one millisecond before the last line it handed back', () => {
it('asks from the look-back window before the newest line it handed back, so a line that arrives late is still asked for', () => {
const tail = new LogTail();

tail.fresh([log('one', '2026-09-25T10:00:00.123Z'), log('two', '2026-09-25T10:00:01.456Z')]);
tail.fresh([log('one', '2026-09-25T10:00:00.123Z'), log('two', '2026-09-25T10:00:11.456Z')]);

expect(tail.since()).toBe('2026-09-25T10:00:01.455Z');
expect(tail.since()).toBe('2026-09-25T10:00:01.456Z');
expect(DEPLOYMENT_LOG_LOOKBACK_MS).toBe(10_000);
});

it.each([[undefined], [''], ['not a time']])('keeps its place past a line with the timestamp %j', (timestamp) => {
const tail = new LogTail();
const logs = [log('one', '2026-09-25T10:00:00.123Z'), log('two', timestamp)];

expect(tail.fresh(logs)).toEqual(logs);
expect(tail.since()).toBe('2026-09-25T10:00:00.122Z');
expect(tail.since()).toBe('2026-09-25T09:59:50.123Z');
});

it('skips the lines it already handed back at the last millisecond but not a new one sharing it', () => {
Expand All @@ -51,6 +52,32 @@ describe('log tail', () => {
expect(tail.fresh([retrying, retrying, retrying])).toEqual([retrying]);
});

it('hands back an older line that arrived after a newer one was already handed back, and the newer one only once', () => {
const tail = new LogTail();
tail.fresh([log('Site is live', '2026-09-25T10:00:03.000Z')]);

const next = tail.fresh([
log('Edge functions deployed', '2026-09-25T10:00:02.198Z'),
log('Build and hosting completed', '2026-09-25T10:00:02.201Z'),
log('Site is live', '2026-09-25T10:00:03.000Z'),
]);

expect(next.map((entry) => entry.message)).toEqual(['Edge functions deployed', 'Build and hosting completed']);
});

it('skips every line it already handed back inside the look-back window, not only those at the last millisecond', () => {
const tail = new LogTail();
tail.fresh([log('one', '2026-09-25T10:00:01.000Z'), log('two', '2026-09-25T10:00:02.000Z')]);

const next = tail.fresh([
log('one', '2026-09-25T10:00:01.000Z'),
log('two', '2026-09-25T10:00:02.000Z'),
log('three', '2026-09-25T10:00:03.000Z'),
]);

expect(next.map((entry) => entry.message)).toEqual(['three']);
});

it('treats the same message from another stage as a different line', () => {
const tail = new LogTail();
tail.fresh([{ ...log('done', '2026-09-25T10:00:00.123Z'), stage: 'Build' }]);
Expand Down
55 changes: 27 additions & 28 deletions src/deployments/deployment.log-tail.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
import type { DeploymentLog } from './types';

export const DEPLOYMENT_LOGS_FROM = new Date(0).toISOString();
export const DEPLOYMENT_LOG_LOOKBACK_MS = 10_000;

interface LogCursor {
at: number;
printed: Map<string, number>;
}

function logIdentity(log: DeploymentLog): string {
return JSON.stringify([log.stage, log.message]);
function logIdentity(log: DeploymentLog, at: number): string {
return JSON.stringify([at, log.stage, log.message]);
}

function timeOf(log: DeploymentLog): number {
return log.timestamp ? Date.parse(log.timestamp) : Number.NaN;
}

/**
* Logs become searchable out of timestamp order, so every read re-asks for a look-back window
* behind the newest line and hands back only the copies of each line not yet handed back.
*/
export class LogTail {
private cursor: LogCursor | undefined;
private newest: number | undefined;
private readonly printed = new Map<string, number>();

since(): string {
return this.cursor === undefined ? DEPLOYMENT_LOGS_FROM : new Date(this.cursor.at - 1).toISOString();
if (this.newest === undefined) {
return DEPLOYMENT_LOGS_FROM;
}

return new Date(this.newest - DEPLOYMENT_LOG_LOOKBACK_MS).toISOString();
}

fresh(logs: DeploymentLog[]): DeploymentLog[] {
const resumeAt = this.cursor?.at;
const repeats = new Map(this.cursor?.printed);
const seenInThisRead = new Map<string, number>();
const fresh: DeploymentLog[] = [];

for (const log of logs) {
const at = timeOf(log);
const identity = logIdentity(log);
const seen = repeats.get(identity) ?? 0;

if (at === resumeAt && seen > 0) {
repeats.set(identity, seen - 1);
if (Number.isNaN(at)) {
fresh.push(log);
continue;
}

fresh.push(log);
this.remember(at, identity);
}

return fresh;
}
const identity = logIdentity(log, at);
const copy = (seenInThisRead.get(identity) ?? 0) + 1;
seenInThisRead.set(identity, copy);

private remember(at: number, identity: string): void {
if (Number.isNaN(at)) {
return;
}
if (copy <= (this.printed.get(identity) ?? 0)) {
continue;
}

if (this.cursor === undefined || at !== this.cursor.at) {
this.cursor = { at, printed: new Map() };
this.printed.set(identity, copy);
this.newest = this.newest === undefined ? at : Math.max(this.newest, at);
fresh.push(log);
}

this.cursor.printed.set(identity, (this.cursor.printed.get(identity) ?? 0) + 1);
return fresh;
}
}
Loading
Loading