Job-log tree.json step now recommends a 5-second sleep so slow-stamping runners still reuse CI results (GST-3339) (#4589)

When a repository's artifact storage is full, gstack's reuse of CI test
results reads tree.json from one log line, and the docs' `sleep 2` after
that line was too short on a Ubicloud runner, so gstack refused the run
and fell back to running tests locally.

The docs, the troubleshooting entry and the refusal's fix line now say
`sleep 5`, and a new test checks the documented sleeps against GitHub's
whole-second step times.

Repositories that copied the old step should change `sleep 2` to `sleep
5`.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-21 06:49:28 +00:00
1 parent ebc867422e
commit 0adfab9dd9
5 files changed
+48 -5

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
---
important: blocker
---
**The job-log tree.json step's recommended sleep is long enough for real runners.** When a repository's artifact storage is full, gstack reads `tree.json` from one log line the named step prints. The docs recommended `sleep 2` after that line, but runners stamp output up to a second or more after it is printed and the jobs API cuts step times to the second, so a Ubicloud run (44845717681) was refused as `CI_CARRY_TREE_LOG_UNBOUND` and the carry fell back to running tests locally. The docs, the troubleshooting fix and the refusal's fix line now say `sleep 5` after the line, and a test binds the documented sleeps to every sub-second offset with up to 2.5 s of stamping delay (GST-3339).
+10 -3
View File
@@ -850,14 +850,21 @@ hit", so the run holds no `tree.json` and every carry refuses it as
`artifact_missing`. A profile that sets `tree_log_step` to the name of one step
in its job lets gstack read `tree.json` from that job's log instead, only when
the run holds no unexpired artifact by the profile's name at all (an artifact
always wins). The step prints one line, after the test step, a second after
that step ends and a second before the next step starts:
always wins). The step prints one line, after the test step, at least a
second after that step ends, then sleeps 5 seconds before the next step starts:
```yaml
- name: Print tree.json
run: sleep 1 && echo "GSTACK_TREE_JSON checks-tree $(base64 -w0 tree.json)" && sleep 2
run: sleep 1 && echo "GSTACK_TREE_JSON checks-tree $(base64 -w0 tree.json)" && sleep 5
```
The long sleep after the line is what matters. The jobs API cuts each step's
start and finish to the whole second, and the runner stamps a line when it
reads the output, a fraction of a second to a second or more after the `echo`
ran. With `sleep 2` the next step started 1.65 s after the line's stamp on a
Ubicloud runner (run 44845717681), inside the second the check keeps clear, and
the run was refused; `sleep 5` leaves room for about 3 s of stamping delay.
gstack reads the log with `gh api --allow-escape-sequences
repos/<repo>/actions/jobs/<job id>/logs` for every profile job at the attempt
that ran, and counts lines matching
+2 -1
View File
@@ -7552,7 +7552,8 @@ or `no_verified_run` detail) and the lane runs here instead
([pregate.md](pregate.md#tree-log-step)).
**Fix.** Print the line only from the named step, after the test step, with
`sleep 1` before it and `sleep 2` after it, and make sure no test prints `GSTACK_TREE_JSON`. Then
`sleep 1` before it and `sleep 5` after it (`sleep 2` after it is too short on
runners that stamp output late), and make sure no test prints `GSTACK_TREE_JSON`. Then
dispatch a fresh run at the same head and rerun `gstack-ci-carry wait`.
<a id="ci-carry-rerun-malformed"></a>
+1 -1
View File
@@ -428,7 +428,7 @@ export const RELEASE_RESULT_CODES = {
CI_CARRY_TREE_LOG_UNBOUND: {
anchor: 'ci-carry-tree-log-unbound',
summary: 'a CI run with no tree.json artifact (artifact storage full) has one GSTACK_TREE_JSON line in its job log, but the runner did not stamp it inside the step the run profile names in tree_log_step, at least a second after every earlier step ended and a second before every later one started, or that step is missing, repeated or did not succeed; a line printed anywhere else (a test, for one) is never evidence',
fix: 'print the line only from the step tree_log_step names, after the test step, with sleep 1 before it and sleep 2 after it (docs/pregate.md#tree-log-step); then dispatch a fresh run at the same head and rerun gstack-ci-carry wait',
fix: 'print the line only from the step tree_log_step names, after the test step, with sleep 1 before it and sleep 5 after it (docs/pregate.md#tree-log-step); then dispatch a fresh run at the same head and rerun gstack-ci-carry wait',
},
CI_CARRY_RERUN_MALFORMED: {
anchor: 'ci-carry-rerun-malformed',
+31
View File
@@ -220,3 +220,34 @@ describe('the receipt and the lane line say a tree.json came from a job log (rul
expect(recordCiResult(`gstack-evidence: recorded label=tests exit=0 tests_ran=2 log=- source=ci runs=${RUN_ID}/1 policy=p`).treeSource).toBeUndefined();
});
});
describe('the documented print step binds on a real runner, whose output stamps trail the echo (GST-3339)', () => {
const RUN_STEP = 'Tested tree record in the log';
const real = { ...PROFILE, tree_log_step: RUN_STEP };
const at = (ms: number) => new Date(ms).toISOString();
const sec = (ms: number) => at(Math.floor(ms / 1000) * 1000).replace('.000Z', 'Z');
const shaped = (s: Array<[string, string, string]>): ApiStep[] => s.map(([name, started_at, completed_at], i) => ({ number: i + 1, name, conclusion: 'success', started_at, completed_at }));
const bind = (stamp: string, s: ApiStep[], profile: RunProfile = real) => refusal({ jobs: [job({ steps: s })], logs: { [JOB_ID]: log(treeLine(stamp)) } }, profile)[0];
// Value: protects=the regression record: the API times steps by flooring the runner's own clock, and run 44845717681's line (sleep 1 / sleep 2) refused as tree_log_unbound only because the step ended 1.65 s after its stamp; fails_when=the fixture drifts from the run it records
test('run 44845717681 (sleep 1 / sleep 2) refuses and run 44857547577 (sleep 3 / sleep 5) binds, exactly as they did on GitHub', () => {
expect(bind('2026-11-19T11:19:39.3384245Z', shaped([['Set up job', '2026-11-19T11:00:00Z', '2026-11-19T11:00:02Z'], ['Run tests', '2026-11-19T11:00:02Z', '2026-11-19T11:19:37Z'], ['Tested tree record (tree.json)', '2026-11-19T11:19:37Z', '2026-11-19T11:19:37Z'], [RUN_STEP, '2026-11-19T11:19:37Z', '2026-11-19T11:19:40Z'], ['Upload the tested tree', '2026-11-19T11:19:40Z', '2026-11-19T11:19:42Z'], ['Complete job', '2026-11-19T11:19:44Z', '2026-11-19T11:19:44Z']]))).toBe('tree_log_unbound');
expect(bind('2026-11-19T11:19:41.4347497Z', shaped([['Set up job', '2026-11-19T11:00:00Z', '2026-11-19T11:00:02Z'], ['Run tests', '2026-11-19T11:00:02Z', '2026-11-19T11:19:37Z'], ['Tested tree record (tree.json)', '2026-11-19T11:19:37Z', '2026-11-19T11:19:38Z'], [RUN_STEP, '2026-11-19T11:19:38Z', '2026-11-19T11:19:46Z'], ['Upload the tested tree', '2026-11-19T11:19:46Z', '2026-11-19T11:19:47Z'], ['Complete job', '2026-11-19T11:19:49Z', '2026-11-19T11:19:49Z']]))).toBe('ok');
});
// Value: protects=the sleeps docs/pregate.md recommends bind whatever fraction of a second the test step ends on, with up to 2.5 s between the echo and the runner's stamp; fails_when=the docs recommend sleeps a stamping delay or the API's whole-second times can push outside the binding window
test('the sleeps in docs/pregate.md bind at every sub-second offset and stamping delay up to 2.5 s', () => {
const doc = require('fs').readFileSync(require('path').join(import.meta.dir, '..', 'docs', 'pregate.md'), 'utf8') as string;
const m = /run: sleep (\d+) && echo "GSTACK_TREE_JSON checks-tree \$\(base64 -w0 tree\.json\)" && sleep (\d+)/.exec(doc);
expect(m).not.toBeNull();
const [before, after] = [Number(m![1]) * 1000, Number(m![2]) * 1000];
const base = Date.parse('2026-11-19T11:19:37Z');
for (const frac of [0, 1, 250, 500, 750, 999]) for (const delay of [0, 400, 1500, 2500]) {
const ended = base + frac;
const echoed = ended + before + 10;
const closed = echoed + after + 10;
const s = shaped([['Set up job', '2026-11-19T11:00:00Z', '2026-11-19T11:00:02Z'], ['Run tests', '2026-11-19T11:00:02Z', sec(ended)], [RUN_STEP, sec(ended), sec(closed)], ['Complete job', sec(closed + 5), sec(closed + 900)]]);
expect([frac, delay, bind(at(echoed + delay), s)]).toEqual([frac, delay, 'ok']);
}
});
});