fix(workspace): a new session shows in its workspace

This commit is contained in:
2026-10-02 16:18:00 +07:00
parent f35bf2043f
commit da1b17778c
6 changed files with 118 additions and 8 deletions
+10 -1
View File
@@ -1310,10 +1310,19 @@ const HOOK_TOOLS = { codex: codexHookInput, antigravity: antigravityHookInput };
* The session the pane holds is also stamped with the pane's lane
* (`sessions.lane_id`, first writer wins) — that is what makes it the
* workspace's own session rather than one that merely ran in the same folder.
* A new Claude pane is started with `--session-id` (pty-run.js), so its run
* names the session before any hook: a hook without `run_id` is stamped from
* that run instead.
*/
function bindRunSession(runId, sessionId, hookType, source, tool) {
if (typeof runId !== "string" || !/^agenthub-lane-\d+(-[1-3])?$/.test(runId)) return;
if (typeof sessionId !== "string" || !sessionId) return;
if (typeof runId !== "string" || !/^agenthub-lane-\d+(-[1-3])?$/.test(runId)) {
// No pane named (a hook handler that predates AGENTHUB_RUN_ID): a run
// that was started holding this very session id still owns it.
const laneId = dashboardRuns.laneForSession(sessionId);
if (laneId != null) stmts.claimSessionLane.run(laneId, sessionId);
return;
}
const row = dashboardRuns.getRun(runId);
if (!row) return;
if (row.session_id !== sessionId) {
+7 -2
View File
@@ -161,8 +161,13 @@ router.get("/", (req, res) => {
params.push(tool);
}
if (lane !== undefined) {
where.push("s.lane_id = ?");
params.push(Number(lane));
// Also a session one of the lane's runs holds that nothing stamped yet:
// two dashboards may share the DB and hooks reach only one of them, which
// may be an older build that never stamps (bindRunSession).
where.push(
"(s.lane_id = ? OR (s.lane_id IS NULL AND s.id IN (SELECT session_id FROM dashboard_runs WHERE lane_id = ?)))"
);
params.push(Number(lane), Number(lane));
}
// `archived=0|1` = only live / only archived; absent = both, as before.
if (req.query.archived === "0") where.push("s.archived_at IS NULL");