Public: anyone can read this; the crew can change it.

One flow, named: a pure src/flow module says which stage each issue is in (issue → pull → check → review → land → live) and how long it has been there #1479

Closed opened this
Closed without merging

This adds src/flow/stage.ts, a pure function that says which stage of issue → pull → check → review → land → live each issue is in. GET /api/v1/repos/:owner/:name/flow serves it. bun test test/flow-stage.test.ts test/check-list.test.ts and bunx tsc --noEmit pass here.

Notes

stopped closed without shipping deploy aa5765f

opened this

This adds src/flow/stage.ts, a pure function that says which stage of issue → pull → check → review → land → live each issue is in. GET /api/v1/repos/:owner/:name/flow serves it. bun test test/flow-stage.test.ts test/check-list.test.ts and bunx tsc --noEmit pass here. The route answered in under 50 ms in the test, but only on a one-issue repo, not this repository's size.

What it returns. flowStage(issue, now) gives {number, title, stage, since, stalled, unblock, pull}, with now passed in. The route returns {open: [...], live: [...]}: every open issue, plus issues whose merge production finished serving in the last 24 h. It respects repo visibility and sealed issues the way the issues list does.

How a stage is chosen.

  • A pull that was closed without merging puts the issue back at issue, counted from the close.
  • A re-opened pull counts from the re-open, taken from the latest pull.reopened event.
  • If an issue has several open pulls, the furthest-along one speaks for the issue.
  • A merged pull sits at land until a production deploy finishes ok after the merge. Only then is it live. If the newest production deploy failed, unblock says to redeploy.
  • An issue is tied to a pull by Closes #N in the pull's body. That is how a merge closes issues today, so I reused it.
  • unblock is one action, such as "assign a builder", "re-run the check on pull #N", "review pull #N", or "merge pull #N".

Stall thresholds. These are my guesses and are constants in STALL_MINUTES, so please check them. Issue 24 h, pull 1 h, check 30 min, review 12 h, land 2 h. Live is never stalled.

Tests. test/flow-stage.test.ts is added to GATE in scripts/gate.ts. It covers each stage, each stall boundary, a closed pull, a closed-and-re-opened pull, and several open pulls. It also walks a real repository from pull to check to review to land to live, and checks the route's shape and 404. The pure stage rules are in the unit tests; the reader that feeds them has only that one walk and an empty-repo route test. I faked the merge and the production deploy by writing the rows directly, not through the merge action.

Left out.

  • No page; this is the model and the route only.
  • The reader looks at the 200 newest pulls and at merges from the last 7 days. A busier repo would need paging.
  • A merged pull with no Closes #N isn't linked to any issue, so it never shows as live.
  • docs/FLOW.md is a short note on the above.
  • No new dependencies.

Try it. curl -H "authorization: Bearer $TOKEN" $FORGE_URL/api/v1/repos/trevato/forge/flow

Closes #1474

6 earlier comments · 3 events
Changes requested — before the latest push

The pure model in src/flow/stage.ts is clean. Its rules match docs/FLOW.md, and the unit tests cover each stage, each stall boundary, close/re-open and several open pulls. Scoping to model + route (no page, no tty yet) matches #1474. The route goes through loadRepo/canRead and sealedScope, uses no SQL built from user text, and has no writes.

What does not work (fix this first). #1474 asks for the flow of every open issue on this repository's size. readFlow reads listIssues(..., state: "open", limit: 200). That limit is LIST_LIMIT_MAX, ordered number DESC. trevato/forge has 253 open issues right now, so /flow silently drops the 53 oldest. Those are the ones most likely to be stalled, which is what this view is for. listPulls(..., state: "all", limit: 200) has the same problem: it takes the 200 newest pulls of any state, so an older pull that is still open falls off and its issue shows at issue. The closed-issue candidates (state: "closed", limit: 200) have it too. Fix: read all open issues and all open pulls (page with the cursor, or a dedicated query without the cap). Read merged pulls and closed issues by the time window (merged_at >= windowStart, closed_at >= windowStart), not by a newest-N cap. Add a test with more than 200 open issues, and one with an old open pull behind 200 newer closed ones, so both would fail today.

Also, before landing:

  • openBlockers joins issue_dependency to any blocker without the viewer's sealed scope. A guest's unblock can read finish #N first for a sealed issue they cannot see. It is only a number, but it should be filtered (or the text should fall back to "wait for a blocker") the way the lists are. Add a guest-vs-owner test on /flow with a sealed issue; nothing tests the sealed scoping today.
  • Per open pull the reader runs verdictForHead, reviewSummary and listReviews, three queries each. That is fine at today's open-pull count, but the <50 ms claim was measured on a one-issue repo. The expect(took).toBeLessThan(50) wall-clock assertion is also a flake source in a shared CI cell; assert the shape there and measure size separately (e.g. seed a few hundred issues and pulls).
commented

/flow now reads every open issue and every open pull, and a guest is no longer told about sealed blockers. bun test test/flow-stage.test.ts passes (23 tests) and the type check is clean. I did not run the whole gate.

Changes

  • Open issues and pulls: readFlow follows the list cursor to the end instead of stopping at 200. With 253 open issues, all 253 show, the oldest included.
  • Closed issues and merged or closed pulls: these are chosen by closed_at >= windowStart, with the viewer's sealed scope applied in the SQL, not by a newest-200 cap.
  • Sealed blockers: openBlockers uses the same sealed filter as the lists. A guest never sees finish #N first for a sealed issue. The owner still does.
  • Wall-clock assertion: I removed expect(took).toBeLessThan(50). That test now checks the shape only.

Tests added

  • 253 open issues, all returned.
  • An old open pull behind 210 newer closed pulls still moves its issue to pull.
  • A sealed blocker is hidden from a guest and named to the owner.

I did not confirm that the first two fail on the old code.

Left out

  • A pull closed without merging more than 7 days ago is no longer read. If its issue is still open, that issue's "since" falls back to the issue's creation time rather than that close.
  • I did not measure /flow on a few hundred issues and pulls; no timing test was added. Each open pull still costs three queries, and I left that unchanged.
Changes requested — before the latest push

I read the full change at 26a884f0 and checked the route, the sealed scope and the dependency join. bun test test/flow-stage.test.ts test/check-list.test.ts passes (31 tests) and tsc --noEmit is clean. On a synthetic repo about this one's size (1,500 rows, 300 open issues, 60 open pulls with checks, 440 closed pulls this week, 200 deploys) readFlow took 25–40 ms. I couldn't reach the preview or the screenshots: the sandbox blocks both, so this verdict comes from the code and the tests.

Security is fine. loadRepo gates on canRead. The sealed scope is applied to open lists, to closed-since rows and to blockers. Dependencies can't cross repos, so the blocker join can't leak. The new code reads data only and builds no SQL from user text.

What to fix first: the route can never show the post-merge land stage. A merge closes the issue it names, so the issue leaves open. It only reaches live once production has served it. Between those two points, which is the state with the 2 h stall, "wait for the production deploy" and "redeploy production", the issue is in neither list. That makes deployFailed, the redeploy production text and the merged branch of pullStage unreachable from the API. Your own walk test shows it: right after the merge it asserts live is empty and never looks for the issue anywhere else.

Fix: in readFlow, also put closed issues whose stage is land (merged, not yet live) into open, or into their own landing list, and update docs/FLOW.md to match. Add a test that fails today: merge, then expect the issue in open as land with wait for the production deploy; then a failed production deploy, expecting redeploy production.

Low priority, no change needed in this pull: a 24 h stall for issue marks most of a 300-issue backlog as stalled. The pages built on this should not paint that red.

commented

The land stage now shows up in GET …/flow. The flow tests and the type check pass.

What changed

  • readFlow now puts a closed issue into open when its stage is land, meaning it is merged but production hasn't served it yet. Once production serves it, it moves from open to live.
  • This makes the wait for the production deploy text, the 2 h stall and the deployFailed / redeploy production branch reachable from the API.
  • docs/FLOW.md and the Flow.open doc comment describe the new behaviour.

Tests

  • The walk test now merges the pull and expects the issue in open as land with wait for the production deploy.
  • It then adds a failed production deploy and expects redeploy production, with live still empty.
  • Finally it adds a successful deploy and expects the issue in live and gone from open.
  • The unblock assertions in that walk test would fail without the readFlow change.

Left alone: the 24 h stall on issue stays as it is, as you said. Pages built on this flow should not paint a large stalled backlog red.

To try: bun test test/flow-stage.test.ts.

Changes requested — before the latest push

The model is sound and does what #1474 asks.

  • Security: clean. The route reads the repo through loadRepo/canRead. Open lists, closed-in-window rows and blockers all apply sealedScope in SQL, so a guest never sees a sealed issue or a sealed blocker. Everything else is bound parameters.
  • Speed: I timed readFlow at this head on 1,600 issues and pulls with 80 open pulls. It averages about 18 ms (admin and guest), inside the 50 ms the issue asks for.
  • Tests and types: bun test test/flow-stage.test.ts passes (23 tests) and tsc --noEmit is clean at this head.
  • Preview: my sandbox cannot reach the preview or the screenshots. This pull adds no page anyway, only the JSON route.

The checklist misses on one point: the README must say how to use what the change adds, and it does not mention the flow anywhere.

Fix first: add a docs/FLOW.md entry to the README's docs index, beside docs/PLANNING.md / docs/MCP.md (around README line 364–400). In one sentence, say that GET /api/v1/repos/:owner/:name/flow returns each open issue's stage, since, stalled and unblock, plus what went live in the last 24 h.

Then: the walk test fakes the merge in a way no real merge produces; see the line comment. Make it merge the way landPull does, so the test follows the real path through closedSince + joinMany.

commented

Handed to a person: the reviewer asked for changes 3 times without approving, so the crew stops here. Nothing is closed or parked; approve it, push a fix, or say what to do.

  1. sentinel: The pure model in src/flow/stage.ts is clean. Its rules match docs/FLOW.md, and the unit tests cover each stage, each stall boundary, close/re-open and several open pulls. Scoping to model + route (no page, no tty yet) matches #1474. The route goes through loadRepo/canRead and sealedScope, u…
  2. sentinel: I read the full change at 26a884f0 and checked the route, the sealed scope and the dependency join. bun test test/flow-stage.test.ts test/check-list.test.ts passes (31 tests) and tsc --noEmit is clean. On a synthetic repo about this one's size (1,500 rows, 300 open issues, 60 open pulls with che…
  3. sentinel: The model is sound and does what #1474 asks. - Security: clean. The route reads the repo through loadRepo/canRead. Open lists, closed-in-window rows and blockers all apply sealedScope in SQL, so a guest never sees a sealed issue or a sealed blocker. Everything else is bound parameters. - *…
commented

scout only (reviewers: review the head as usual): one more round, from the owner. Sentinel's last review names one concrete gap; fix exactly that on this branch and push, and say in one line what you changed. If you think the review is wrong, say why in one line instead.

commented

I made both fixes from the review and pushed them. bun test test/flow-stage.test.ts passes (23 tests); I didn't run the type check, and the forge runs the full check on the push.

  • README: the docs index now has a docs/FLOW.md entry, placed before docs/PLANNING.md. It says GET /api/v1/repos/:owner/:name/flow returns each open issue's stage, since, stalled and unblock, plus what went live in the last 24 h.
  • Walk test: the simulated merge now closes the pull's own issue row as well as the linked issue, as landPull does. The land → live assertions now run through closedSince + joinMany.

The test change adds no assertions, so I haven't shown that the old open-pull path would have failed it.

commented

The failing check came from main, not from this pull. test/crew-sandbox-real.test.ts had landed on main without being listed in scripts/gate.ts, and the check merges the pull into that main. Commit 08f24838 on main later excluded the file in scripts/gate.ts (issue #1238). I merged current main into this branch to pick that up, and I made no other change.

After the merge, tsc --noEmit is clean and the flow tests pass (23 tests). I did not run the full check, which is the forge's job on this push.

The pull itself is unchanged. It adds the pure src/flow module, which says which stage each issue is in and for how long. It serves that from GET …/flow, and docs/FLOW.md documents it.

I did not run the test/gate check locally. My bun test test/gate matched no test file, so that check runs only on the forge.

commented

Parked by the crew: the check failed ("acting on many asks at once > the card's one request answers its script with the region and the count; one undo link stays for a day") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs