Forgejo: link implementer session to its pull request (implementer split 2/3) #46
Labels
No labels
Agent
Ignore
Agent
In Progress
Agent
Planned
Agent
Planning
Agent
Ready
Agent
Triage
Compat
Breaking
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lucas/omp-deck#46
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implementation: #48
Problem
Once the implementer session opens its pull request, events on that pull request should reach the same session.
forgejo_create_prcalls are denied.Builds on split 1/3 (#47), which already maps the PR an implementer session opens in
forgejo_sessions(bridgetool_execution_endlistenermapImplementerPr), allows comments on mapped numbers, and routes mentions on mapped PRs to the session (dispatcherreuseMapped, covered by a dispatcher test). The PR number stays inforgejo_sessions, not in the trigger scope; mapping failures stay log-only. Remaining gaps: deny a secondforgejo_create_pr, and name the linked PR in the implementer's system context on resume.Plan reference: KB
project/forgejo-integration-plan.md, steps 10 and 14. Design:project/forgejo-integration.md(Implementer, Session routing).Plan
3. Reverse lookup in
apps/server/src/db/forgejo-sessions.tsThere is no existing lookup from session to numbers, so add one below
setForgejoSession:It runs
SELECT number FROM forgejo_sessions WHERE repo_key = ? AND session_id = ? ORDER BY numberwithrepo.toLowerCase()and returnsrows.map((r) => r.number). Sameprepare<…>style asgetForgejoSession.4. Policy: linked PR helper, second-PR deny, system context
In
apps/server/src/bridge/session-policy.ts:listForgejoSessionNumbersnext to the existinggetForgejoSessionimport.forgejoImplementerPolicy.decide, put this before the finalif (this.toolNames.includes(toolName)) return "allow";: When the list is empty, the call falls through to the existing"allow".systemContext(scope: S, sessionId: string | null): string, with this doc: "Orientation appended to the system prompt of the session.sessionIdis null while the session is being created." The conversation and pull-request policies ignore the new parameter: leave their implementations unchanged, since TypeScript accepts the shorter parameter list.forgejoImplementerPolicy.systemContext({ number, baseBranch }, sessionId): whensessionId !== nullandimplementerPrNumbers(...)returns a first entrypr, insert this line right after theYou were started to implement issue #…line:`- You already opened pull request #${pr} for this issue. Continue the work on its branch and post updates on #${pr}; issue #${number} stays open for comments. Do not open another pull request.`Otherwise the text is unchanged.
policySystemContext(trigger: SessionTrigger, sessionId: string | null): stringand passsessionIdin all three switch branches.5. Callers of
policySystemContextgrep -rn "policySystemContext(" apps/server/srcmust return exactly these call sites; update each:apps/server/src/bridge/in-process.tscreateSession(~line 267):policySystemContext(opts.trigger, null). The session id doesn't exist yet and no PR can be mapped yet.apps/server/src/bridge/in-process.tsresumeSession(~line 364):policySystemContext(trigger, existingId ?? null).apps/server/src/bridge/session-policy.test.ts: existing calls get anullsecond argument.If the grep finds other callers, pass
nullunless the caller has the session id at hand, in which case pass it.Tests
apps/server/src/db/forgejo-sessions.test.ts, created if absent (unverified — confirm first; copy thebootDbtemp-DB setup fromsession-policy.test.tslines 108–119).listForgejoSessionNumbersshould:[4, 9]foro/rafter mappingO/R#9ando/r#4tos1ando/r#5tos2;[]for an unknown session.apps/server/src/bridge/session-policy.test.ts,describe("forgejo_implementer"):forgejo_create_prisallowwith only the issue mapped (setForgejoSession("o/r", 7, "s1")). AftersetForgejoSession("o/r", 12, "s1")it is denied withthis session already opened pull request #12; push further commits to its branch instead, while sessions2is stillallow.policySystemContext(IMPL, "s1"), witho/r#12mapped tos1, containsYou already opened pull request #12.policySystemContext(IMPL, null)and an unmapped"s1"don't contain it.Verification
cd apps/server && bun test src/bridge/session-policy.test.ts src/db/forgejo-sessions.test.ts src/forgejo/dispatcher.test.ts: all pass, including the existing routing test.bun run typecheckfrom the repo root, or the typecheck script in the rootpackage.jsonif it has another name: clean.## Verificationsection.Blocker resolved: plan rebased on split 1/3 (#47). The original plan assumed 1/3 would keep a
pullNumberin the implementer trigger scope. 1/3 landed with a different design:forgejo_sessionsrecords the PR an implementer session opens (bridgetool_execution_endlistener), the comment policy and the dispatcher read that mapping, and routing PR mentions to the session is already tested. This issue now builds on that design and covers only the remaining gaps: (1) deny a secondforgejo_create_pronce a PR is mapped to the session; (2) name the linked PR in the implementer's system context on resume. If mapping the PR fails, it is still only logged, as in 1/3. The scope keeps nopullNumberand the PR wrapper from the original plan is dropped. The issue description has been updated to the revised plan.